Deterministic Morphisms¶
A deterministic kernel sends each input to a Dirac measure at a function's output, so a transformation such as softmax can take part in a probabilistic program (let steps) without a further random draw. Its output is still random when its input is. The module gives deterministic kernels for cumulative sums of monotone splines, the softmax projection onto the simplex, and covariance reconstruction from a correlation Cholesky factor and scales.
LearnedFunction is the
learned case: a parameter source applied to the input's
coordinates, followed by an output nonlinearity. It is what a
morphism f : X -> Y [role=function] declaration compiles to, and a program's
let z = f(a, b) calls its
apply_values
with one value per domain factor. Its weights are ordinary module parameters,
fit as point estimates, unless it is constructed with latent=<name>: its
weights are then read from the sites
network_weight_sites
names, passed to each evaluation, as a [weights=latent] declaration draws
them.
SequenceFunction is the
learned case over whole sequences, what a [role=function] declaration with
param_source=self_attention or param_source=positions(N) compiles to. Its
input keeps a position axis before the coordinate axis, shape
(..., T, d), and its network reads every position at once: a
SelfAttentionSource
mixes the positions, and a
PositionSource adds a
learned vector to each. A program's let h = attn(u) passes it one sequence.
deterministic
¶
Deterministic morphisms in :math:\mathbf{Kern}.
Each builder returns a ContinuousMorphism whose runtime
realisation is a Dirac kernel concentrated on a deterministic
image: cumsum_morphism for ordinal monotone splines,
softmax_morphism for the standard simplex projection,
cholesky_quad_form_morphism for
covariance reconstruction from a correlation Cholesky factor and
a positive-scale vector.
Categorically a deterministic morphism :math:f : X \to Y is the
unit-Kleisli image of a measurable map; its log-density is
:math:-\infty everywhere except at :math:y = f(x) and zero
there. The variational backend treats the sampling path as an
identity reparameterization of the deterministic image and the
log-density as a no-op (the surrounding KL terms absorb the
Dirac indicator).
FunctionOutput
¶
The nonlinearity a LearnedFunction applies to its network's output.
DeterministicMorphism
¶
DeterministicMorphism(domain: AnySpace, codomain: AnySpace, apply: Callable[[Tensor], Tensor], name: str, *, mappable: bool = False)
Bases: ContinuousMorphism
Helper base for deterministic morphisms f : X → Y.
A deterministic morphism in :math:\mathbf{Kern} is a Dirac
kernel concentrated on :math:f(x). Its log-density is
:math:-\infty everywhere except at :math:y = f(x) and
:math:0 (= :math:\log 1) there; for gradient-based inference
we treat the sampling path as an identity reparameterization
of the deterministic image.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
The input space.
TYPE:
|
codomain
|
The output space.
TYPE:
|
apply
|
The map |
name
|
The morphism's name.
TYPE:
|
mappable
|
Whether
TYPE:
|
Source code in src/quivers/continuous/deterministic.py
point_mass_value
¶
The Dirac's location, :math:f(x).
Reporting it lets a composition through this morphism integrate over its codomain exactly, by evaluating the next kernel at the single point carrying all the mass, instead of approximating an integral that has no spread to resolve.
Source code in src/quivers/continuous/deterministic.py
LearnedFunction
¶
LearnedFunction(domain: AnySpace, codomain: AnySpace, source: ParamSource, output: FunctionOutput = 'identity', latent: str | None = None)
Bases: DeterministicMorphism
A learned deterministic map f : X -> Y between continuous spaces.
The map applies a parameter source to the input's coordinates and
then an output nonlinearity, :math:f(x) = \sigma(g_\theta(x)),
with :math:g_\theta a LinearSource
(the affine map :math:W x + b), an
MLPSource, or an
IdentitySource.
As a kernel it is the Dirac kernel at :math:f(x): it contributes
no density and no site, a composition through it is exact (see
point_mass_value),
and a scan over it is a deterministic recurrence. Its weights are
module parameters, fit as point estimates by the objective that
trains the model around it.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
The input space. A
TYPE:
|
codomain
|
The output space, as wide as the source's output.
TYPE:
|
source
|
The network from input coordinates to output coordinates.
TYPE:
|
output
|
The nonlinearity applied to the network's output.
TYPE:
|
latent
|
When given, the network's weights are latent: they are read from
the sites
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the domain or codomain is not continuous. |
ValueError
|
If the source's output width is not the codomain's width, or
|
Source code in src/quivers/continuous/deterministic.py
latent_sites
property
¶
The site each network parameter is drawn at, when latent.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
Parameter path to site name; empty for point weights. |
output
property
¶
output: FunctionOutput
The nonlinearity applied to the network's output.
| RETURNS | DESCRIPTION |
|---|---|
FunctionOutput
|
Its name. |
factor_widths
property
¶
The width of each factor of the domain, in order.
| RETURNS | DESCRIPTION |
|---|---|
tuple[int, ...]
|
One width per factor. |
evaluate
¶
Apply the map to a batch of inputs.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Inputs, shape
TYPE:
|
weights
|
For latent weights, each site's drawn value by site name;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the coordinate axis is not the domain's width, or latent weights are missing, misshaped, or given for point weights. |
Source code in src/quivers/continuous/deterministic.py
apply_values
¶
Apply the map to one value per domain factor.
This is how a program's let y = f(a, b) calls the map: each
argument is one factor's value, a scalar for a one-wide factor
or a vector of the factor's width, possibly led by axes the
arguments share.
| PARAMETER | DESCRIPTION |
|---|---|
*values
|
One value per factor, in the domain's order.
TYPE:
|
weights
|
For latent weights, each site's drawn value by site name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The image, shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the number of values is not the number of factors, or a value's trailing axis is not its factor's width. |
Source code in src/quivers/continuous/deterministic.py
SequenceFunction
¶
SequenceFunction(domain: AnySpace, codomain: AnySpace, source: SelfAttentionSource | PositionSource)
Bases: LearnedFunction
A learned deterministic map from a sequence of rows to a sequence.
Where a LearnedFunction maps each row on its own, a sequence
function reads every row of a sequence at once: the axis before the
coordinate axis is the position axis, and the image at a position may
depend on every other position. Its network is a
SelfAttentionSource,
which mixes the positions, or a
PositionSource,
which adds a learned vector per position. Like a learned function it
contributes no site and no density, and its weights are module
parameters fit as point estimates.
| PARAMETER | DESCRIPTION |
|---|---|
domain
|
The space of one row of the input sequence; not a product.
TYPE:
|
codomain
|
The space of one row of the output sequence.
TYPE:
|
source
|
The network, from a sequence of domain rows to a sequence of codomain rows.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the domain or codomain is not continuous. |
ValueError
|
If the domain is a product, or the source's output width is not the codomain's width. |
Source code in src/quivers/continuous/deterministic.py
evaluate
¶
Apply the map to a batch of sequences.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Sequences, shape
TYPE:
|
weights
|
Must be
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/quivers/continuous/deterministic.py
apply_values
¶
Apply the map to one sequence, as a program's let call does.
| PARAMETER | DESCRIPTION |
|---|---|
*values
|
The one sequence, shape
TYPE:
|
weights
|
Must be
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Shape |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the call passes other than one value, or |
Source code in src/quivers/continuous/deterministic.py
cumsum_morphism
¶
cumsum_morphism(dim: int) -> DeterministicMorphism
Cumulative sum cumsum : Euclidean(dim) → Euclidean(dim).
Maps :math:(x_1, \dots, x_K) to
:math:(x_1, x_1 + x_2, \dots, \sum_i x_i). The canonical
monotonic-spline parameterization for ordinal covariates
(coef ~ Normal(0, sigma) followed by cumsum(coef - coef[0])
gives a 0-anchored, monotonically-increasing effect across the
ordered levels).
Source code in src/quivers/continuous/deterministic.py
softmax_morphism
¶
softmax_morphism(dim: int) -> DeterministicMorphism
Softmax softmax : Euclidean(dim) → Simplex(dim).
The standard exponential normalizer onto the probability simplex. Useful for closed-form class-probability computations in posterior blocks where one would otherwise need a log-sum-exp aggregation by hand.
Source code in src/quivers/continuous/deterministic.py
cholesky_quad_form_morphism
¶
cholesky_quad_form_morphism(dim: int) -> ContinuousMorphism
Covariance reconstruction (L, s) -> diag(s) L L^T diag(s).
Given a Cholesky factor :math:L of a :math:K \times K
correlation matrix and a positive-scale vector
:math:s \in (0, \infty)^K, returns the corresponding
covariance matrix :math:\Sigma = D R D^T with
:math:R = L L^T and :math:D = \mathrm{diag}(s).
Domain is the product
CholeskyFactor(K) <quivers.continuous.spaces.CholeskyFactor> *
PositiveReals(K) <quivers.continuous.spaces.PositiveReals>;
codomain is Euclidean(K * K) <quivers.continuous.spaces.Euclidean>
flattened in row-major order so the result composes with
downstream
quivers.continuous.families.ConditionalMultivariateNormal
consumers that accept a flat covariance vector.
Source code in src/quivers/continuous/deterministic.py
function_factor_widths
¶
function_factor_widths(space: AnySpace) -> tuple[int, ...]
The width of each factor of a learned function's domain.
| PARAMETER | DESCRIPTION |
|---|---|
space
|
The domain; a
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[int, ...]
|
One width per factor, the one width of a space that is not a product. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If a factor is not continuous. |
Source code in src/quivers/continuous/deterministic.py
learned_function_draw_message
¶
The refusal of a sample or observe that draws from a function.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The learned function's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The message every path raises. |
Source code in src/quivers/continuous/deterministic.py
weight_site_names
¶
The site names of a network's weights and biases, layer by layer.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The network's morphism name.
TYPE:
|
depth
|
The number of hidden layers.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[str, str], ...]
|
One |
Source code in src/quivers/continuous/deterministic.py
network_weight_sites
¶
network_weight_sites(source: Module, name: str) -> dict[str, str]
The site each weight and bias of a network is drawn at.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
The network, whose affine layers are
TYPE:
|
name
|
The network's morphism name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
Each parameter's path in |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a layer has no bias or the network has no affine layer. |