Mathematics
Every continuous type of the core gets a reference measure and the log-volume of its retraction's chart, Lebesgue measure with log-volumes and on the core's own types, the measure the retraction normalizes on an embedded type that declares its chart's domain and log-volume, and sums over products; a type that declares none has no densities.
The problem#
A density is a density with respect to a measure. The core fixes one for each of its own types, Lebesgue measure on the Euclidean and positive types, counting measure on the discrete ones and product measures on products, and states every density, importance weight and retirement against them (the appendix). It leaves the embedded types, the curved types that later crates declare, without one: their points are stored in a coordinate space of which they fill no open set, so Lebesgue measure gives them none, and the appendix defers “surface measure on a sphere, Haar measure on the rotations” to the entries that bring those types.
Every distribution with a density on a curved type needs that measure, and the first of them is already being worked out: the normal distribution, generalized to the law of for a normal on any space whose chart’s volume is known, so that a measurement of a rotation or of a direction is held as what was measured rather than as a residual. Its log-density is that of less the log-volume of the chart at (Proposition 4), and so it needs, of every type it is used on, a reference measure and that log-volume as something it can compute and differentiate.
Asking each distribution’s entry to supply them would put a type’s measure outside the type, and have every curved type answer the same question once per distribution. This entry answers it once, for every type: it gives each continuous type of the core a reference measure and the log-volume of its retraction’s chart, lets an embedded type declare its own, and completes the appendix with the rule for a type that declares none.
Setting#
The mathematics of densities in tangent charts is in the note on densities in tangent charts, and this document uses its notation throughout. A continuous type is a manifold of dimension with a retraction ; with a reference measure on , the chart at has a domain on which it is a diffeomorphism onto its image , and a volume on , with (Definition 1). Its log-volume is . The chart is global if , and full if has a complement of measure zero. A random vector of density moves to a point of density (Proposition 4).
An embedded type is declared to the core by its storage size , its dimension , a retraction , its inverse and optionally a projection, each an operation on Euclidean values, smooth as computed at and on the diagonal, with bases (Proposition 3). Its boundary operations are the inclusion , the retraction and the projection, whose derivative maps the core assembles from passes over , and the projection. Every operation has derivative maps of first and second order at most, tangent, cotangent and Hessian passes, and an order that says which of them it admits (Operations).
The measure a retraction normalizes is the one whose charts have volume at their centre, at every . It exists on every manifold with a retraction, and is the Riemannian volume of the metric in which every basis of the retraction is orthonormal, so that it depends on the bases alone and not on how the manifold is stored (Proposition 6); for an embedded type it is times surface measure (Proposition 7).
The core’s own types#
The core’s types keep the measures the appendix gives them, and their charts’ volumes follow directly from their retractions.
With Lebesgue measure on , on and on , the charts of the core’s Euclidean and positive types are global and full at every point, with the log-volumes
On a product of continuous types, with the product of the factors’ measures, the chart at has the log-volume at the stacked tangent , and is global, or full, if and only if every factor’s is.
On the chart at is the translation , a diffeomorphism of onto itself with Jacobian determinant , so it is global and full with . A matrix of is flattened column by column into , which carries Lebesgue measure to Lebesgue measure, so the same holds. On , maps onto , with inverse , and its Jacobian is , whose determinant is ; the change of variables formula gives the volume. Products are Proposition 9.
∎As operations of the base point’s storage and the tangent vector, the log-volumes are
and read at the coordinate of a point, the positive one is , which does not depend on . With (2), Proposition 4 gives back the core’s own formula for a density written in the logarithmic chart of a positive quantity, (20): a vector whose logarithm has density has the density , which is with , at every .
Why the positive orthant keeps Lebesgue measure. The measure the positive orthant’s retraction normalizes is not Lebesgue measure but (the note’s example), so the core’s positive type is the one continuous type whose reference measure is not the one its retraction normalizes, and the one whose log-volume depends on the base point. It keeps Lebesgue measure all the same. The densities of positive quantities in common use, the gamma, the inverse gamma, the log-normal and the exponential, are published and computed against Lebesgue measure, and a log-density that differed from theirs by would surprise everyone comparing skoro with them. The difference is not a constant: a mode with respect to is a mode in the logarithmic chart, and is not the mode a user of the gamma distribution expects. And the appendix already fixes Lebesgue measure, which the core’s tests rely on. The cost is that the log-volume of a type must be allowed to depend on the base point, which an embedded type whose bases are not of constant volume needs anyway.
What an embedded type declares#
An embedded type has no Lebesgue measure, and the surface measure its storage induces depends on the storage: the rotations stored as matrices and as quaternions would have densities that differ by a constant, and a type whose basis is not orthonormal, densities that differ by a function of the point. The measure an embedded type is given is therefore the one its retraction normalizes. On a group whose retraction translates a chart of the identity it is a Haar measure (Proposition 8), and on a sphere with orthonormal bases it is surface measure; on any type, it is the same whatever the storage, so long as the bases are, and a density on the type means the same whether its points are stored as matrices or as quaternions.
The core cannot compute the chart’s volume from a declared type in general (below), and the appendix cannot give a measure to a type whose volume it cannot compute. So the chart’s volume becomes an optional declaration of an embedded type, beside its retraction, its inverse and its projection.
Let an embedded type of dimension have the retraction and the inverse of Proposition 3, and let be the measure its retraction normalizes. A declared chart volume for it is a domain and a log-volume, as follows.
The domain assigns to every an open set containing on which is a diffeomorphism onto an open set of whose complement has -measure zero, and such that for every . It is declared either as global, at every , or by a discretization that is true at exactly when .
The log-volume is an operation on Euclidean values such that
the log-volume of the chart at with respect to . It has derivative maps to the order the type claims, and is smooth as computed on every , at in particular.
The log-volume of the chart at is then the operation read at the base point’s storage,
a composite of the inclusion and an operation on Euclidean values, whose derivatives with respect to , in its chart, and to follow by the chain rule from those of (4) and of . On a group, does not depend on its first argument (Proposition 8), and neither does it for the stereographic chart of a sphere with orthonormal bases, whose volume depends on the length of alone. In general it may, and it does on a type whose bases have a volume that varies from point to point.
Each condition of the definition is there for a use.
- The inverse on the whole chart. Proposition 3 asks of only that it invert the retraction near , which is enough for derivatives. A density at a point is read at its coordinate , which may be anywhere in the chart, so a type that declares a volume asks more: is the inverse of the chart on its whole image. The usual charts have it: the logarithm of the rotations by less than , the Cayley inverse (12), and the stereographic inverse (15) away from .
- The domain. Within , Proposition 4 applies to every density of whose mass is in . A global chart takes every density on , and a sampler that draws is then exact for the density (10) below, whatever ’s law. A chart that is not global, such as an exponential chart, is a diffeomorphism only on its domain, and the law of for an with mass outside it is within that mass of the law the density describes (Proposition 5). Which of the two a type’s chart is, and for a chart that is not global its domain, is therefore part of what a distribution must know to say whether its sampler is exact. The domain is declared as a discretization, an operation the core already has, whose output is a boolean and which has no derivatives, so that a test or a sampler can ask of a tangent vector whether it lies in the domain.
- Fullness. The image of a full chart is all of but a set of measure zero, so a density in the chart is a density on , read correctly at every point that has positive probability. The complement may be where is undefined, as is for the stereographic chart, and is never reached by a draw. A chart that is not full, such as the normalization chart of the sphere, which reaches the open hemisphere around alone, defines a density that is zero outside its image, and its computes a coordinate there all the same, at which a log-density is finite and wrong. The definition asks for fullness, so that no type’s density can be silently wrong at a point a model can be given.
- The log-volume as an operation. is one more operation on Euclidean values, written as a composite or as a fused operation, and tested like one. A term reads it at , which is whenever the point is at its mean, as a measurement is when it equals its prediction; so it is asked to be smooth as computed there, as is (Smooth as computed). The exponential chart of the rotations has , with a removable singularity at , computed below a cutoff from its series (11), in a kernel or in a composite with its closed form guarded, as the core says of . Its order is the type’s to claim: a term over the type has Hessians only if admits Hessian passes.
The acceptance-test sphere. The core’s acceptance test declares the unit sphere outside the core, with the stereographic retraction and inverse (15) and a basis orthonormal on the sphere. Its normalized measure is surface measure , since , and its chart is global and full: the retraction is defined for every , inverts it on all of by the computation that accompanies (15), and it reaches every point but . Its log-volume is that of the note’s table,
independent of , smooth everywhere as written, and a composite of the core’s primitives. Read at the coordinate of a point, it has a form in storage too: with , , so and . The sphere is the natural type to test a declaration on: it is curved, already written against the core’s public interface alone, and its volume is known in closed form.
Declared, not computed#
The volume of an embedded type’s chart could be computed from its retraction alone. Proposition 7 gives it, and it extends to every type the core has.
Let a continuous type be stored in , with reference measure , where is the measure its storage induces and is continuous and positive: on the core’s Euclidean and positive types, on an embedded type, and the product of the factors’ on a product. For every and every ,
with the derivative of the retraction in storage with respect to its tangent argument. If the chart is full, then
at every , finite when is compact.
The first part of the proof of Proposition 7 gives the volume of the chart with respect to as , and with respect to it is that times . On the core’s Euclidean and positive types, stored as and its open subset , the measure the storage induces is Lebesgue measure, so . On an embedded type, is that of Proposition 7. A product is stored as its factors’ storage concatenated, the measure that storage induces is the product of the factors’, because the coordinates of different factors are orthogonal, and its reference measure is the product . For the second part, take in (2): , which is when the chart is full.
∎The core does not compute the volume this way. In a term, the log-volume is a value of the forward pass, its gradient enters the term’s gradient, and its Hessian the term’s Hessian. Computed by the area formula, the forward value would contain , a first derivative of the retraction, so its gradient would need the second derivatives of and its Hessian the third, and the core’s operations have derivative maps of second order at most. Nor can a composite be built from a pass: it is built from the values of operations, and a derivative map is what a pass over it computes, not a value in the compilation graph. And every evaluation would cost tangent passes over , a Gram matrix and its log-determinant, where the declared formulas of the note’s table are one scalar function of the tangent vector: , and for the exponential charts of , and , and for the Cayley chart of the rotations and the stereographic chart of the sphere.
A type therefore declares its log-volume, and Proposition 6 is what a test checks the declaration against. Its right side needs only first derivatives, which a tangent pass over gives, columns at its second input, and the bases at the moved point, a second tangent pass at :
at points of the type and tangent vectors of its domain, near and far from it. Two smooth functions that agree on an open set agree in every derivative there, so a declaration that passes this check at enough points has the right derivatives as well, and the derivative maps of itself are checked as any operation’s are. Three further identities are checked with it, each cheap and each catching a different mistake:
- at every , the normalization, which a log-volume computed against surface measure rather than the normalized measure fails by ;
- for throughout the domain, not only near , which is the inverse on the whole chart that the definition asks for; and, where the domain is not global, that is true at the points of the check and false beyond them;
- on a compact type with a full chart, the total mass of Proposition 6,
the same at every , which a chart that is not full, or a log-volume wrong by a constant, fails. For the sphere with (5) it is , for the rotations with either the exponential or the Cayley chart , the same for both because both have the left-translated bases and so normalize the same measure.
The check (7) holds on the core’s own types too, with the second term absent: on its first term is , which is (2). On a product it is the sum of the factors’ checks, since is block diagonal and the second term has a term for each embedded factor alone.
Products#
A product of continuous types has the product of its factors’ reference measures, and by Proposition 9 its chart’s log-volume is the sum of its factors’ over the stacked tangent: with stored as its factors’ storage concatenated and ,
each term read from the slices of and that belong to its factor. The product’s chart is global if every factor’s is, and its domain is otherwise the product of the factors’, whose discretization is the conjunction of theirs, a global factor’s being always true; it is full because every factor’s is. A product has a volume exactly when every factor has one. The core’s own types always do, so a product of them always does, and a product with an embedded factor that declares none has none. On the core’s runtime products, whose factors and dimensions are known only when the quantity is created, (9) is assembled then, as the product’s retraction is.
The product’s measure is the product of its factors’, and not, in general, the measure the product retraction normalizes: a positive factor contributes Lebesgue measure. By Proposition 9 the two agree when every factor’s measure is its own normalized one, which is the case for products of embedded and Euclidean types.
Densities against the reference measures#
With a reference measure on every continuous type that has a volume, the appendix’s account of a model’s probability space reaches the curved types without change, and what the core states against base measures is stated against these.
Densities through a chart. A distribution that draws a point as , with of density on and in the domain almost surely, has with respect to the type’s reference measure the log-density
by Proposition 4 and (4), on every type, the core’s included: on the correction vanishes, and on it is (20). The same holds of a sampler’s log-density , and of a parameter’s proposal. This is the general form of the one place the core names where base measures are easy to mismatch, a density written in a chart, and the importance weight (18) is right on a curved type when its terms and its proposals keep to it.
Importance weights. Proposition 19 takes to be the product of the free quantities’ base measures. A free quantity’s base measure is now its type’s reference measure: Lebesgue measure on the Euclidean and positive types, the measure its retraction normalizes on an embedded type, counting measure on a discrete type, and the product of its factors’ on a product.
Retirement. The integral of Proposition 23 over the retired free quantities is against the product of their reference measures. The core does not compute it, but the replacement it checks stands for it, and whoever approximates it in a chart works with (2): for a quantity of whose chart at is full,
so a Laplace approximation in the chart expands , not alone. On an embedded type and the log-volume enters through its derivatives only, through its Hessian when its gradient at vanishes, as for every chart of the note’s table: on the exponential chart of the rotations, on the Cayley and stereographic charts. On a positive quantity it enters through its value and its gradient, the vector of ones.
Types without a volume#
An embedded type that declares no volume has no reference measure, and so no densities: there is no measure against which a function of its points could be the density of a law. The appendix therefore holds for the types that have a volume, and of a quantity of a type that has none, the core asks what needs no measure on it and refuses what does.
- No term scores it. A term that scores a quantity is that quantity’s conditional density (the appendix), so the core refuses a term that scores a quantity of a type without a volume. Such a quantity is always a parameter.
- It has no proposal. A proposal is a density with respect to the parameter’s base measure, and the core refuses one for a parameter of a type without a volume. A query that leaves such a parameter free can therefore not be generated, which the core already refuses, naming a free quantity that has neither a sampler nor a proposal.
- It is not integrated out. A retirement that would integrate such a quantity out, with it in , is refused: the integral of Proposition 23 is not defined. It may be retired with a given value, in , since fixing a quantity needs no measure on it.
Everything else is allowed. A term may be conditioned on such a quantity, since a conditional density of another quantity given it needs no measure on it; a query may observe it; and a query may leave it free, as optimization does: its log-density is then a function of the quantity, whose maximum is a likelihood estimate, but not a density of it, so an algorithm that integrates over the query’s free quantities, a sampler or an evidence, must refuse it. A distribution on a type without a volume can therefore only be a likelihood factor over data: with the measured value a constant , a function such as of the state scores nothing and needs no measure. That is how factor-graph libraries hold every measurement, and it remains available on every type; a volume is what makes the measurement a quantity of its own, with a law that can be sampled and integrated.
In skoro’s terms#
- Every continuous type has, or declares, a reference measure and a chart log-volume , an operation on the storage of the base point and the tangent vector. The Euclidean types (real, vector, matrix) have Lebesgue measure and ; the positive orthant has Lebesgue measure and (2), which is at the coordinate of ; both charts are global and full. Discrete types have counting measure and no chart.
- An embedded type may declare its chart’s volume, by Definition 3: a domain, global or given by a discretization of , on which the chart is a diffeomorphism onto a full image and inverted by the type’s , and a log-volume , an operation on Euclidean values with derivative maps to the type’s order, smooth as computed at . Its reference measure is then the one its retraction normalizes, the same for every storage with the same bases: Haar measure on the groups, surface measure on the sphere.
- A product’s log-volume is the sum of its factors’ over the stacked tangent (9), its measure the product of theirs; it has a volume when every factor has.
- The log-volume is differentiated with respect to the tangent vector and, through the inclusion, to the base point in its chart, (4), whenever a term contains it, as the densities of (10) do; its order bounds theirs.
- A declaration is tested, not trusted: against the area formula (7), computed by first-order passes over the retraction, against , against the inverse on the whole domain, and, on a compact type, against the total mass (8). The core’s acceptance-test sphere declares (5) and is checked so.
- The appendix gives every quantity of a type with a volume its reference measure, against which terms, samplers, proposals, importance weights and retirements are stated. A quantity of a type without one is never scored, has no proposal and is never integrated out by a retirement; it is a parameter, observed or free, and a distribution on its type is a likelihood factor over data.
Open questions#
None remain.
Built on by
- The uniform distribution on compact types, and broad scales of a normal on a curved type: Mathematics The uniform distribution on a type of finite mass, curved or finite and discrete, its constant term and its sampler; and what a normal with a large scale is on a curved type, with the ways of refusing it, bounding its scale, replacing its law and documenting it weighed against each other.
- Observed quaternions of arbitrary sign on outside data: Mathematics A unit quaternion names a rotation twice, and the stereographic chart of the unit quaternions tells the two names apart, so that a measurement given with the wrong sign is misread; the rotations, the rigid motions and the extended poses become the groups themselves, stored as quaternions up to sign under the Cayley chart, which cannot tell the signs apart, and the core learns to declare a type stored up to a finite group.
- Accuracy on the GPU: Mathematics How the absolute error of a GPU's sine and cosine reaches the closed forms of the removable singularities and their derivatives, measured on a wgpu adapter; the error the cutoffs are designed for and how a device is admitted to it; and the conditions a cutoff and its series must meet so that single precision on the GPU agrees with double precision as it does on the CPU.
- Rotations and rigid motions: Mathematics The rotations as unit quaternions with the stereographic chart, global and full with a declared volume so that they carry the normal, the rigid motions SE(3) and SE₂(3) as their semidirect products with the left-translated chart, and the usual maps of all three, each a composite of the core's operations.
- Normal distributions: Mathematics skoro's one normal distribution, the law of a point moved by normal noise through its chart, defined on every space whose chart is global and whose volume is known, so that flat, positive and curved quantities alike, measurements among them, are drawn and scored exactly; with its scale, its sampler, its properties, its expected information, its roles, and its use as a likelihood factor.
- Reference measures and chart volumes of spaces: Implementation Every continuous `Space` gets a log-volume composite and a chart domain, an embedded declaration takes its chart's volume with `with_volume`, the core refuses a density, a proposal or an integration over a type without one, and `testing::check_volume` holds a declaration to the area formula.