Inline Distribution Builders¶
The morphisms the DSL compiler emits for an inline family call such as
sample x <- 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 becomes a
MixedInlineDistribution,
which reads the bound arguments from its stacked input and fills in the
literals. 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::
draw x ~ LogitNormal(0.0, 1.0) # all fixed
draw b ~ Bernoulli(x) # direct variable
draw r ~ TruncatedNormal(mu, sigma, 0.0, 1.0) # mixed
Terminology
- Fixed: all distribution parameters are float literals known at
compile time. The morphism has domain
Unit(terminal object) and ignores its input. - 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.
FixedDistribution
¶
FixedDistribution(codomain: AnySpace, make_dist: Callable, discrete: bool = False, support: Constraint | None = None, *, domain: AnySpace = Unit)
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.
| 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:
|
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
|
Log-probabilities. Shape |
Source code in src/quivers/continuous/inline.py
MixedInlineDistribution
¶
MixedInlineDistribution(domain: AnySpace, codomain: AnySpace, param_spec: list[tuple[str, int | float | None]], dist_builder: Callable, discrete: bool = False, support: Constraint | None = None, param_event_ranks: tuple[int, ...] | None = None)
Bases: ContinuousMorphism
General inline distribution with arbitrary literal/variable mix.
Handles any combination of literal float 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::
draw x ~ Normal(0.0, 1.0) # all fixed (0 variable inputs)
draw y ~ Normal(mu, sigma) # all variable (2 variable inputs)
draw z ~ Normal(mu, 0.5) # mixed (1 variable input)
draw w ~ TruncatedNormal(mu, 0.5, 0.0, 1.0) # mixed
| 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:
|
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_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: float | list[float], codomain: AnySpace, *, parameterization: str) -> FixedDistribution
Create a literal categorical from probabilities or logits.
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 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) -> 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:
|
| 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). |
Source code in src/quivers/continuous/inline.py
1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 | |
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).