Measure Algebra¶
These combinators build measures from measures: Mixture, Restrict, Pushforward, PointMass,
Independent, and Normalize, which back the operator families of the DSL. Restricting a
probability measure to an event of probability 0.2 leaves total mass 0.2, and dividing by 0.2 gives
the conditional distribution (Bernardo and Smith, 1994). Each combinator states whether it keeps that
mass or normalizes it, and
normalize_at_boundary renormalizes a
subprobability measure where it is sampled or scored.
Independent(base, reinterpreted_batch_ndims=0) is the identity case:
it preserves every base batch and intrinsic event axis, raw mass, and interval
query. Positive counts reinterpret that many trailing batch axes as one event
and multiply their masses. Counts must be nonnegative integers no larger than
the base batch rank. The identity case does not reduce the batch axes.
An intrinsic base event follows the reinterpreted batch axes. For a base with
batch shape (2, 3) and event shape (4,), a count of one gives batch (2,)
and event (3, 4); zero retains (2, 3) and (4,). Boolean and fractional
counts are invalid. Native construction and checked source use the same
axis-count validation; source examples
show how typed headers distinguish outer rows from base batch axes.
import torch
from quivers.continuous.measure import Independent, Normalize, Restrict
base = torch.distributions.Normal(torch.zeros(2, 3), torch.ones(2, 3))
product = Independent(Restrict(base, -1.0, 1.0), 1)
assert product.batch_shape == torch.Size((2,))
assert product.event_shape == torch.Size((3,))
normalized = Normalize(product)
point = torch.zeros(2, 3)
expected = base.log_prob(point).sum(-1) - product.log_normalizer()
torch.testing.assert_close(normalized.log_prob(point), expected)
This restriction retains its raw coordinate masses until Normalize divides
by their product. Reinterpreting batch axes does not normalize the base.
Raw masses and interval endpoints¶
log_interval_mass(low, high, lower_closed=..., upper_closed=...) integrates
the retained measure over the requested interval. Both endpoints are included
by default; either flag may be false, including for discrete or mixed laws.
An interval with equal endpoints contains only its atom when both flags are
true. None leaves that side unbounded.
The four log-tail methods use this same operation:
| Method | Event |
|---|---|
log_cdf(x) |
\((-\infty,x]\) |
log_cdf_left(x) |
\((-\infty,x)\) |
log_survival_function(x) |
\((x,\infty)\) |
log_survival_function_left(x) |
\([x,\infty)\) |
These methods return raw mass. Thus cdf(x) can exceed one for an
unnormalized measure; Normalize(base).cdf(x) gives its probability CDF.
Restrict retains intersection mass, and Normalize divides by the retained
total mass once. A mixture's sampling probability for component \(j\) is
proportional to its raw weight times its total mass, so a restricted component
is selected according to its remaining mass.
import torch
from quivers.continuous.measure import Mixture, Normalize, PointMass, Restrict
half = Restrict(torch.distributions.Uniform(0.0, 1.0), 0.0, 0.5)
raw = Mixture(torch.tensor([2.0, 3.0]), [half, PointMass(torch.tensor(0.0))])
probability = Normalize(raw)
assert abs(raw.log_normalizer().exp().item() - 4.0) < 1e-6
assert abs(probability.cdf(torch.tensor(0.0)).item() - 0.75) < 1e-6
open_lower = probability.log_interval_mass(0.0, 0.25, lower_closed=False).exp()
assert abs(open_lower.item() - 0.125) < 1e-6
Atoms and density references¶
A scalar mixture combines component densities against one common reference.
At any retained atom, log_prob includes atomic masses alone; an atomless
component's continuous density does not add probability to that point.
Away from the atom carrier, continuous component densities contribute as usual.
Integer-valued scalar laws use counting measure on the integers, including
integer locations where a particular component assigns zero mass.
atom_reference(value) identifies the retained atomic carrier, while
log_atom_mass(value) reads its raw mass. Restriction can remove an atom's
mass without changing the base carrier, and normalization rescales the mass.
Coupled mixed vector laws need a joint stratum reference; composition that
lacks this information fails explicitly.
Censoring and truncation use these interval masses for different purposes.
An interval-censored observation contributes the event's raw mass. A truncated
response instead uses the normalized restriction as its whole response law.
The Censored distribution is a third operation: it clamps sampled values to
its endpoints and retains the resulting endpoint atoms.
Restriction masks excluded values before invoking a base density. This retains
zero mass outside either the interval or a parameter-dependent base support,
without evaluating an invalid logarithm in an inactive branch. Independent event
coordinates reduce the mask to their event's batch axes. Conditional
families.Truncated reuses Normalize(Restrict(...)) for its coordinate laws;
both interfaces share the rejection loop while retaining their sampling policy
and attempt budget. Normal coordinates retain their specialized inverse sampler.
Batch selection and transformed event shapes¶
Measure.select_batch(active, output_shape=...) selects active batch cells
while retaining each event intact. Mixture components, restrictions, and
normalizers delegate through this operation; a vector response's component
axis is not another batch axis.
A pushforward obtains its output event shape from the bijector's
forward_shape; inversion uses inverse_shape. Its jacobian_event_dim
states which trailing event coordinates the Jacobian already reduces.
Composition reduces any remaining event coordinates exactly once. Thus a
shape-changing stick-breaking map retains its simplex event axis, and a
composed vector map does not duplicate or omit the change-of-variables term.
Parameterized bijectors implement select_batch alongside the measure so
masked evaluation uses the corresponding parameters.
measure
¶
Sub-Giry measures and their primitive transformations.
A Measure is an unnormalized positive measure on a Borel space. Probability
measures have total mass one; restrictions and likelihood scores may produce
sub-probability measures. The runtime tracks total mass as a log normalizer and
normalizes at sample or observation boundaries.
The module provides point masses, restriction, pushforward through a bijector,
finite mixtures, event-dimension declarations with Independent, and
normalization of positive-mass sub-measures.
Measure
¶
Bases: Distribution, ABC
Abstract base for sub-Giry monad values.
The runtime tracks each Measure as a sub-distribution: it
has a log_prob returning the unnormalised log-density and a
log_normalizer() returning the log of the total mass. For
probability measures (mass one), log_normalizer() returns
zero by definition. For sub-measures from Restrict or
Mixture with unnormalised weights, log_normalizer() carries
the residual mass symbolically until the next
Normalize or
sample / observe boundary.
log_prob_normalized(value) is a derived helper returning
log_prob(value) - log_normalizer() so consumers that want the
probability-measure log-density can ask for it explicitly.
log_normalizer
abstractmethod
¶
log_normalizer() -> Tensor
Log of the total mass of this measure. For probability measures, zero. For sub-measures, the symbolic normaliser the lazy algebra carries through composition.
select_batch
¶
select_batch(active: Tensor, *, output_shape=None) -> Distribution
Reconstruct selected rows of the compositional measure algebra.
| PARAMETER | DESCRIPTION |
|---|---|
active
|
Boolean selection over the measure's broadcast batch.
TYPE:
|
output_shape
|
Optional selected batch layout, retaining reinterpreted event axes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Distribution
|
The same measure construction on the selected parameter rows. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If a custom measure supplies no batch reconstruction rule. |
Source code in src/quivers/continuous/measure.py
log_prob_normalized
¶
Log-density of the renormalised probability measure.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Evaluation points, broadcast against the distribution batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log density after subtracting the raw total log mass. |
Source code in src/quivers/continuous/measure.py
log_interval_mass
¶
Read a raw event mass supplied by the concrete measure algebra.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Optional scalar bounds.
TYPE:
|
high
|
Optional scalar bounds.
TYPE:
|
lower_closed
|
Whether each endpoint belongs to the event.
TYPE:
|
upper_closed
|
Whether each endpoint belongs to the event.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Raw log event mass. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If a custom measure has no interval integration capability. |
Source code in src/quivers/continuous/measure.py
log_cdf
¶
Read raw log mass on the closed lower half-line.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Scalar cutoffs, broadcast against the measure batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log mass on |
Source code in src/quivers/continuous/measure.py
log_survival_function
¶
Read raw log mass on the open upper half-line.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Scalar cutoffs, broadcast against the measure batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log mass on |
Source code in src/quivers/continuous/measure.py
log_cdf_left
¶
Read raw log mass strictly below a cutoff.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Scalar cutoffs, broadcast against the measure batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log mass on |
Source code in src/quivers/continuous/measure.py
log_survival_function_left
¶
cdf
¶
Read raw lower-half-line mass from the same interval operation.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Scalar cutoffs, broadcast against the measure batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
CDF for a normalized measure; raw cumulative mass otherwise. |
Source code in src/quivers/continuous/measure.py
PointMass
¶
PointMass(value: Tensor | float, validate_args: bool | None = None)
Bases: Measure
Dirac measure at a deterministic value.
The unit \(\eta\) of the Giry monad: PointMass(x) is the
measure that places mass one on the singleton \(\{x\}\).
log_prob(y) is zero when y == value and \(-\infty\)
otherwise.
In a Mixture alongside
a non-degenerate component, PointMass is the structural-zero
spike that yields zero-inflation and hurdle factorisations.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Retained location of the atom.
TYPE:
|
validate_args
|
Optional Torch argument-validation policy.
TYPE:
|
Source code in src/quivers/continuous/measure.py
mean
property
¶
mean: Tensor
Expected response under the probability law.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Expected response under the probability law. |
variance
property
¶
variance: Tensor
Response variance under the probability law.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Response variance under the probability law. |
atom_reference
¶
Identify the retained Dirac carrier independently of scalar dtype.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Whether each query equals the retained atom. |
Source code in src/quivers/continuous/measure.py
log_atom_mass
¶
Read singleton mass under the same Dirac carrier.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Zero at the atom and negative infinity elsewhere. |
Source code in src/quivers/continuous/measure.py
support
¶
support() -> Constraint
Constraint describing valid response values.
| RETURNS | DESCRIPTION |
|---|---|
Constraint
|
Constraint describing valid response values. |
Source code in src/quivers/continuous/measure.py
log_normalizer
¶
log_normalizer() -> Tensor
Log of the raw total mass, one value per batch entry.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log of the raw total mass, one value per batch entry. |
expand
¶
Broadcast the retained atom over a new batch shape.
| PARAMETER | DESCRIPTION |
|---|---|
batch_shape
|
Requested broadcast batch shape.
TYPE:
|
_instance
|
Unused Torch expansion instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Distribution with the requested batch shape and retained construction. |
Source code in src/quivers/continuous/measure.py
log_interval_mass
¶
Keep the atom exactly when both interval bounds admit its value.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Optional event bounds.
TYPE:
|
high
|
Optional event bounds.
TYPE:
|
lower_closed
|
Endpoint membership.
TYPE:
|
upper_closed
|
Endpoint membership.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Zero at included atoms and negative infinity elsewhere. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an endpoint is NaN. |
Source code in src/quivers/continuous/measure.py
icdf
¶
Return the atom at every valid probability.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Evaluation points, broadcast against the distribution batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Response quantiles at the requested probabilities. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a probability is NaN or lies outside [0,1]. |
Source code in src/quivers/continuous/measure.py
log_prob
¶
The log mass at a point: zero at the atom, -inf elsewhere.
The result takes the floating dtype of value (the default
dtype for an integer or Boolean value), so a double-precision
mixture is not rounded to single precision by its atom's term.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The log masses. |
Source code in src/quivers/continuous/measure.py
sample
¶
Draws from the normalized law with leading sample dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
sample_shape
|
Leading independent sampling dimensions. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Draws from the normalized law with leading sample dimensions. |
Source code in src/quivers/continuous/measure.py
Restrict
¶
Restrict(base: Distribution, low: Tensor | float | None = None, high: Tensor | float | None = None, validate_args: bool | None = None, *, lower_closed: bool | Tensor = True, upper_closed: bool | Tensor = True)
Bases: Measure
Restriction of a base distribution to a sub-interval.
Restricts base to the interval [low, high] (with low or
high set to \(\pm\infty\) for one-sided restrictions). The
log-density is base.log_prob(value) inside the interval and
\(-\infty\) outside; the symbolic log-normaliser is the log of
the base measure's mass on [low, high].
The compiler does not renormalise eagerly; the sub-measure
propagates through Mixture, Pushforward, and other
operators until a Normalize
or sample / observe boundary collapses it. This is the
discipline that makes the algebra close, per
Di Lavore-Roman-Sobocinski 2025.
Normal interval masses use log-CDF differences with tail reflection. Other continuous bases use their CDF difference, and discrete bases use interval probabilities that include both endpoints.
| PARAMETER | DESCRIPTION |
|---|---|
base
|
Underlying distribution or raw measure.
TYPE:
|
low
|
Optional interval endpoints; omitted sides are unbounded.
TYPE:
|
high
|
Optional interval endpoints; omitted sides are unbounded.
TYPE:
|
validate_args
|
Optional Torch argument-validation policy.
TYPE:
|
lower_closed
|
Endpoint membership, closed by default; Boolean tensors may vary by batch row.
TYPE:
|
upper_closed
|
Endpoint membership, closed by default; Boolean tensors may vary by batch row.
TYPE:
|
Source code in src/quivers/continuous/measure.py
support
¶
support() -> Constraint
Intersect the base support with the exact interval event.
| RETURNS | DESCRIPTION |
|---|---|
Constraint
|
Includes closed endpoint atoms and excludes open endpoints. |
Source code in src/quivers/continuous/measure.py
log_normalizer
¶
log_normalizer() -> Tensor
Log of the raw total mass, one value per batch entry.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log of the raw total mass, one value per batch entry. |
Source code in src/quivers/continuous/measure.py
log_interval_mass
¶
Query the raw mass of an intersection without normalizing twice.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Lower event bound; None leaves that side unbounded.
TYPE:
|
high
|
Upper event bound; None leaves that side unbounded.
TYPE:
|
lower_closed
|
Whether the lower endpoint belongs to the event.
TYPE:
|
upper_closed
|
Whether the upper endpoint belongs to the event.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Raw log mass on the requested interval, retaining independent batch axes. |
Source code in src/quivers/continuous/measure.py
expand
¶
Broadcast the retained restriction without changing endpoint semantics.
| PARAMETER | DESCRIPTION |
|---|---|
batch_shape
|
Requested broadcast batch shape.
TYPE:
|
_instance
|
Unused Torch expansion instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Distribution with the requested batch shape and retained construction. |
Source code in src/quivers/continuous/measure.py
atom_reference
¶
Preserve the base carrier even when restriction removes its mass.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Membership in the fixed base atomic carrier. |
Source code in src/quivers/continuous/measure.py
log_atom_mass
¶
Restrict base singleton masses using the retained endpoint policy.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Raw singleton log mass inside the restriction. |
Source code in src/quivers/continuous/measure.py
log_prob
¶
Raw log density or mass at the evaluation points.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Evaluation points, broadcast against the distribution batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Raw log density or mass at the evaluation points. |
Source code in src/quivers/continuous/measure.py
sample
¶
Draw from the restricted, renormalised measure.
A base with a closed-form CDF and inverse CDF is drawn by inversion: a uniform draw between the CDF at the two ends of the interval, mapped back through the inverse CDF, which is exactly the base conditioned on the interval. Any other base is drawn by rejection one entry at a time: each entry outside the interval is redrawn from the base until it falls inside, so every entry is an independent draw of the conditioned base.
| PARAMETER | DESCRIPTION |
|---|---|
sample_shape
|
The leading sample shape. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Draws of shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the restricted measure has zero or nonfinite total mass. |
RuntimeError
|
If rejection leaves an entry outside the interval after
|
Source code in src/quivers/continuous/measure.py
Pushforward
¶
Pushforward(base: Distribution, bijector: Bijector, validate_args: bool | None = None)
Bases: Measure
Pushforward of a base distribution through a bijector.
Implements \(f_*\mu\), the measure whose log-density at y is
base.log_prob(b.inverse(y)) + b.inverse_log_det_jacobian(y).
Functorial in b: composing bijectors composes the pushforward.
Does not commute with Restrict
in general; the compiler's rewrite pass handles the cases that
do (monotone bijectors with interval restrictions).
| PARAMETER | DESCRIPTION |
|---|---|
base
|
Underlying distribution or raw measure.
TYPE:
|
bijector
|
Invertible measurable coordinate transformation.
TYPE:
|
validate_args
|
Optional Torch argument-validation policy.
TYPE:
|
Source code in src/quivers/continuous/measure.py
support
¶
support() -> Constraint
Constraint describing valid response values.
| RETURNS | DESCRIPTION |
|---|---|
Constraint
|
Constraint describing valid response values. |
Source code in src/quivers/continuous/measure.py
log_normalizer
¶
log_normalizer() -> Tensor
Preserve the base measure's raw mass under the bijection.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log total mass on the retained batch axes. |
Source code in src/quivers/continuous/measure.py
log_interval_mass
¶
Pull an interval back through the bijector's scalar capability.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Lower event bound; None leaves that side unbounded.
TYPE:
|
high
|
Upper event bound; None leaves that side unbounded.
TYPE:
|
lower_closed
|
Whether the lower endpoint belongs to the event.
TYPE:
|
upper_closed
|
Whether the upper endpoint belongs to the event.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Raw log mass on the requested interval, retaining independent batch axes. |
Source code in src/quivers/continuous/measure.py
atom_reference
¶
Pull the atomic carrier back through the retained bijection.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points in the image space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Membership in the image of the base carrier. |
Source code in src/quivers/continuous/measure.py
log_atom_mass
¶
Transport singleton masses without a density Jacobian.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points in the image space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Raw singleton log mass in the image space. |
Source code in src/quivers/continuous/measure.py
log_prob
¶
Raw log density or mass at the evaluation points.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Evaluation points, broadcast against the distribution batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Raw log density or mass at the evaluation points. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If a mixed vector law requires an undeclared stratified reference. |
Source code in src/quivers/continuous/measure.py
sample
¶
Draws from the normalized law with leading sample dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
sample_shape
|
Leading independent sampling dimensions. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Draws from the normalized law with leading sample dimensions. |
Source code in src/quivers/continuous/measure.py
Mixture
¶
Mixture(weights: Tensor, components: list[Distribution], validate_args: bool | None = None)
Bases: Measure
Finite mixture of arbitrary-family components.
weights is a vector summing to one (or, in the sub-measure
regime, any non-negative vector; the total mass is the sum).
components is a list of Distribution instances, possibly of
different families and possibly including
PointMass for
inflation / hurdle structure.
The log-density is logsumexp(log_weights + log_components)
over the component axis, broadcasting weights against the
distribution batch shape. The symbolic log-normaliser is
log(sum_k w_k * Z_k) where Z_k is the per-component
normaliser (in particular when components are themselves
sub-measures from Restrict).
Associativity (the Giry monad's multiplication law) is
canonicalised by flatten(), which the compiler's rewrite
pass calls before lowering.
PyMC issue #5533 documents how nested-mixture composition breaks in production PPLs; the operator algebra closes the gap.
| PARAMETER | DESCRIPTION |
|---|---|
weights
|
Nonnegative raw component weights on the last axis.
TYPE:
|
components
|
Laws with the same event shape and broadcastable batches.
TYPE:
|
validate_args
|
Optional Torch argument-validation policy.
TYPE:
|
Source code in src/quivers/continuous/measure.py
num_components
property
¶
Number of retained mixture components.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of retained mixture components. |
component_probabilities
property
¶
component_probabilities: Tensor
Normalized probabilities of the components.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
mean
property
¶
mean: Tensor
Mean of the normalized mixture, sum_k p_k E_k[Y].
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The mean on the batch and event axes. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If a component has no analytic mean. |
variance
property
¶
variance: Tensor
Variance of the normalized mixture by the law of total variance.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If a component has no analytic mean or variance. |
support
¶
support() -> Constraint
Constraint describing valid response values.
| RETURNS | DESCRIPTION |
|---|---|
Constraint
|
Constraint describing valid response values. |
Source code in src/quivers/continuous/measure.py
log_normalizer
¶
log_normalizer() -> Tensor
Read raw total mass using the common weighted measure sum.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log mass on each mixture batch entry. |
Source code in src/quivers/continuous/measure.py
log_interval_mass
¶
Add raw component event masses, including any point atoms.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Lower event bound; None leaves that side unbounded.
TYPE:
|
high
|
Upper event bound; None leaves that side unbounded.
TYPE:
|
lower_closed
|
Whether the lower endpoint belongs to the event.
TYPE:
|
upper_closed
|
Whether the upper endpoint belongs to the event.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Raw log mass on the requested interval, retaining independent batch axes. |
Source code in src/quivers/continuous/measure.py
expand
¶
Broadcast the common mixture batch and its component weights.
| PARAMETER | DESCRIPTION |
|---|---|
batch_shape
|
Requested broadcast batch shape.
TYPE:
|
_instance
|
Unused Torch expansion instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Distribution with the requested batch shape and retained construction. |
Source code in src/quivers/continuous/measure.py
atom_reference
¶
Take the union of component carriers, including zero-weight components.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Membership in at least one component atomic carrier. |
Source code in src/quivers/continuous/measure.py
log_atom_mass
¶
Add weighted singleton masses under the common atomic carrier.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Weighted raw singleton log mass. |
Source code in src/quivers/continuous/measure.py
log_prob
¶
Raw log density or mass at the evaluation points.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Evaluation points, broadcast against the distribution batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Raw log density or mass at the evaluation points. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If mixed vector components lack a common stratified reference measure. |
Source code in src/quivers/continuous/measure.py
sample
¶
Draws from the normalized law with leading sample dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
sample_shape
|
Leading independent sampling dimensions. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Draws from the normalized law with leading sample dimensions. |
Source code in src/quivers/continuous/measure.py
flatten
¶
flatten() -> Mixture
Apply the Giry-monad-multiplication associativity rule:
any nested Mixture component is replaced by its components
with weights scaled by the outer weight. Returns a flat
Mixture whose components are not themselves Mixture
instances.
| RETURNS | DESCRIPTION |
|---|---|
Mixture
|
Equivalent mixture with nested component weights multiplied. |
Source code in src/quivers/continuous/measure.py
pushforward_inside
¶
pushforward_inside(bijector) -> Mixture
Push a single bijector inside every component:
Functoriality of the Giry monad on measurable isomorphisms; the per-component pushforward is the canonical shape the renderer prefers.
| PARAMETER | DESCRIPTION |
|---|---|
bijector
|
Measurable invertible coordinate transformation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Mixture
|
Mixture obtained by applying the bijector to each component. |
Source code in src/quivers/continuous/measure.py
restrict_to
¶
restrict_to(low=None, high=None, *, lower_closed=True, upper_closed=True) -> Mixture
Condition the raw mixture on an endpoint-aware interval.
Components retain their restricted raw measures. Dividing each original weight by the common event mass normalizes their sum; component selection then uses the same weighted masses as every other mixture. Zero-mass components need no separate normalization.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Optional event bounds.
TYPE:
|
high
|
Optional event bounds.
TYPE:
|
lower_closed
|
Endpoint membership, closed by default.
TYPE:
|
upper_closed
|
Endpoint membership, closed by default.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Mixture
|
A probability measure on the requested event. Its retained component weights multiply raw restricted measures. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the event has zero or nonfinite mass on any batch entry. |
Source code in src/quivers/continuous/measure.py
lift_point_masses
¶
lift_point_masses() -> Mixture
Surface the PointMass components as a Bernoulli-style
branch with the non-degenerate components in the
complementary mixture. Returns a Mixture whose components
are pairwise measure-disjoint: each PointMass(x) carries
only its spike, and the non-degenerate components live in the
complement.
For a single PointMass plus a single non-degenerate
component (the ZIP / hurdle canonical shape), the rewrite is
a no-op: the current form is already the Bernoulli-branch
factorisation the renderers expect. For Mixtures with
multiple PointMass components at distinct values, returns a
canonical form with the point masses ordered first.
| RETURNS | DESCRIPTION |
|---|---|
Mixture
|
Equivalent mixture with atomic components placed first. |
Source code in src/quivers/continuous/measure.py
Independent
¶
Independent(base: Distribution, reinterpreted_batch_ndims: int | Tensor, validate_args: bool | None = None)
Bases: Measure
Reinterpret the last reinterpreted_batch_ndims batch dims
of base as event dims. Wraps PyTorch's
Independent.
The log-density sums base.log_prob(value) over the
reinterpreted dims; the log-normaliser sums in the same
direction when base is itself a sub-measure.
| PARAMETER | DESCRIPTION |
|---|---|
base
|
Independent coordinate laws or raw measures.
TYPE:
|
reinterpreted_batch_ndims
|
Nonnegative number of trailing batch axes forming one event. Zero preserves the base law's batch and event axes. A tensor must be scalar and carry an integer value.
TYPE:
|
validate_args
|
Optional Torch argument-validation policy.
TYPE:
|
Source code in src/quivers/continuous/measure.py
has_rsample
property
¶
Whether the base law supports a pathwise sample.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
The base law's declared sampling capability. |
mean
property
¶
mean: Tensor
Base means with the declared batch and event axes retained.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Coordinate means, when defined by the base law. |
variance
property
¶
variance: Tensor
Base marginal variances with every coordinate axis retained.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Marginal coordinate variances, when defined by the base law. |
rsample
¶
Draw pathwise samples only when the base law supports them.
| PARAMETER | DESCRIPTION |
|---|---|
sample_shape
|
Additional leading independent sample axes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Base pathwise draws with the same coordinate layout. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If the base law has no pathwise sampler. |
Source code in src/quivers/continuous/measure.py
support
¶
support() -> Constraint
Constraint describing valid response values.
| RETURNS | DESCRIPTION |
|---|---|
Constraint
|
Constraint describing valid response values. |
Source code in src/quivers/continuous/measure.py
log_normalizer
¶
log_normalizer() -> Tensor
Reduce raw mass over the newly declared independent event axes.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log total mass with only independent batch axes retained. |
Source code in src/quivers/continuous/measure.py
log_interval_mass
¶
Multiply independent coordinate event masses by adding their logarithms.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Lower event bound; None leaves that side unbounded.
TYPE:
|
high
|
Upper event bound; None leaves that side unbounded.
TYPE:
|
lower_closed
|
Whether the lower endpoint belongs to the event.
TYPE:
|
upper_closed
|
Whether the upper endpoint belongs to the event.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Raw log mass on the requested interval, retaining independent batch axes. |
Source code in src/quivers/continuous/measure.py
atom_reference
¶
Identify singleton atoms jointly across reinterpreted event axes.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Queries with intrinsic event axes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Whether every coordinate belongs to its base atomic carrier. |
Source code in src/quivers/continuous/measure.py
log_atom_mass
¶
Multiply coordinate singleton masses across declared event axes.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Queries with intrinsic event axes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Joint singleton log mass. |
Source code in src/quivers/continuous/measure.py
log_prob
¶
Raw log density or mass at the evaluation points.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Evaluation points, broadcast against the distribution batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Raw log density or mass at the evaluation points. |
Source code in src/quivers/continuous/measure.py
sample
¶
Draws from the normalized law with leading sample dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
sample_shape
|
Leading independent sampling dimensions. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Draws from the normalized law with leading sample dimensions. |
Source code in src/quivers/continuous/measure.py
Normalize
¶
Normalize(base: Distribution, validate_args: bool | None = None)
Bases: Measure
Rescale a sub-measure to a probability measure.
log_prob_normalized(value) = log_prob(value) - log_normalizer()
by construction; this wrapper makes the normalisation explicit
so downstream code can rely on log_normalizer() == 0. Use at
the observe / sample boundary or whenever a probability measure
is required (e.g. before sampling).
| PARAMETER | DESCRIPTION |
|---|---|
base
|
Raw measure with finite positive total mass on every batch entry.
TYPE:
|
validate_args
|
Optional Torch argument-validation policy.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If any base batch entry has zero or nonfinite total mass. |
Source code in src/quivers/continuous/measure.py
mean
property
¶
mean: Tensor
Mean of a scalar law conditioned on an interval, without sampling.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The truncated mean from a closed form, a finite sum, or deterministic quadrature, in the dtype of the base law. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If the base is not the restriction of a scalar law to an interval, or no deterministic rule covers that law there. |
support
¶
support() -> Constraint
Constraint describing valid response values.
| RETURNS | DESCRIPTION |
|---|---|
Constraint
|
Constraint describing valid response values. |
Source code in src/quivers/continuous/measure.py
log_normalizer
¶
log_normalizer() -> Tensor
Log of the raw total mass, one value per batch entry.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log of the raw total mass, one value per batch entry. |
Source code in src/quivers/continuous/measure.py
log_interval_mass
¶
Normalize the same base event mass by the retained total mass.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Lower event bound; None leaves that side unbounded.
TYPE:
|
high
|
Upper event bound; None leaves that side unbounded.
TYPE:
|
lower_closed
|
Whether the lower endpoint belongs to the event.
TYPE:
|
upper_closed
|
Whether the upper endpoint belongs to the event.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Raw log mass on the requested interval, retaining independent batch axes. |
Source code in src/quivers/continuous/measure.py
expand
¶
Broadcast a normalized measure through its underlying construction.
| PARAMETER | DESCRIPTION |
|---|---|
batch_shape
|
Requested broadcast batch shape.
TYPE:
|
_instance
|
Unused Torch expansion instance.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
Distribution with the requested batch shape and retained construction. |
Source code in src/quivers/continuous/measure.py
atom_reference
¶
Preserve the base atomic carrier under normalization.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Membership in the base carrier. |
Source code in src/quivers/continuous/measure.py
log_atom_mass
¶
Normalize raw base singleton masses exactly once.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Query points.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Normalized singleton log mass. |
Source code in src/quivers/continuous/measure.py
log_prob
¶
Raw log density or mass at the evaluation points.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Evaluation points, broadcast against the distribution batch.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Raw log density or mass at the evaluation points. |
Source code in src/quivers/continuous/measure.py
sample
¶
Draws from the normalized law with leading sample dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
sample_shape
|
Leading independent sampling dimensions. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Draws from the normalized law with leading sample dimensions. |
Source code in src/quivers/continuous/measure.py
truncated_law
¶
truncated_law(base: Distribution, event: Mapping[str, Tensor | float | int | None] | None) -> Distribution
The sampling law of a response under its recording roles.
| PARAMETER | DESCRIPTION |
|---|---|
base
|
The response law.
TYPE:
|
event
|
The bound recording roles. Only a truncation interval changes how a response is sampled; censoring says how it is recorded.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Distribution
|
|
Source code in src/quivers/continuous/measure.py
normalize_at_boundary
¶
normalize_at_boundary(d: Distribution) -> Distribution
Lift d to a probability measure if it is a sub-measure
with non-zero log-normaliser; otherwise return d unchanged.
Called by the inline / observe path to enforce the "renormalise at the observe / sample boundary" invariant the sub-Giry algebra relies on.
| PARAMETER | DESCRIPTION |
|---|---|
d
|
Native distribution or measure to normalize at an execution boundary.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Distribution
|
Probability law, with explicit normalization when required. |
Source code in src/quivers/continuous/measure.py
Cited sources¶
José M. Bernardo and Adrian F. M. Smith. Bayesian Theory. Wiley, 1994. URL: https://onlinelibrary.wiley.com/doi/book/10.1002/9780470316870, doi:10.1002/9780470316870.