T:7 Gradients#

T:7.1 Derivatives of the DF with respect to the anisotropy parameters#

The rows of the inversion are \(F = T_b[g](q)\) on a fixed grid \(q\), where \(T_b\) is the operator of Section T:2.3 with its completion below the floor, applied to the source \(g\), namely the rows of \(\mathrm{d}^N\varrho_\mathrm{aux}/\mathrm{d} P^N\). At a fixed central anisotropy \(b = \beta_\mathrm{c}\), the operator is linear in its source, so that

\begin{equation} \frac{\partial F}{\partial {R_\mathrm{a}}} = T_b\!\left[\partial_{R_\mathrm{a}} g\right], \qquad \frac{\partial F}{\partial {\beta_\mathrm{c}}} = T_b\!\left[\partial_{b}\, g\right] + E_b[g] , \tag{T:7.1} \end{equation}

where \(\partial_\theta g\) denotes the mixed derivatives at fixed \(P\), formed symbolically in the same way as the derivatives of Section T:1.2.1, and \(E_b\) is the derivative of the operator itself with respect to \(b\) at fixed \(g\), through its prefactor and the exponent of its kernel. \(E_b\) has no closed form and is taken from the values of the operator at nearby \(b\): a central Richardson quotient over a step and its half inside the region of one form, or the one-sided third-order combinations of both sides and their mean at a corner where the form changes on one side (half-integer \(\beta_\mathrm{c}\), or the switch of the pair). The step balances the measured accuracy of the kernel against the truncation term of the quotient. The quotient’s record states the Richardson residual of the quotient and, at a corner, the spread between its two sides, both relative to the scale of the column.

The table that the lookup reads is a function of the rows and of closed forms in \(\theta\), so its derivative is the chain rule through each piece, with every discrete choice of the forward pass held fixed: the grid, the anchor, the range of the fit, and the nodes below the written floor. The contribution of the rows is Eq. (T:7.1) along the rows. The form above the anchor is its least-squares fit linearized in the rows, with the exponent \(\kappa(b)\) and the amplitude \(A(b)\) of the center in closed form on the regular branch. The nodes below the floor are the integral, which is linear in its source, with the source’s cubic in \((\ln P, \ln|g|)\) linearized; in \(b\), the exponent and the prefactor of the floor pair are differenced in the same way as \(E_b\). The tail contributes through its amplitude, exponent, and scale from the first node below the floor. On a Method II model the Method I model is held fixed, and the sources of the Method II model are the Leibniz sum of Section T:2.6, whose derivative is the same sum with \(\partial h/\partial\theta\) in closed form; the leaves are the rows, the edge law, and the stated form of the center, each with its derivative written out. The derivative is that of the solve with its choices fixed; between two parameters at which a choice changes, the solve at the second differs from the held one by its own tolerance.

T:7.2 Anisotropy models and parameters with derivatives, and the refused cases#

The rule of the DF’s table (Section T:7.1) serves constant anisotropy and an isotropic component (\(\beta_\mathrm{c}\)), Cuddeford Type I (\(\beta_\mathrm{c}\) and \(R_\mathrm{a}\)), and Osipkov-Merritt Type I and II (\(R_\mathrm{a}\)). The tangent rows of the second moments (Section T:7.3) are served in \(\beta_\mathrm{c}\) for every family and in \(R_\mathrm{a}\) for every family that has it, Cuddeford Type II included, an Osipkov-Merritt model being varied in \(\beta_\mathrm{c}\) as the Cuddeford model of its type at \(\beta_\mathrm{c} = 0\). The velocity distributions are served in the parameters of the DF’s path: \(\beta_\mathrm{c}\) of a constant member, \(R_\mathrm{a}\) of an Osipkov-Merritt member, both of a Cuddeford Type I member; the column of a parameter that path does not take is not a number, and an isotropic member’s velocity distributions are refused with the reason stated. A member without \(R_\mathrm{a}\) holds it at its own, infinite, value with a zero gradient. The rule of the DF’s table refuses three cases, each with the reason stated. The first is Cuddeford Type II, whose source, the derivative of order \(j\) of the auxiliary density, behaves as \(|P - P(R_\mathrm{a})|^{s}\) with \(s = 1 - \beta_\mathrm{c} - j\) (Eq. (T:2.15)), with an interior point that moves with \(R_\mathrm{a}\) and an exponent that moves with \(\beta_\mathrm{c}\); the derivative of that factor with respect to \(R_\mathrm{a}\) is not integrable at the interior point for \(s < 0\) and is a point mass there at \(s = 0\), so the mixed rows do not carry the derivative, and the family is refused for both parameters. The second is a center on its critical branch, where the branch itself changes with \(\beta_\mathrm{c}\). The third is a component on a truncated profile that carries no DF of the model it was cut from. The velocity distributions, which read the DF’s table and its derivative, refuse the same cases, and besides them an isotropic member’s \(\beta_\mathrm{c}\) and a row at \(\beta_\mathrm{c} = \pm 1/2\), whose angle integral is taken in closed form. The second moments read no DF: their tangent rows serve a center on its critical branch and Cuddeford Type II as well; the JAX functions of the observables refuse a Cuddeford Type II component for all the observables, the second moments included, while the likelihood serves it as a free component. The derivative of the observables of a model with respect to \((\beta_\mathrm{c}, R_\mathrm{a})\) is the full derivative for a Method II model, whose profile is held fixed. A truncated Method I model is refused with the reason stated, since its profile is that of its own DF and moves with the anisotropy, so that neither the Jeans path at a fixed profile nor the DF’s path at a fixed potential carries the full derivative; an untruncated model is refused on both paths, since its edge terms read its DF.

T:7.3 Derivatives of the velocity dispersions and distributions#

Each observable is served as a JAX function of \(\theta = (\beta_\mathrm{c}, R_\mathrm{a})\) with a custom derivative. Its value is the public call on the model rebuilt at \(\theta\) on the host, and its derivative is given by the tangent rows of the observable in \(\theta\) on the tables’ own rows, with their placement frozen. The tangent rows of the radial dispersion are the derivative of the Jeans rule Eq. (T:6.1) on the same rows and nodes on the fixed profile, with the limit of the edge reading unmoved. The tangent rows of the projection are the derivative of the line-of-sight rule on the same nodes, through the derivative of the profile’s reading, with the surface density held, and zero where the surface density is zero. A negative squared dispersion is refused with the reason stated, never clipped, so no row of the forward is clipped and no tangent row is set to zero for that reason. The derivative of the squared dispersion over an aperture is the aperture’s integral of the tangent rows of the squared dispersion, on the nodes and weights of the plain call (the integral is linear in the rows); the derivative of the dispersion over the aperture is that over twice its value, and zero where the value is zero. The velocity distributions take their derivatives in two parts. The first is through the derivative of the DF’s table (Section T:7.1): the lookup is differentiated by JAX on its own expressions, and the transpose carries a cotangent on \(F\), and on its integral \(G\) where a row reads it, at the energies back to the numbers of the table through the three maps between them (the padded nodes, the spline slopes where a table has no exact ones, and the derived numbers of the forms), with the energies held fixed, and contracts it with the table’s derivative in \(\theta\). The second is the explicit part at a fixed table: the derivative, by JAX on a twin of the velocity plane or of the angle integral with the forward’s discrete choices held, of the distribution’s own dependence on \(\theta\) through the anisotropy’s factor, the augmented energy and the edges of the integration. For its transpose, each row of the line-of-sight tables that a nonzero cotangent reaches is computed once more by its own rule, with every read of \(F\) and \(G\) collected at the level from which the value of its velocity came. With the setting that checks the rows, which is off by default, the row so computed is held to the forward’s row bit for bit, and so is the row formed again level by level, and a row that differs is refused with the reason stated; the order of summation on a GPU does not promise that equality, so on a GPU the check can refuse a row that the CPU serves. Without the check, no row is compared and every row is served on either backend. At a \(\theta\) where the model is refused, the value is not a number and its gradient is zero.

T:7.4 The likelihood#

The log-likelihood of a model against data is a JAX function of the weights of the components and of the mass and length scales of the model, traceable and differentiable in both, and with the anisotropy of the free components as parameters through the tangent rows above. The observables predicted by a model are read on the host once, as tables over projected radius; a projected radius in the units of the data is \(R = L\,l\,x\) and a velocity is \(v = V(m/l)^{1/2}u\), with \(x\) and \(u\) in internal units, \(L\) and \(V\) the factors of the model’s units, and \(m\) and \(l\) the scales relative to the model’s own. For a superposed model, the composite profile for a new set of weights is one matrix-vector product over the members’ tabulated moments (Section T:6.9); the second moments that the likelihood compares with the data are linear in the normalized weights, while the likelihood itself is not, and the gradient of the log-likelihood in the weights is exact because JAX differentiates the whole function. A refused input inside the traced function (a negative weight, a radius outside the table) gives minus infinity with a zero gradient, never an exception, so that a sampler over the parameters always sees a value. A binned distribution and the Gauss-Hermite moments in apertures are computed at the model’s own length scale: a length scale other than the model’s own gives minus infinity, and the gradient in the length scale is not a number for a binned distribution and zero for the moments in apertures.