Inline Distribution Builders¶
The DSL compiler emits these morphisms for an
inline family call such as
let x <- sample Normal(loc=mu, scale=1.0). A call whose arguments are all literals becomes a
FixedDistribution, built by a make_fixed_*
factory. A call with at least one bound argument, such as loc=beta * x, becomes a
MixedInlineDistribution, which reads the
bound arguments from its stacked input and fills in the literals, so that
a later draw can depend on an earlier one.
Both can be constructed directly to build a program in Python.
inline
¶
Inline distribution morphisms for monadic programs.
These ContinuousMorphisms parameterize distributions using either fixed literal values or direct variable values, without learned neural-network transformations. Used by the DSL compiler for inline draw steps like::
let x <- sample LogitNormal(mu=0.0, sigma=1.0) # fixed
let b <- sample Bernoulli(probs=x) # variable
let r <- sample TruncatedNormal(mu=mu, sigma=sigma, low=0.0, high=1.0)
Terminology
- Fixed: all distribution parameters are numeric literals known at
compile time. The morphism has domain
Unit(terminal object) and ignores its input. Integer lexemes retain their exact integer carriers until family-specific validation and conversion. - Direct: some or all parameters come from bound variables at runtime. The morphism uses the input tensor directly as distribution parameters (no learned neural-net transformation).
Architecture
Each family is described once by a FamilySpec in
quivers.continuous.family_spec. The factories and builders
below dispatch on the registered spec rather than maintaining
per-family hard-coded functions; specials (truncated, Dirichlet,
uniform, transformed) override the generic dispatch by setting
fixed_factory_override / mixed_builder_override on their
FamilySpec entry.
UnsizedParameterError
¶
Bases: ValueError
An inline family parameter whose shape only the data would fix.
The compiled runtime sizes every parameter when it builds a program, so a matrix parameter whose extents the checked program leaves open cannot be built; the compiler reports it at the draw.
FixedDistribution
¶
FixedDistribution(codomain: AnySpace, make_dist: Callable, discrete: bool = False, support: Constraint | None = None, *, domain: AnySpace = Unit, mappable: bool = False)
Bases: ContinuousMorphism
A distribution with all parameters fixed at construction time.
The rsample input is used only for batch size and device
inference; the distribution parameters themselves are constants.
An explicit Euclidean intrinsic_shape retains tensor event axes.
The constructor owns its native event suffix; remaining scalar coordinate
axes use the shared independent-product measure. Scores retain every
leading sample and execution axis.
| PARAMETER | DESCRIPTION |
|---|---|
codomain
|
The output space.
TYPE:
|
make_dist
|
TYPE:
|
discrete
|
Whether the output is discrete (returns LongTensor).
TYPE:
|
support
|
The support of the underlying distribution. Used by variational
guides to apply the right bijector for unconstrained→constrained
sampling. Defaults to
TYPE:
|
domain
|
Input space whose values select no family parameters. |
mappable
|
Whether the distribution's density can be evaluated at many positions in one pass: it is a tensor computation that branches on no value except through a validator, and changes no tensor in place.
TYPE:
|
Source code in src/quivers/continuous/inline.py
with_domain
¶
with_domain(domain: AnySpace) -> FixedDistribution
Return the same fixed family on a declared input space.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Input space whose values select no family parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
A fixed distribution that keeps the declared kernel domain. |
Source code in src/quivers/continuous/inline.py
rsample
¶
Sample from the fixed distribution.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Input (used only for batch size and device).
TYPE:
|
sample_shape
|
Additional leading sample dimensions. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Samples from the distribution. |
Source code in src/quivers/continuous/inline.py
log_prob
¶
Log-probability under the fixed distribution.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Input (used only for batch size and device).
TYPE:
|
y
|
Output values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
One log density per leading sample and run position for explicitly shaped events; legacy carriers retain their native batch layout. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an explicitly shaped query has incompatible event axes. |
Source code in src/quivers/continuous/inline.py
MixedInlineDistribution
¶
MixedInlineDistribution(domain: AnySpace, codomain: AnySpace, param_spec: list[tuple[str, int | float | Tensor | None]], dist_builder: Callable, discrete: bool = False, support: Constraint | None = None, param_event_ranks: tuple[int, ...] | None = None, param_shapes: tuple[tuple[int, ...] | None, ...] | None = None, param_integers: tuple[bool, ...] | None = None, param_constraints: tuple[str | None, ...] | None = None, param_batch_ndims: tuple[int | None, ...] | None = None, structural_batch_ndims: int = 0)
Bases: ContinuousMorphism
General inline distribution with arbitrary literal/variable mix.
Handles any combination of literal numeric values and runtime variable inputs for any distribution family. At construction time, receives a specification of which parameter positions are fixed literals vs. variable inputs, plus a builder function that creates the PyTorch distribution from fully-resolved parameter tensors.
This is the general mechanism underlying all inline distribution patterns in the DSL::
let x <- sample Normal(loc=0.0, scale=1.0) # all fixed
let y <- sample Normal(loc=mu, scale=sigma) # all variable
let z <- sample Normal(loc=mu, scale=0.5) # mixed
let w <- sample TruncatedNormal(mu=mu, sigma=0.5, low=0.0, high=1.0)
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Source space (stacked variable parameters from program env).
TYPE:
|
codomain
|
Target space.
TYPE:
|
param_spec
|
For each distribution parameter position, one of:
TYPE:
|
dist_builder
|
TYPE:
|
discrete
|
Whether the output is discrete (returns LongTensor).
TYPE:
|
support
|
Support of the underlying distribution; used by variational
guides. Defaults to
TYPE:
|
param_event_ranks
|
The rank of one value of each parameter: 0 for a per-row scalar, 1 for a vector, 2 for a matrix. Defaults to every parameter a scalar.
TYPE:
|
param_shapes
|
For each parameter of rank two or more read from the input, the
shape one row's value has, which its flat columns are laid out
in;
TYPE:
|
param_integers
|
Parameters constrained to integers. Literal and constant counts retain float64 precision independently of the input's dtype.
TYPE:
|
param_constraints
|
Checked custom parameter constraints, distinguishing signed integers and Boolean values from finite trial counts before numeric packing.
TYPE:
|
param_batch_ndims
|
Checked count of enclosing batch axes read by each parameter; None leaves the legacy scalar/vector packing convention in effect.
TYPE:
|
structural_batch_ndims
|
Intrinsic base batch rank proved by a compositional constructor, separate from the conditioning input's leading run axis.
TYPE:
|
Source code in src/quivers/continuous/inline.py
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
with_domain
¶
with_domain(domain: AnySpace) -> MixedInlineDistribution
Return the same all-literal family on a declared input space.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
Input space whose values select no family parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MixedInlineDistribution
|
The family with every parameter a literal, reading its input only for the number of rows. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a parameter is read from the input, whose columns the new domain would not carry. |
Source code in src/quivers/continuous/inline.py
validate_parameter
¶
Validate discrete parameter slots before numeric packing can round them.
| PARAMETER | DESCRIPTION |
|---|---|
position
|
Declared constructor slot.
TYPE:
|
value
|
Original literal or tensor, before concatenation with Real values.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
(ValueError, TypeError)
|
If a Boolean or signed integer violates its carrier, or an integer exceeds this floating packed representation's exact capacity. |
Source code in src/quivers/continuous/inline.py
rsample
¶
Sample from the distribution.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Stacked variable parameters.
TYPE:
|
sample_shape
|
Additional leading sample dimensions. |
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Samples from the distribution. |
Source code in src/quivers/continuous/inline.py
log_prob
¶
Log-probability under the distribution.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Stacked variable parameters.
TYPE:
|
y
|
Observed values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Log-probabilities. Shape matches the broadcast of the
distribution's batch shape with |
Source code in src/quivers/continuous/inline.py
make_fixed_logitnormal
¶
make_fixed_logitnormal(mu: float, sigma: float, codomain: AnySpace) -> FixedDistribution
Create a fixed LogitNormal(mu, sigma) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
mu
|
Location parameter of the underlying normal.
TYPE:
|
sigma
|
Scale parameter of the underlying normal (positive).
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from LogitNormal(mu, sigma). |
Source code in src/quivers/continuous/inline.py
make_fixed_uniform
¶
make_fixed_uniform(low: float, high: float, codomain: AnySpace) -> FixedDistribution
Create a fixed Uniform(low, high) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
low
|
Lower bound.
TYPE:
|
high
|
Upper bound.
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from Uniform(low, high). |
Source code in src/quivers/continuous/inline.py
make_fixed_normal
¶
make_fixed_normal(loc: float, scale: float, codomain: AnySpace) -> FixedDistribution
Create a fixed Normal(loc, scale) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
loc
|
Mean.
TYPE:
|
scale
|
Standard deviation (positive).
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from Normal(loc, scale). |
Source code in src/quivers/continuous/inline.py
make_fixed_bernoulli
¶
make_fixed_bernoulli(prob: float, codomain: AnySpace) -> FixedDistribution
Create a fixed Bernoulli(prob) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
prob
|
Success probability.
TYPE:
|
codomain
|
Output space (FinSet of size 2).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from Bernoulli(prob). |
Source code in src/quivers/continuous/inline.py
make_fixed_beta
¶
make_fixed_beta(concentration1: float, concentration0: float, codomain: AnySpace) -> FixedDistribution
Create a fixed Beta(concentration1, concentration0) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
concentration1
|
Alpha parameter.
TYPE:
|
concentration0
|
Beta parameter.
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from Beta(a, b). |
Source code in src/quivers/continuous/inline.py
make_fixed_logit_beta
¶
make_fixed_logit_beta(concentration1: float, concentration0: float, codomain: AnySpace) -> FixedDistribution
Create a fixed LogitBeta(concentration1, concentration0) distribution.
The draw is logit(p) for p ~ Beta(concentration1,
concentration0), scored and sampled on the real line by
LogitBeta. The shapes
are passed through unclamped, so a shape far below one keeps its
exact density rather than being lifted to a floor.
| PARAMETER | DESCRIPTION |
|---|---|
concentration1
|
The Beta shape on
TYPE:
|
concentration0
|
The Beta shape on
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from LogitBeta(a, b). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If either shape is not positive. |
Source code in src/quivers/continuous/inline.py
make_fixed_log_gamma
¶
make_fixed_log_gamma(concentration: float, rate: float, codomain: AnySpace) -> FixedDistribution
Create a fixed LogGamma(concentration, rate) distribution.
The draw is log(g) for g ~ Gamma(concentration, rate),
scored and sampled on the real line by
LogGamma. The parameters
are passed through unclamped, so a shape far below one keeps its
exact density rather than being lifted to a floor.
| PARAMETER | DESCRIPTION |
|---|---|
concentration
|
The Gamma shape (positive).
TYPE:
|
rate
|
The Gamma rate (positive).
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from LogGamma(concentration, rate). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the shape or the rate is not positive. |
Source code in src/quivers/continuous/inline.py
make_fixed_exponential
¶
make_fixed_exponential(rate: float, codomain: AnySpace) -> FixedDistribution
Create a fixed Exponential(rate) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
rate
|
Rate parameter (positive).
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from Exponential(rate). |
Source code in src/quivers/continuous/inline.py
make_fixed_halfcauchy
¶
make_fixed_halfcauchy(scale: float, codomain: AnySpace) -> FixedDistribution
Create a fixed HalfCauchy(scale) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
scale
|
Scale parameter (positive).
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from HalfCauchy(scale). |
Source code in src/quivers/continuous/inline.py
make_fixed_halfnormal
¶
make_fixed_halfnormal(scale: float, codomain: AnySpace) -> FixedDistribution
Create a fixed HalfNormal(scale) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
scale
|
Scale parameter (positive).
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from HalfNormal(scale). |
Source code in src/quivers/continuous/inline.py
make_fixed_lognormal
¶
make_fixed_lognormal(loc: float, scale: float, codomain: AnySpace) -> FixedDistribution
Create a fixed LogNormal(loc, scale) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
loc
|
Mean of the underlying normal.
TYPE:
|
scale
|
Standard deviation of the underlying normal (positive).
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from LogNormal(loc, scale). |
Source code in src/quivers/continuous/inline.py
make_fixed_gamma
¶
make_fixed_gamma(concentration: float, rate: float, codomain: AnySpace) -> FixedDistribution
Create a fixed Gamma(concentration, rate) distribution.
| PARAMETER | DESCRIPTION |
|---|---|
concentration
|
Shape parameter (positive).
TYPE:
|
rate
|
Rate parameter (positive).
TYPE:
|
codomain
|
Output space.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from Gamma(concentration, rate). |
Source code in src/quivers/continuous/inline.py
make_fixed_dirichlet
¶
make_fixed_dirichlet(concentration: float | list[float], codomain: AnySpace) -> FixedDistribution
Create a fixed Dirichlet(concentration) distribution on the simplex over the codomain's element axis.
| PARAMETER | DESCRIPTION |
|---|---|
concentration
|
Concentration parameter. A scalar is broadcast to all simplex components (symmetric Dirichlet). A list / tuple of length equal to the codomain's dimension specifies per-component concentrations. Each entry must be positive.
TYPE:
|
codomain
|
Output space; its
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling from the chosen Dirichlet on
the (d-1)-simplex embedded in |
Source code in src/quivers/continuous/inline.py
make_fixed_truncated_normal
¶
make_fixed_truncated_normal(mu: float, sigma: float, low: float, high: float, codomain: AnySpace) -> FixedDistribution
Create a fixed truncated normal with literal parameters.
Source code in src/quivers/continuous/inline.py
make_fixed_categorical
¶
make_fixed_categorical(values: object, codomain: AnySpace, *, parameterization: str) -> FixedDistribution
Create a literal categorical from probabilities or logits.
| PARAMETER | DESCRIPTION |
|---|---|
values
|
Real scalar or sequence of real scalar weights. A scalar repeats over the codomain; a scalar tensor retains its numeric value.
TYPE:
|
codomain
|
Existing finite response space fixing the number of categories.
TYPE:
|
parameterization
|
The selected
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Native categorical morphism with its ordinary support validation. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If a weight is not a real scalar literal. |
ValueError
|
If a weight vector's length differs from the codomain cardinality. |
Source code in src/quivers/continuous/inline.py
make_fixed_lkj_cholesky
¶
make_fixed_lkj_cholesky(concentration: float, codomain: AnySpace) -> FixedDistribution
Create a fixed LKJ prior over Cholesky factors of correlation matrices.
| PARAMETER | DESCRIPTION |
|---|---|
concentration
|
The LKJ shape, positive; one is uniform over correlation matrices and larger values concentrate toward the identity.
TYPE:
|
codomain
|
Output space; its
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FixedDistribution
|
Distribution morphism sampling lower-triangular Cholesky factors. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/continuous/inline.py
get_inline_param_names
¶
get_inline_param_names(family: str, families: FamilyCatalog | None = None) -> tuple[str, ...] | None
Get the ordered parameter names for an inline family.
| PARAMETER | DESCRIPTION |
|---|---|
family
|
Distribution family name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...] or None
|
Parameter names, or None if not an inline family. |
Source code in src/quivers/continuous/inline.py
get_inline_parameterizations
¶
Return every complete keyword schema accepted by a family call.
Most families expose one canonical schema. Categorical exposes two
one-parameter schemas so probabilities and logits occupy the same
source-language level without overloading a positional value.
Source code in src/quivers/continuous/inline.py
make_inline_distribution
¶
make_inline_distribution(family: str, args: tuple, codomain: AnySpace, variable_types: dict[str, AnySpace] | None = None, value_extents: Mapping[str, tuple[int, ...]] | None = None, *, sampleable_references: Mapping[str, tuple[ContinuousMorphism, str]] | None = None, batch_ndims: int = 0, families: FamilyCatalog | None = None) -> tuple[ContinuousMorphism, tuple[StepArgument, ...] | None]
Create an inline distribution from family name and mixed args.
Handles any combination of literal and variable arguments for any registered distribution family. The general mechanism:
- All literals →
FixedDistribution(no variable input) - Any variables →
MixedInlineDistributionwith a param_spec that records which positions are literals vs. variable slices
| PARAMETER | DESCRIPTION |
|---|---|
family
|
Distribution family name.
TYPE:
|
args
|
Arguments from the DSL. Strings are variable names, floats are literal values.
TYPE:
|
codomain
|
The output space for the distribution.
TYPE:
|
variable_types
|
Mapping of variable names to their space types (for domain construction of direct distributions).
TYPE:
|
value_extents
|
The checked extents of the values the program binds, by name. A
gather
TYPE:
|
sampleable_references
|
Native kernel references in sampleable argument positions. Their original input context is packed once, independently of scalar or event-valued constructor parameters.
TYPE:
|
batch_ndims
|
Explicit enclosing batch rank retained by the checked observation layout.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of (ContinuousMorphism, tuple[str, ...] | None)
|
The inline distribution morphism, and the variable names to pass as step input (None = use program input). |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a gather indexes more axes than its value's checked extents have. |
Source code in src/quivers/continuous/inline.py
3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 | |
reload_inline_registry
¶
Refresh the inline dicts from
quivers.continuous.family_spec.FAMILY_REGISTRY. Useful
when new families are registered after inline has
imported (test plugins, downstream extensions).