Flows & RBIG¶
These are the Layer 1 assemblies — containers that stack transforms into a full flow, and one-call factories that build a ready-to-train (or already-fitted) Gaussianization flow. A Gaussianization flow alternates a marginal CDF step \(G\) with a rotation \(R\),
driving the data toward a standard normal one block at a time. After \(L\) blocks the flow is a
density estimator (log_prob), a sampler (sample), and — because the latent is Gaussian — a
plug-in estimator for the information-theoretic measures in
Information Theory.
Containers¶
SurVAEFlow is the general container: it threads a key through a chain that may mix
bijections, surjections, and stochastic transforms, and vmaps log_prob / sample over any
leading sample_shape. For a bijection-only chain it matches flowjax.Transformed exactly.
SurVAEFlow
¶
Bases: Module
Container that threads PRNG keys through a mixed bijection / surjection chain.
Composes any sequence of flowjax.bijections.AbstractBijection and
AbstractSurjection transforms. Forward direction is base -> data
(used by sample); inverse direction is data -> base (used by
log_prob). Each transform receives its own independent split of the
user-supplied key, regardless of whether it actually consumes it — this
keeps the call shape uniform and JIT-friendly.
For a chain consisting solely of AbstractBijection instances,
log_prob is identical (up to numerical noise) to that of the
equivalent flowjax.distributions.Transformed(base, Chain(transforms)),
so users can migrate without changing semantics.
Attributes:
| Name | Type | Description |
|---|---|---|
base_dist |
AbstractDistribution
|
A |
transforms |
tuple[AbstractBijection | AbstractSurjection, ...]
|
Tuple of bijections / surjections, applied left-to-right in the forward direction. |
data_shape |
tuple[int, ...]
|
Event shape of the data (output of the forward chain /
input to |
Properties
lower_bound: True iff at least one surjection in the chain
contributes a lower bound to log_prob (i.e. has its
class-level lower_bound flag set).
Conditioning model
sample and log_prob accept a single optional condition
kwarg that is broadcast to every layer in the chain and to the
base distribution. A layer that opts in (cond_shape is not None)
consumes the condition; a layer that does not (cond_shape is
None) silently ignores it. So a single global context vector can
drive any subset of {base, couplings, FiLM-wrapped layers} —
including:
- base only: pair a
ConditionalDiagGaussian/ClassCondDiagGaussian(orpyrox_flows.NumpyroBasein factory mode) base with otherwise unconditional transforms. - transforms only: pair an unconditional base
(
flowjax.distributions.Normal, …) with one or more coupling layers built withcond_dim > 0(or any transform wrapped inConditioner). - both: a conditional base and condition-aware transforms;
the same
conditionreaches both.
Inside a coupling layer there are two distinct conditioning streams:
the data-dependent untransformed half of x (always present —
the whole point of coupling) and the external condition
(present only when cond_dim > 0). The two are concatenated
inside the inner MLP; users do not slice or merge them manually.
Shape
Methods follow the single-event convention but accept a leading
sample_shape that is vmapped over internally:
sample(key, sample_shape, condition)→sample_shape + data_shapelog_prob(x, key, condition):xof shapesample_shape + data_shape→sample_shape
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from flowjax.distributions import Normal
>>> from gauss_flows_models.flows import SurVAEFlow
>>> from gauss_flows_maps.bijections import AffineCoupling
>>> base = Normal(jnp.zeros(4))
>>> flow = SurVAEFlow(base, [AffineCoupling(jr.key(0), shape=(4,))])
>>> x = flow.sample(jr.key(1), (5,))
>>> x.shape
(5, 4)
>>> flow.log_prob(x, jr.key(2)).shape
(5,)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/survae.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
sample
¶
sample(key: PRNGKeyArray, sample_shape: tuple[int, ...] = (), condition: ArrayLike | None = None) -> Array
Sample by drawing from base_dist and pushing through to data.
Each draw uses an independent key derived from key; sample_shape
is realised via jax.vmap over a leading batch of keys, mirroring
the FlowJax convention.
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/survae.py
log_prob
¶
Evaluate log p(x) (or its lower bound if any surjection is lower-bound).
Accepts batched inputs of shape sample_shape + data_shape; the
leading sample_shape dimensions are vmapped over and each sample
receives its own key derived from key. For deterministic chains
(bijections + non-stochastic surjections) the key is unused but still
consumed by the dispatch.
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/survae.py
ClassCondFlow
¶
Bases: Module
Class-conditional flow built on a ClassCondDiagGaussian base.
A thin convenience wrapper around SurVAEFlow that:
- constructs a
ClassCondDiagGaussianbase with the givenn_classesandevent_shape; - exposes a
labelkeyword in its public API (instead of the more genericcondition) for ergonomics in the class-conditional case; - carries
n_classesas static metadata for downstream tooling.
Only the base is class-conditioned. The transform chain must be
unconditional — every transform's cond_shape must be None. This
is because the class label is broadcast as a scalar int (a shape-()
condition that the base requires for index lookup), which is incompatible
with the (cond_dim,)-shaped condition that conditional couplings
expect. If you want conditional transforms in addition to a class-
conditional base, build a SurVAEFlow directly and pack a
label-derived feature vector (e.g. one-hot) into a custom condition;
this wrapper deliberately does not support that to keep the contract
simple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
PRNG key used to initialise the base distribution. |
required |
n_classes
|
int
|
Number of classes |
required |
event_shape
|
tuple[int, ...]
|
Single-event shape |
required |
transforms
|
Sequence[AbstractBijection | AbstractSurjection]
|
Sequence of unconditional bijections / surjections,
applied left-to-right in the base→data direction. Conditional
transforms ( |
required |
learn_mean
|
bool
|
Forwarded to |
True
|
logscale_factor
|
float
|
Forwarded to |
1.0
|
Shape
label: scalar int (cond_shape == ())x/y:event_shape
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.flows import ClassCondFlow
>>> from gauss_flows_maps.bijections import AffineCoupling
>>> coupling = AffineCoupling(jr.key(0), shape=(4,)) # unconditional layer
>>> flow = ClassCondFlow(
... jr.key(1), n_classes=3, event_shape=(4,),
... transforms=[coupling],
... )
>>> label = jnp.int32(1)
>>> x = flow.sample(jr.key(2), label=label)
>>> log_p = flow.log_prob(x, jr.key(3), label=label)
>>> assert x.shape == (4,) and log_p.shape == ()
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/class_cond_flow.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
sample
¶
Sample by drawing from the class-conditional base and pushing through.
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/class_cond_flow.py
log_prob
¶
Evaluate log p(x | label).
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/class_cond_flow.py
Flow factories¶
gaussianization_flow builds the classic marginal-mixture + rotation stack;
coupling_gaussianization_flow swaps the marginal step for spline coupling layers;
iterative_rbig constructs the trainable iterative-RBIG flow. Each returns a FlowJax
Transformed distribution.
gaussianization_flow
¶
gaussianization_flow(key: PRNGKeyArray, *, n_dims: int, n_layers: int = 8, n_components: int = 8, rotation: str = 'householder', n_reflections: int | None = None, base_dist: AbstractDistribution | None = None) -> Transformed
Construct a Gaussianization flow.
Stacks n_layers alternating G∘R blocks, where each block is a
marginal Gaussianization step G (a mixture-of-Gaussians CDF applied
per dimension) followed by a rotation R (Householder, orthogonal, or
LU-parametrised linear). Mixture means and Householder vectors are
randomly initialised to break symmetry so gradient training has a
signal to separate the components. The block stack is composed with a
memory-efficient flowjax.bijections.Scan and wrapped in a
base flowjax.distributions.Normal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
JAX random key. |
required |
n_dims
|
int
|
Dimensionality of the data. |
required |
n_layers
|
int
|
Number of flow layers. Defaults to 8. |
8
|
n_components
|
int
|
Number of mixture components for marginal Gaussianization. Defaults to 8. |
8
|
rotation
|
str
|
Type of rotation, one of |
'householder'
|
n_reflections
|
int | None
|
Number of Householder reflections (only for
|
None
|
base_dist
|
AbstractDistribution | None
|
Optional base distribution override (must have event
shape |
None
|
Returns:
| Type | Description |
|---|---|
Transformed
|
A flowjax |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import jax.random as jr
>>> from gauss_flows_models.flows import gaussianization_flow
>>> flow = gaussianization_flow(jr.key(0), n_dims=4, n_layers=4, n_components=8)
>>> flow.sample(jr.key(1), (8,)).shape
(8, 4)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/gaussianization.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
coupling_gaussianization_flow
¶
coupling_gaussianization_flow(key: PRNGKeyArray, *, n_dims: int, n_layers: int = 8, n_bins: int = 8, nn_width: int = 64, nn_depth: int = 2, interval: float = 5.0, invert: bool = True) -> Transformed
Construct a coupling-based Gaussianization flow.
Stacks n_layers alternating C∘P blocks, where each block is a
rational-quadratic-spline coupling layer C followed by a permutation P
(a flowjax.bijections.Flip for n_dims == 2, a random
flowjax.bijections.Permute otherwise; no permutation for
n_dims == 1). Unlike gaussianization_flow, the coupling
conditioner lets each layer represent non-linear, cross-coordinate
transformations. The block stack is composed with
flowjax.bijections.Scan and wrapped in a base
flowjax.distributions.Normal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
JAX random key. |
required |
n_dims
|
int
|
Dimensionality of the data. |
required |
n_layers
|
int
|
Number of coupling layers. Defaults to 8. |
8
|
n_bins
|
int
|
Number of spline bins in each coupling layer. Defaults to 8. |
8
|
nn_width
|
int
|
Hidden layer width for coupling conditioner. Defaults to 64. |
64
|
nn_depth
|
int
|
Depth of the coupling conditioner MLP. Defaults to 2. |
2
|
interval
|
float
|
Interval for the rational quadratic spline. Defaults to 5.0. |
5.0
|
invert
|
bool
|
Whether to invert the bijection so |
True
|
Returns:
| Type | Description |
|---|---|
Transformed
|
A flowjax |
Examples:
>>> import jax.random as jr
>>> from gauss_flows_models.flows import coupling_gaussianization_flow
>>> flow = coupling_gaussianization_flow(jr.key(0), n_dims=4, n_layers=2)
>>> flow.sample(jr.key(1), (8,)).shape
(8, 4)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/gaussianization.py
iterative_rbig
¶
iterative_rbig(key: PRNGKeyArray, *, n_dims: int, n_layers: int = 100, n_components: int = 8, rotation: str = 'householder', n_reflections: int | None = None) -> Transformed
Construct an iterative RBIG (Rotation-Based Iterative Gaussianization) flow.
Implements the classic RBIG algorithm as a normalizing flow: each of
n_layers iterations alternates a marginal Gaussianization step G
with a rotation R (the G∘R block). This is a thin wrapper around
gauss_flows.gaussianization_flow with a large default
n_layers reflecting the many shallow iterations RBIG typically
uses; all arguments are forwarded unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
JAX random key. |
required |
n_dims
|
int
|
Dimensionality of the data. |
required |
n_layers
|
int
|
Number of RBIG iterations. Defaults to 100. |
100
|
n_components
|
int
|
Number of mixture components for marginal Gaussianization. Defaults to 8. |
8
|
rotation
|
str
|
Type of rotation, either |
'householder'
|
n_reflections
|
int | None
|
Number of Householder reflections. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Transformed
|
A flowjax |
Examples:
>>> import jax.random as jr
>>> from gauss_flows_models.flows import iterative_rbig
>>> flow = iterative_rbig(jr.key(0), n_dims=4, n_layers=3, n_components=4)
>>> flow.sample(jr.key(1), (5,)).shape
(5, 4)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/rbig.py
RBIG warm-start¶
Rotation-Based Iterative Gaussianization fits each block in closed form from data — per-dimension
Gaussian-mixture CDFs followed by a random/PCA rotation — giving a strong warm start with no
gradient training. The result is an ordinary flow that can be used as-is or fine-tuned with
fit_gaussianization_flow.
fit_rbig
¶
fit_rbig(x: ArrayLike, *, n_layers: int = 10, n_components: int = 8, random_state: int = 0) -> Transformed
Fit an iterative-Gaussianization (RBIG) flow to data in closed form.
Greedily walks n_layers blocks of [FixedRotation (PCA),
MixtureGaussianCDF (GMM per-dim)], fitting each block directly from
the current data state — a per-dimension Gaussian-mixture EM fit in
JAX, no gradient training — and propagating the data forward
before the next block. The result is a warm start: a
flowjax.distributions.Transformed whose log_prob is
already a reasonable density estimator and can be refined further by
the usual NLL minimisation (see
gauss_flows.fit_gaussianization_flow).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Training data of shape |
required |
n_layers
|
int
|
Number of |
10
|
n_components
|
int
|
Mixture components |
8
|
random_state
|
int
|
Base seed for the k-means++ draws of the per-dim GMM
EM fits. Each fit uses
|
0
|
Returns:
| Type | Description |
|---|---|
Transformed
|
A flowjax |
Transformed
|
Gaussianises |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import jax.random as jr
>>> from gauss_flows_models.inference import fit_rbig
>>> x = jr.normal(jr.key(0), (500, 2))
>>> flow = fit_rbig(x, n_layers=4, n_components=4)
>>> flow.sample(jr.key(1), (8,)).shape
(8, 2)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/init/rbig.py
fit_rbig_coupling
¶
fit_rbig_coupling(x: ArrayLike, key: PRNGKeyArray, *, n_layers: int = 6, n_components: int = 8, nn_width: int = 64, nn_depth: int = 2, log_scale_bound: float = 5.0, random_state: int = 0) -> Transformed
Warm-start an RBIG-style coupling flow in closed form.
Each block is [FixedRotation (PCA), MixtureGaussianCDFCoupling].
The coupling's conditioner is initialised in closed form — no gradient
training — with a zero kernel and a bias set from per-b-dim Gaussian-mixture
EM fits (via _init_coupling_from_fits), so
the layer starts as a constant-in-x_a mixture-CDF transform on the
x_b half — numerically equivalent to a diagonal marginal fit on
the x_b dims. Gradient training (see
gauss_flows.fit_gaussianization_flow) can then break the
constancy and let the conditioner modulate on x_a.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ArrayLike
|
Training data of shape |
required |
key
|
PRNGKeyArray
|
JAX random key for the conditioner MLPs' hidden-layer init. |
required |
n_layers
|
int
|
Number of |
6
|
n_components
|
int
|
Mixture components per transformed dim. Defaults to 8. |
8
|
nn_width
|
int
|
Hidden layer width of each conditioner MLP. Defaults to 64. |
64
|
nn_depth
|
int
|
Depth of each conditioner MLP. Defaults to 2. |
2
|
log_scale_bound
|
float
|
Tanh bound on per-dim log-scales. Must match the value used at gradient-training time. Defaults to 5.0. |
5.0
|
random_state
|
int
|
Base seed for per-dim GMM EM fits. Defaults to 0. |
0
|
Returns:
| Type | Description |
|---|---|
Transformed
|
A flowjax |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import jax.random as jr
>>> from gauss_flows_models.inference import fit_rbig_coupling
>>> x = jr.normal(jr.key(0), (500, 2))
>>> flow = fit_rbig_coupling(x, jr.key(1), n_layers=2, n_components=4)
>>> flow.sample(jr.key(2), (8,)).shape
(8, 2)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/init/rbig.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
State-space flows¶
Three constructions that put a normalizing flow and a state-space model together.
All take their state-space pieces from gaussx,
which is a declared dependency of gauss-flows-models (pinned by git tag, since gaussx is not on PyPI).
normalizing_kalman_filter itself never imports gaussx — it duck-types on the
base distribution's cond_shape — so it works with any (T, M)-shaped base.
ConjugateTransformFilter and TransformFilter import gaussx at module level.
Normalizing Kalman Filter¶
normalizing_kalman_filter composes a linear-Gaussian state-space base with a
per-timestep observation warp (de Bézenac et al., 2020). The base supplies the
density over the latent series and the warp maps each timestep into observation
space, so the Markov structure survives and the Kalman recursion still applies in
latent space.
The base is typically a LinearGaussianSSM, whose log_prob is the Kalman filter's marginal likelihood; build it with masked=True for partially observed series, or with LinearGaussianSSM.from_sde for a Gaussian-process prior over irregular observation times. The example below uses it.
Two things it exists to get right. First, the construction needs two nested
Vmaps — one over channels, one over time — and skipping the channel one raises a
shape error that mentions neither Vmap nor the axis at fault. The constructor
supplies the time axis and validates the channel axis with an error that names the
fix.
Second, and more consequential: the default recommendation deviates from the
source paper. The paper uses a coupling flow specifically to model cross-series
dependence. With a masked base — partially-observed series — that is unsound.
Marginalising the unobserved channels commutes with the warp only when the warp's
Jacobian is diagonal; a coupling bijection's is triangular, so a missing entry in
the conditioning half corrupts the transform of channels that were observed.
Measured on a 2-layer coupling flow with M = 6 and ~40% missing, the error on the
observed channels alone had median 0.49 against a signal scale of 0.43 — the
corruption is the size of the signal, and it looks like underfitting rather than a
bug. An elementwise warp gives exactly 0.0.
So the recommendation is an elementwise warp with the cross-channel structure in
the state-space model's H and R, where the Kalman recursion handles it
exactly. A mask-conditioned warp is permitted; an unconditional channel-mixing warp
over a masked base is refused at construction. An unmasked base places no
restriction on the warp.
Two details that follow from this and are easy to get wrong:
- The log-det is restricted to the observed channels. Change of variables
applies to the coordinates being modelled, so with a masked base the Jacobian
term is summed under the mask. A plain
Transformedsums it over allT × Mentries, adding terms for values that were never measured — the density then stops being a marginal likelihood, off by a data-dependent offset. The constructor wraps elementwise warps to handle this automatically, subtracting the unobserved channels' contributions from the warp's own log-determinant rather than rebuilding the total from autodiff — so a bijection that reports a log-det differing from its map's derivative (HistogramCDF(method="monotonic")is the in-repo example) keeps its declared value, and an all-observed mask reproduces the ordinary density exactly. In the mask-conditioned case (2) none of this applies: a channel-mixing Jacobian does not decompose per channel, so therelog_probis a training objective, not a marginal likelihood. - A warp is classified structurally, never by measurement. Sampling the
Jacobian cannot establish diagonality, in two independent ways.
OrthogonalRotationstarts with zero Cayley parameters, so it is the identity when you build it and would pass any probe — then becomes a dense rotation the moment an optimiser touches it. And a parameter-free bijection need not have a constant Jacobian either: a fixed shear that engages only past a threshold looks diagonal at every probe point drawn from the bulk and mixes channels in the tail. So classification comes from the type. Recognised are flowjax's elementwise family and everything in gauss_flows' owntransforms.bijections.elementwisesubpackage —MixtureGaussianCDF,MixtureLogisticCDF,RQSplineMarginal,HistogramCDF,InverseGaussCDF,Elementwise. A scalar bijection lifted withVmap(..., axis_size=M)is admitted whatever it contains, since 1x1 Jacobian blocks are diagonal by construction. For a warp outside all of that, passassume_elementwise_warp=Trueto assert the property yourself; a probe still refuses assertions it can immediately disprove, but passing it proves nothing. - Mind the warp's direction.
warpmaps the Gaussian base to observations. The Gaussianising CDFs go the other way —MixtureGaussianCDFmaps data to Gaussian — so they belong inside anInvert:Invert(MixtureGaussianCDF(n_components=8, shape=(M,))). Passing one directly builds a model of the pushforward through the Gaussianiser rather than of the observations.fit_rbigalready follows this convention, returningTransformed(base, Invert(Chain(...))).RQSplineMarginaland a liftedRationalQuadraticSplineare direction-neutral. HistogramCDFneeds a probit step. It maps data to a uniform variable, not a Gaussian one, soInvert(HistogramCDF(...))expects[0, 1]inputs while the base supplies all of ℝ; values outside clamp to the fitted bin edges and the density stops being normalised. Compose it with the stepMixtureGaussianCDFalready includes:Invert(Chain([HistogramCDF(...), InverseGaussCDF(shape=(M,))])).
normalizing_kalman_filter
¶
normalizing_kalman_filter(base: AbstractDistribution, warp: AbstractBijection, *, n_steps: int | None = None, assume_elementwise_warp: bool = False) -> Transformed
Compose a state-space base with a per-timestep observation warp.
Builds the Normalizing Kalman Filter of de Bézenac et al. (2020) by lifting
warp over the time axis, so the base's Markov structure is preserved and
the Kalman recursion still applies in latent space. See the module docstring
for the two-nested-flowjax.bijections.Vmap construction and the reason a
masked base restricts which warps are allowed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
AbstractDistribution
|
Any distribution with event shape |
required |
warp
|
AbstractBijection
|
Bijection with event shape |
required |
n_steps
|
int | None
|
Time-axis size |
None
|
assume_elementwise_warp
|
bool
|
Assert that |
False
|
Returns:
| Type | Description |
|---|---|
Transformed
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Shape
- Base event:
(T, M) - Warp event:
(M,)(single timestep, single event) - Returned distribution event:
(T, M) log_probof a(T, M)observation: scalar()sample(key, (S,)):(S, T, M)
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from flowjax.bijections import Affine, Chain, RationalQuadraticSpline, Vmap
>>> from gauss_flows_models.distributions import LinearGaussianSSM
>>> from gauss_flows_models.filters import normalizing_kalman_filter
>>> M, T = 4, 8
>>> # 1. Channel axis: lift the scalar spline to an M-vector, THEN chain.
>>> warp = Chain([
... Vmap(RationalQuadraticSpline(knots=6, interval=4),
... in_axes=None, axis_size=M),
... Affine(loc=jnp.zeros(M), scale=jnp.ones(M)),
... ])
>>> # A state-space base over (T, M): s_t = A s_{t−1} + q_t, y_t = H s_t + v_t.
>>> base = LinearGaussianSSM(
... transition=0.9 * jnp.eye(M), obs_model=jnp.eye(M),
... process_noise=0.1 * jnp.eye(M), obs_noise=0.1 * jnp.eye(M),
... init_mean=jnp.zeros(M), init_cov=jnp.eye(M), n_steps=T,
... )
>>> nkf = normalizing_kalman_filter(base, warp) # 2. Time axis, for you.
>>> y = nkf.sample(jr.key(0))
>>> nkf.shape, nkf.log_prob(y).shape
((8, 4), ())
With missing data, build the base with masked=True and pass the
observation mask as the condition:
>>> masked_base = LinearGaussianSSM(
... transition=0.9 * jnp.eye(M), obs_model=jnp.eye(M),
... process_noise=0.1 * jnp.eye(M), obs_noise=0.1 * jnp.eye(M),
... init_mean=jnp.zeros(M), init_cov=jnp.eye(M), n_steps=T,
... masked=True,
... )
>>> masked_nkf = normalizing_kalman_filter(masked_base, warp)
>>> mask = jr.bernoulli(jr.key(1), 0.7, (T, M))
>>> masked_nkf.log_prob(y, condition=mask).shape
()
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/kalman.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 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 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | |
Ensemble Conjugate Transform Filter¶
ConjugateTransformFilter performs the ensemble Kalman analysis in a Gaussianised
latent space (Chipilski, 2025): warp the ensemble, update, warp back. The framing
worth keeping is that the EnKF's Gaussian assumption is a statement about
coordinates, not about the algorithm. Applied to a non-Gaussian prior the
physical-space update is biased, and the bias does not shrink with ensemble size —
no number of extra members will fix it. Conjugating the update with a bijection
removes it.
Worth stating the exactness conditions precisely, because they are easy to
over-claim. The conjugated update is exact Bayes only in the population limit,
and only when the observation model is affine with additive Gaussian noise in
the same latent coordinates that Gaussianise the prior. A merely "Gaussian
likelihood" is not enough — y = ζ² + ε has Gaussian noise and a non-Gaussian
posterior no Kalman update reproduces. With a finite ensemble the gain is empirical
and the perturbations are Monte Carlo, so the result is an estimate regardless.
Outside those conditions there is no guaranteed ordering against the
physical-space update: it usually helps, and helps a lot when the prior really is a
warped Gaussian, but a badly matched warp can make the latent joint less Gaussian
and do worse. gauss_flows cannot check the condition for you.
On the reference paper's lognormal / logit-normal problem, whose exact posterior
mean is [0.548062, 0.353937] (error in the posterior mean, averaged over 4 draws):
ensemble size J |
conjugated update | physical-space update |
|---|---|---|
| 2,000 | 0.0030 | 0.0239 |
| 20,000 | 0.0011 | 0.0257 |
| 200,000 | 0.0004 | 0.0260 |
One column converges; the other plateaus.
rbig_conjugate_filter fits the warp with RBIG, which suits the method unusually
well: a closed-form Gaussianising map straight from the prior ensemble, no training
loop — exactly the Γ the method needs, and exactly what the reference
implementation hand-specifies per experiment.
ConjugateTransformFilter
¶
Bases: Module
Ensemble Kalman analysis performed in a Gaussianised latent space.
Implements the Ensemble Conjugate Transform Filter of Chipilski (2025).
Given a bijection \(\Gamma\) that maps a Gaussian latent space onto the
physical state space, analysis warps the ensemble into latent
coordinates, applies gaussx.enkf_analysis there, and warps the result
back. See the module docstring for the accuracy argument.
Exactness caveat. The update is exact Bayes only in the population
limit, and only when the prior really is the pushforward of a Gaussian under
warp and the observation model is affine with additive Gaussian noise
in those same latent coordinates. With a finite ensemble the gain is
empirical and the perturbations are Monte Carlo, so even then the result is
an estimate. "Gaussian likelihood" is not sufficient on its own: a model
like \(y = \zeta^2 + \varepsilon\) has Gaussian noise but a non-Gaussian
posterior this update does not reproduce.
When the assumption does not hold, this is an approximation with no guaranteed ordering against the physical-space update. A poorly matched warp can make the latent joint less Gaussian and give a worse answer than doing nothing — "Gaussianise first" is not monotone. It typically helps, and helps a great deal when the prior is genuinely a warped Gaussian (see the module docstring), but a degraded result is an expected possibility rather than a sign of a bug in the implementation or of too few members. gauss_flows cannot check the condition for you — nothing in the ensemble reveals it — so treat exactness as conditional on a modelling assumption you have made, not as a guarantee the library enforces.
A practical note on warp: analysis calls warp.inverse under
jax.vmap once per ensemble member, so a warp whose inverse is itself
iterative (flowjax.bijections.NumericalInverse, root-finding splines)
makes the analysis step expensive in proportion to the ensemble size.
Closed-form warps — RBIG's, or an explicit exp / logistic pair —
are what this method is designed around.
Attributes:
| Name | Type | Description |
|---|---|---|
warp |
AbstractBijection
|
Bijection mapping latent (Gaussian) values to physical state
values, with event shape |
obs_warp |
AbstractBijection | None
|
Optional separate bijection for observation space, event
shape |
Shape
analysisparticles:(J, N)in,(J, N)outanalysisobs_particles:(J, M)analysisobservation:(M,)
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> import lineax as lx
>>> from flowjax.bijections import Exp
>>> from gauss_flows_models.filters import ConjugateTransformFilter
>>> # A strictly-positive state: the prior is lognormal in physical
>>> # space, Gaussian under log.
>>> filt = ConjugateTransformFilter(warp=Exp(shape=(2,)))
>>> prior = jnp.exp(jr.normal(jr.key(0), (256, 2))) # (J, N)
>>> noise = lx.DiagonalLinearOperator(0.1 * jnp.ones(2))
>>> posterior = filt.analysis(
... prior, prior, jnp.array([1.0, 2.0]), noise, key=jr.key(1)
... )
>>> posterior.shape
(256, 2)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/conjugate_filter.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
analysis
¶
analysis(particles: Array, obs_particles: Array, observation: Array, obs_noise: Any, *, key: PRNGKeyArray | None = None, perturbed_obs: Array | None = None, localization: Array | None = None) -> Array
Analysis step. Returns the posterior ensemble in physical space.
Everything is supplied in physical coordinates and returned in
physical coordinates; the latent detour is internal. obs_noise is
the observation error covariance in latent observation coordinates,
because that is where the Gaussian likelihood is assumed to live.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Array
|
Prior ensemble in physical state space, shape |
required |
obs_particles
|
Array
|
Prior ensemble in physical observation space, i.e.
the image of |
required |
observation
|
Array
|
The observation in physical space, shape |
required |
obs_noise
|
Any
|
Observation error covariance operator in latent
observation coordinates, a |
required |
key
|
PRNGKeyArray | None
|
PRNG key, forwarded to |
None
|
perturbed_obs
|
Array | None
|
Pre-built perturbed observation ensemble in
physical space, shape |
None
|
localization
|
Array | None
|
Optional state-observation taper, shape |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Posterior ensemble in physical state space, shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the observation-space warp's event shape does not
match |
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/conjugate_filter.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
rbig_conjugate_filter
¶
rbig_conjugate_filter(particles: Array, *, n_layers: int = 10, n_components: int = 8, random_state: int = 0) -> ConjugateTransformFilter
Fit a Gaussianising warp to a prior ensemble with RBIG.
Convenience constructor. RBIG gives a closed-form \(\Gamma\) from the ensemble with no gradient-based training, which is what the conjugate transform needs and what the reference implementation specifies by hand for each experiment. The fitted warp is used for both the state and the observation space.
Unlike a hand-specified warp, an RBIG warp is fitted, so the resulting filter is an approximation even when the prior really is a pushforward of a Gaussian — expect a bias reduction rather than the exact update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Array
|
Prior ensemble in physical state space, shape |
required |
n_layers
|
int
|
Number of RBIG |
10
|
n_components
|
int
|
Mixture components per marginal layer. Defaults to 8. |
8
|
random_state
|
int
|
Base seed for the per-dimension GMM fits. RBIG's fit is deterministic given this seed, so no PRNG key is taken. |
0
|
Returns:
| Type | Description |
|---|---|
ConjugateTransformFilter
|
A |
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.filters import rbig_conjugate_filter
>>> prior = jnp.exp(jr.normal(jr.key(0), (512, 2))) # lognormal
>>> filt = rbig_conjugate_filter(prior, n_layers=4, n_components=4)
>>> filt.warp.shape
(2,)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/conjugate_filter.py
Transform Filter¶
TransformFilter runs any Gaussian filter in warped coordinates. It composes
bijections into the dynamics and observation operators,
and delegates to gaussx.nonlinear_kalman_filter (the integrator passed
through selects EKF / UKF / CKF / GHKF / Monte Carlo) or, for the ensemble
case, to gaussx.enkf_analysis. Warping only the observation preserves
conjugacy and is the territory of the two constructions above; warping the
state breaks conjugacy and makes the predict step non-Gaussian, which is
why the moment-based path needs an integrator even for linear physical
dynamics.
What this buys — and what it does not. Measured on a strictly positive 2-D state with saturating growth and multiplicative noise (T = 40), against a physical-space filter with noise matched at the operating point:
- Support: 0/80 latent 95% credible intervals cross zero, against 54/80 (EKF) and 57/80 (UKF) in physical coordinates; the ensemble analysis produces 0/8,000 negative members against 743/8,000.
- Calibration: NLPD improves from 1.35 to 0.24.
- Point accuracy: no win. RMSE on the posterior mean is a wash (within a few percent, either direction, depending on the problem and precision).
A user who adopts this expecting RMSE wins will be disappointed, and will be right to be — the feature buys calibration and support, not point accuracy.
Two traps the API is shaped around: predictive() returns the quadrature
mean, because pushing the latent mean through the warp yields the
pushforward median (comparing that against a physical-space mean silently
mixes estimands and once flipped this feature's own benchmark conclusions);
and predictive_interval() offers transformed quantiles only, because a
symmetric moment interval in physical space is exactly what reintroduces
impossible values.
TransformFilter
¶
Bases: Module
Run a Gaussian filter in warped coordinates.
Composes warp_state and warp_obs into the dynamics and
observation operators and delegates to gaussx:
filter runs gaussx.nonlinear_kalman_filter on the composed maps (the
integrator passed through selects EKF / UKF / CKF / GHKF / Monte Carlo);
analysis runs gaussx.enkf_analysis for the ensemble case. Latent
moments are pushed back to physical space with predictive (quadrature
mean and covariance) and predictive_interval (transformed quantiles).
What this buys, measured — and what it does not. Filtering a positive state in log coordinates removes impossible posterior mass (zero credible intervals crossing zero, zero negative ensemble members) and improves predictive density, but point RMSE can worsen relative to the physical-space filter. Calibration and support, not point accuracy.
A practical note on warps: every filter step calls the warps' forward
and inverse maps, so a warp_state whose inverse is itself iterative
(flowjax.bijections.NumericalInverse, root-finding splines) puts a
root-find inside the innermost filter loop — a performance cliff.
Closed-form warps (Exp, Affine chains, RBIG's) are what this
wrapper is designed around.
Attributes:
| Name | Type | Description |
|---|---|---|
warp_state |
AbstractBijection | None
|
Bijection, latent → physical state, event shape |
warp_obs |
AbstractBijection | None
|
Bijection, latent → physical observation, event shape
|
noise_frame |
Literal['latent', 'physical']
|
Where the noise covariances are Gaussian — |
Shape
filterobservations:(T, M)physical; init moments(N,)/(N, N)latent; returned moments latent.analysisparticles:(J, N)in,(J, N)out, physical.predictive/predictive_interval:(N,)/(N, N)latent in, physical out; a leading time axis is vmapped.
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from flowjax.bijections import Exp
>>> from gauss_flows_models.filters import TransformFilter
>>> # A strictly positive 2-D state filtered in log coordinates.
>>> filt = TransformFilter(warp_state=Exp(shape=(2,)))
>>> growth = lambda x: x * jnp.exp(0.3 * (1.0 - x / 3.0))
>>> observations = jnp.exp(jr.normal(jr.key(0), (40, 2))) # (T, M)
>>> state = filt.filter(
... growth, # physical dynamics, (N,) -> (N,)
... lambda x: x, # physical observation operator
... 0.05 * jnp.eye(2), # Q, latent frame
... 0.10 * jnp.eye(2), # R, latent frame
... observations,
... jnp.zeros(2), # latent init mean
... jnp.eye(2), # latent init cov
... )
>>> mean, cov = filt.predictive(
... state.filtered_means, state.filtered_covs
... ) # physical-space moments, (T, 2) / (T, 2, 2)
>>> lo, hi = filt.predictive_interval(
... state.filtered_means, state.filtered_covs
... ) # strictly positive by construction
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/transform_filter.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 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 611 612 613 614 615 | |
filter
¶
filter(dynamics: Any, obs_fn: Any, process_noise: Any, obs_noise: Any, observations: Array, init_mean: Array, init_cov: Array, *, integrator: Any | None = None, mask: Array | None = None, joseph: bool = True, solver: Any | None = None) -> Any
Filter in latent coordinates. Moments returned are latent.
dynamics, obs_fn, and observations are all supplied in
physical coordinates; the composition and the warping of the
data are internal. The initial moments are latent — they
describe a Gaussian, and latent space is where the Gaussian lives.
Push the returned moments to physical space with predictive /
predictive_interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dynamics
|
Any
|
Physical state transition |
required |
obs_fn
|
Any
|
Physical observation operator |
required |
process_noise
|
Any
|
Process covariance, |
required |
obs_noise
|
Any
|
Observation covariance, |
required |
observations
|
Array
|
Physical observations, shape |
required |
init_mean
|
Array
|
Latent initial mean, shape |
required |
init_cov
|
Array
|
Latent initial covariance, shape |
required |
integrator
|
Any | None
|
gaussx integrator; the choice of integrator is the choice of filter. Defaults to gaussx's default (unscented). |
None
|
mask
|
Array | None
|
Optional |
None
|
joseph
|
bool
|
Use the Joseph-form covariance update. Default |
True
|
solver
|
Any | None
|
gaussx solver strategy for the innovation solve. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
|
Any
|
moments and the latent-space log-likelihood. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a |
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/transform_filter.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
analysis
¶
analysis(particles: Array, obs_particles: Array, observation: Array, obs_noise: Any, *, key: PRNGKeyArray | None = None, perturbed_obs: Array | None = None, localization: Array | None = None) -> Array
Ensemble Kalman analysis in latent coordinates.
The ensemble leg: warp the prior ensemble into latent coordinates,
run gaussx.enkf_analysis there, warp the posterior ensemble back.
Everything is supplied and returned in physical coordinates.
obs_noise follows noise_frame: with "latent" (default)
it is the observation covariance in latent observation coordinates;
with "physical" it is Gaussian in physical coordinates and is
re-expressed by linearising \(\Gamma_y^{-1}\) at the observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
particles
|
Array
|
Prior ensemble in physical state space, |
required |
obs_particles
|
Array
|
Image of the ensemble under the observation
operator, physical, |
required |
observation
|
Array
|
The observation, physical, |
required |
obs_noise
|
Any
|
Observation error covariance, |
required |
key
|
PRNGKeyArray | None
|
PRNG key for the observation perturbations, drawn in latent
space. Mutually exclusive with |
None
|
perturbed_obs
|
Array | None
|
Pre-built perturbed observations in physical
space, |
None
|
localization
|
Array | None
|
Optional state-observation taper, |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Posterior ensemble in physical state space, |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a warp's event shape does not match its ensemble. |
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/transform_filter.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
predictive
¶
Push latent moments to physical space by Gauss-Hermite quadrature.
Returns \((\mathbb{E}[x], \mathrm{Cov}[x])\) for \(x = \Gamma_x(z)\), \(z \sim \mathcal{N}(m, P)\) — not \(\Gamma_x(m)\), which is the pushforward median: for a non-affine warp the two differ, and comparing \(\Gamma_x(m)\) against a physical-space mean silently mixes estimands.
The quadrature grid is a tensor product, order ** N points, so
this is practical for small state dimension (N <= ~5). Lower
order before reaching for it in higher dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
Array
|
Latent mean, shape |
required |
cov
|
Array
|
Latent covariance, shape |
required |
order
|
int
|
Gauss-Hermite points per dimension. Default |
32
|
Returns:
| Type | Description |
|---|---|
Array
|
Tuple |
Array
|
shape. With |
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/flows/transform_filter.py
predictive_interval
¶
Per-dimension credible interval via transformed quantiles.
Computes \(\Gamma_x(m \pm z_\alpha s)\) with \(s\) the latent marginal standard deviations — the latent Gaussian quantiles pushed through the warp. Monotone maps preserve quantiles, so the result is an exact equal-tailed interval in physical space and it respects the support by construction. Deliberately offers no symmetric moment-based option: \(\hat\mu \pm z_\alpha \hat\sigma\) in physical space is what reintroduces impossible values.
Requires an elementwise warp_state (quantiles do not commute
with channel mixing). A decreasing warp flips the endpoints; they
are returned sorted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
Array
|
Latent mean, shape |
required |
cov
|
Array
|
Latent covariance, shape |
required |
level
|
float
|
Two-sided coverage level in |
0.95
|
Returns:
| Type | Description |
|---|---|
tuple[Array, Array]
|
Tuple |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |