Base Distributions¶
A normalizing flow needs a tractable base distribution \(p_Z\) to push forward through its
bijections. The default is a standard normal (flowjax.distributions.Normal), but a richer
or structured base can shorten the flow it has to learn. These distributions expose
log_prob and sample and plug into any FlowJax
Transformed or the package's SurVAEFlow
container as the base_dist argument.
Euclidean bases¶
LowRankGaussian is \(\mathcal{N}(\gvect{\mu}, \mat{W} \mat{W}^\top + \gmat{\Psi})\) with a loading \(\mat{W} \in \mathbb{R}^{D \times K}\) and a noise covariance \(\gmat{\Psi} = \mathrm{diag}(\gvect{\psi})\): isotropic noise (\(\gvect{\psi} = \sigma^2 \vect{1}\), noise="isotropic") is probabilistic PCA, and a free diagonal (noise="diagonal") is factor analysis. Its covariance is a gaussx.LowRankUpdate, so gaussx evaluates the density by the Woodbury identity and the matrix-determinant lemma with the \(K \times K\) capacitance \(\mat{M} = \mat{I} + \mat{W}^\top \gmat{\Psi}^{-1} \mat{W}\),
at \(O(DK^2 + K^3)\) cost, without forming the \(D \times D\) covariance. It replaces GaussianPCA (GaussianPCA(key, event_shape, latent_dim, log_sigma_init=…) is now LowRankGaussian(key, event_shape, rank, log_noise_scale_init=…)). AbstractOperatorGaussian is its base: a subclass builds the covariance operator \(\gmat{\Sigma}\), and the base takes the log-density from gaussx.gaussian_log_prob and the draws from gaussx.sample_mvn, both dispatched on the structure of \(\gmat{\Sigma}\).
GaussianMixture is a 1-D mixture used as a marginal target. Its component scales or Cholesky factors (scale_tril) and its weights are paramax.Parameterize leaves of gauss_flows_maps.reparam (an exp-diagonal CholeskyFactor or Reparametrised("exp"), and a Simplex), and GaussianMixture.from_fitted starts one from fitted means, scales and weights. The conditional variants emit
mean/scale from a context vector for amortised inference and class-conditional flows.
ConditionalDiagGaussian draws \(\vect{x} = \gvect{\beta}(\vect{c}) + \gvect{\gamma}(\vect{c}) \odot \gvect{\epsilon}\) with \(\gvect{\epsilon} \sim \mathcal{N}(\vect{0}, \mat{I})\), where \((\gvect{\gamma}, \gvect{\beta})\) come from the shared AffineModulation of the context. Its readout starts at zero, so the distribution is \(\mathcal{N}(\vect{0}, \mat{I})\) for every context at initialisation.
LowRankGaussian
¶
Bases: AbstractOperatorGaussian
𝒩(μ, W Wᵀ + Ψ): probabilistic PCA (isotropic Ψ) or factor analysis (diagonal Ψ).
Σ = W Wᵀ + Ψ, Ψ = diag(ψ), ψ = exp(2 log s) + ε, x = μ + W z + Ψ^½ η
with the loading W ∈ ℝ^(D×K), K ≤ D, the noise scale s (one scalar for
noise="isotropic", so ψ = σ² 1 with σ = s; one per dimension for
noise="diagonal"), the floor ε, and z ∈ ℝᴷ, η ∈ ℝᴰ standard normal.
Σ is a gaussx.LowRankUpdate of a diagonal base, so
gaussx.gaussian_log_prob evaluates it by the Woodbury identity and the
matrix-determinant lemma with the K × K capacitance M = I + Wᵀ Ψ⁻¹ W,
Σ⁻¹ = Ψ⁻¹ − Ψ⁻¹ W M⁻¹ Wᵀ Ψ⁻¹, log det Σ = ∑ᵢ log ψᵢ + log det M,
at O(DK² + K³) cost, and gaussx.sample_mvn draws it at O(DK).
Use as a flow base when the Gaussianized target has approximately
low-rank correlation in D dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
JAX random key used to initialise |
required |
event_shape
|
tuple[int, ...]
|
Shape of a single sample |
required |
rank
|
int
|
Rank |
required |
noise
|
NoiseKind
|
|
'isotropic'
|
loc
|
ArrayLike
|
Mean μ. A scalar is broadcast to shape |
0.0
|
log_noise_scale_init
|
float
|
Initial value of every log s. Defaults to
|
0.0
|
W_init_scale
|
float
|
Standard deviation of the Gaussian that initialises
|
0.1
|
eps
|
float
|
Floor ε added to the noise variance ψ, so Ψ stays invertible
when log s drifts very negative in training. Defaults to
|
1e-12
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Shape
- log_prob:
(D,)→ scalar (batch via vmap / leading axes) - sample:
(key, sample_shape)→(*sample_shape, D) - covariance_operator: → a D × D
gaussx.LowRankUpdate - covariance: →
(D, D)
Examples:
Probabilistic PCA, x ~ 𝒩(μ, W Wᵀ + σ² I):
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import LowRankGaussian
>>> pca_base = LowRankGaussian(jr.key(0), event_shape=(50,), rank=5)
>>> pca_base.sample(jr.key(1), (8,)).shape
(8, 50)
Factor analysis, x ~ 𝒩(μ, W Wᵀ + diag(ψ)):
>>> fa_base = LowRankGaussian(
... jr.key(1), event_shape=(50,), rank=5, noise="diagonal"
... )
>>> fa_base.log_noise_scale.shape
(50,)
>>> fa_base.log_prob(jnp.zeros(50)).shape
()
As the base of a Gaussianization flow:
>>> from gauss_flows_models.flows import gaussianization_flow
>>> base = LowRankGaussian(jr.key(2), event_shape=(4,), rank=2)
>>> flow = gaussianization_flow(jr.key(3), n_dims=4, n_layers=2, base_dist=base)
>>> flow.sample(jr.key(4), (8,)).shape
(8, 4)
References
Tipping, M. E. and Bishop, C. M. (1999). Probabilistic principal component analysis. Journal of the Royal Statistical Society: Series B, 61(3), 611–622.
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/low_rank.py
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 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 | |
covariance_operator
¶
The covariance Σ = Ψ + W Wᵀ as a gaussx.LowRankUpdate.
Returns:
| Type | Description |
|---|---|
LowRankUpdate
|
|
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/low_rank.py
covariance
¶
The dense covariance W Wᵀ + Ψ, for tests and small D.
Returns:
| Type | Description |
|---|---|
Array
|
The |
AbstractOperatorGaussian
¶
Bases: AbstractDistribution
𝒩(μ, Σ) with Σ a lineax operator that the subclass builds.
log p(x) = −½ (D log 2π + log det Σ + (x − μ)ᵀ Σ⁻¹ (x − μ)), x = μ + L z
with z ~ 𝒩(0, I) and L Lᵀ = Σ. The log-density is
gaussx.gaussian_log_prob and the draw gaussx.sample_mvn, so the solve,
the log-determinant and the factor L are chosen by the structure of Σ
(a low-rank update, a Kronecker product, a block-tridiagonal band, …).
The base holds the mean loc (μ, shape (D,)); a subclass declares
shape ((D,)) and implements covariance_operator. The base is
unconditional (cond_shape is None).
Shape
- log_prob:
(D,)→ scalar (batch via vmap / leading axes) - sample:
(key, sample_shape)→(*sample_shape, D)
Examples:
A subclass needs only the mean, the event shape and Σ:
>>> import jax.numpy as jnp
>>> import lineax as lx
>>> from gauss_flows_models.distributions import AbstractOperatorGaussian
>>> class DiagonalGaussian(AbstractOperatorGaussian):
... variance: jnp.ndarray
... shape: tuple[int, ...]
... def covariance_operator(self):
... return lx.DiagonalLinearOperator(self.variance)
>>> dist = DiagonalGaussian(jnp.zeros(3), jnp.ones(3), (3,))
>>> round(float(dist.log_prob(jnp.zeros(3))), 4)
-2.7568
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/operator_gaussian.py
covariance_operator
abstractmethod
¶
The covariance Σ as a D × D lineax operator.
Returns:
| Type | Description |
|---|---|
AbstractLinearOperator
|
The operator Σ; its structure decides gaussx's solve, |
AbstractLinearOperator
|
log-determinant and sampling factor. |
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/operator_gaussian.py
sample
¶
sample(key: PRNGKeyArray, sample_shape: tuple[int, ...] = (), condition: ArrayLike | None = None) -> Array
Draw sample_shape events in one gaussx.sample_mvn call.
FlowJax's sample maps _sample over one key per event with
jax.vmap; one call with num_samples instead lets gaussx factor Σ
once and keeps its structure-or-fallback choices unbatched, so a
fallback it guards with lax.cond is not evaluated for every draw.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
JAX random key. |
required |
sample_shape
|
tuple[int, ...]
|
Leading shape of the draws. Defaults to |
()
|
condition
|
ArrayLike | None
|
Unused; the distribution is unconditional. |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Draws of shape |
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/operator_gaussian.py
GaussianMixture
¶
Bases: AbstractDistribution
Trainable multivariate Gaussian-mixture base distribution.
Parameterises a K-component mixture of D-dimensional Gaussians
with trainable component means, scales, and weights. The density is
p(x) = ∑ₖ wₖ · N(x; locₖ, Σₖ) with mixing weights w on the open
simplex. Two covariance parameterisations are supported: a diagonal one
(one scale per component per dim) and a full-covariance one (a
per-component lower-triangular Cholesky factor Σₖ = Lₖ Lₖᵀ).
Both are stored as paramax.Parameterize leaves of the maps in
gauss_flows_maps.reparam, and paramax.unwrap turns each into its
constrained value:
weights: aSimplexleaf,w = softmax([u, 0])withuof shape(K − 1,), so the weights have exactlyK − 1degrees of freedom. WithK = 1there is nothing to train andweightsis the constant[1].scale_tril, full covariance: aCholeskyFactorleaf with anexpdiagonal,(K, D, D)unwrapped from(K, D(D + 1)/2)raw values.scale_tril, diagonal: aReparametrised("exp")leaf, the(K, D)scales unwrapped from their(K, D)logarithms.
Use as a flow base when the Gaussianized target is multi-modal or
fat-tailed — the natural companion to MixtureGaussianCDF,
the per-dimension marginal transform.
To start from fitted means, covariances and weights, use from_fitted,
which stores each through the map's parameter (so it is checked and
inverted): for diagonal=False, pass the Cholesky factors of the fitted
covariances (jnp.linalg.cholesky), and for diagonal=True the
fitted standard deviations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
JAX random key used to initialise the component means. |
required |
n_components
|
int
|
Number of mixture components |
required |
event_shape
|
tuple[int, ...]
|
Shape of a single sample |
required |
diagonal
|
bool
|
If |
True
|
loc_init_scale
|
float
|
Std of the Gaussian used to initialise component
means. Defaults to |
1.0
|
log_scale_init
|
float
|
Logarithm of the initial scale (resp. of the initial
Cholesky diagonal for |
0.0
|
Note
The event shape is stored as self.shape per the flowjax
distribution contract; mixing weights are uniform at init.
Shape
- log_prob:
(D,)→ scalar (batch via vmap / leading axes) - sample:
(key, sample_shape)→(*sample_shape, D)
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import GaussianMixture
>>> dist = GaussianMixture(jr.key(0), n_components=3, event_shape=(2,))
>>> dist.sample(jr.key(1), (8,)).shape
(8, 2)
>>> dist.log_prob(jnp.zeros(2)).shape
()
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/mixture.py
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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
from_fitted
classmethod
¶
from_fitted(loc: ArrayLike, scale_tril: ArrayLike, weights: ArrayLike, *, diagonal: bool = True) -> GaussianMixture
Build a mixture that starts at fitted means, scales and weights.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loc
|
ArrayLike
|
Component means, |
required |
scale_tril
|
ArrayLike
|
For |
required |
weights
|
ArrayLike
|
Mixing weights |
required |
diagonal
|
bool
|
Whether the covariances are diagonal. |
True
|
Returns:
| Type | Description |
|---|---|
GaussianMixture
|
A |
GaussianMixture
|
are the given values. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When a value lies outside its set (the maps check it). |
Examples:
>>> import jax.numpy as jnp
>>> from gauss_flows_models.distributions import GaussianMixture
>>> covariances = jnp.stack([jnp.eye(2), 2.0 * jnp.eye(2)])
>>> dist = GaussianMixture.from_fitted(
... jnp.zeros((2, 2)),
... jnp.linalg.cholesky(covariances),
... jnp.array([0.3, 0.7]),
... diagonal=False,
... )
>>> dist.log_prob(jnp.zeros(2)).shape
()
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/mixture.py
ConditionalDiagGaussian
¶
Bases: AbstractDistribution
Diagonal Gaussian whose location and scale are an affine modulation of noise.
A draw is standard normal noise modulated by the context c,
x = β(c) + γ(c) ⊙ ε, ε ~ 𝒩(0, I),
so by change of variables
log p(x | c) = Σᵢ [log 𝒩((xᵢ − βᵢ(c)) / γᵢ(c); 0, 1) − log γᵢ(c)],
where (γ, log γ, β) = modulation.modulation(c) come from the shared
gauss_flows_maps.conditioning.AffineModulation. Its readout starts at zero
weight and bias (0, r₀), so γ = 1 and β = 0 for every c and the
distribution starts as 𝒩(0, I).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
PRNG key for the modulation's init; unused with a pre-built
|
required |
event_shape
|
tuple[int, ...]
|
Single-event shape |
required |
cond_dim
|
int
|
Context size |
required |
nn_width
|
int
|
Width of the modulation's trunk. |
64
|
nn_depth
|
int
|
Number of trunk layers; |
2
|
activation
|
Callable[[Array], Array]
|
Activation after each trunk layer. |
tanh
|
readout_scale
|
float
|
Factor on the readout's default weight; the default |
0.0
|
scale_map
|
_FlowScaleMap
|
The positive scale map |
'exp'
|
modulation
|
AffineModulation | None
|
A pre-built |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Shape
sample: condition (K,) to x (D,).
log_prob: x (D,) and condition (K,) to a scalar.
Examples:
At init the log-density is the standard normal's for every context:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from flowjax.distributions import StandardNormal
>>> from gauss_flows_models.distributions import ConditionalDiagGaussian
>>> base = ConditionalDiagGaussian(jr.key(0), event_shape=(3,), cond_dim=2)
>>> cond = jnp.array([0.5, -0.5])
>>> x = base.sample(jr.key(1), condition=cond)
>>> x.shape
(3,)
>>> bool(jnp.allclose(base.log_prob(x, cond), StandardNormal((3,)).log_prob(x)))
True
A batch of contexts, with a bounded scale and a linear readout:
>>> base = ConditionalDiagGaussian(
... jr.key(0), event_shape=(3,), cond_dim=2, nn_depth=0,
... scale_map="one_plus_tanh",
... )
>>> base.log_prob(jnp.zeros((5, 3)), condition=jnp.ones((5, 2))).shape
(5,)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/conditional_diag_gaussian.py
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 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
ClassCondDiagGaussian
¶
Bases: AbstractDistribution
Class-conditional diagonal Gaussian with learned per-class parameters.
Stores a (n_classes, *event_shape) lookup table for the means
(when learn_mean=True) and another for the raw log-scales. The
effective log-scale is log_scale_raw[idx] * logscale_factor; the
multiplicative factor matches the Glow stabilisation trick (Kingma &
Dhariwal 2018) where small stored values keep the effective scales
well-conditioned at init.
The condition is a scalar integer class label (cond_shape = ()).
Out-of-range indices follow JAX gather semantics — the caller is
responsible for passing in-range labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKeyArray
|
PRNG key. Currently unused (parameters are deterministically initialised); accepted to match the constructor convention used by other learnable bases in this package. |
required |
n_classes
|
int
|
Number of classes |
required |
event_shape
|
tuple[int, ...]
|
Single-event shape (any rank). |
required |
learn_mean
|
bool
|
If |
True
|
logscale_factor
|
float
|
Multiplicative factor applied to |
1.0
|
Shape
- Condition:
()(scalar int) - Sample / log_prob input:
event_shape - log_prob output: scalar
()
Glow recipe
ClassCondDiagGaussian(key, n_classes=10, event_shape=(D,),
learn_mean=False, logscale_factor=3.0)
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import ClassCondDiagGaussian
>>> base = ClassCondDiagGaussian(jr.key(0), n_classes=4, event_shape=(3,))
>>> label = jnp.int32(2)
>>> x = base.sample(jr.key(1), condition=label)
>>> log_p = base.log_prob(x, condition=label)
>>> assert x.shape == (3,) and log_p.shape == ()
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/class_cond_diag_gaussian.py
16 17 18 19 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 | |
State-space bases¶
LinearGaussianSSM is the distribution of a whole series \(y_{1:T}\) under a linear-Gaussian state-space model, \(s_t = A_t s_{t-1} + q_t\) and \(y_t = H_t s_t + v_t\) with \(q_t \sim \mathcal{N}(0, Q_t)\) and \(v_t \sim \mathcal{N}(0, R_t)\). Its event shape is \((T, M)\) and its log_prob is the marginal likelihood \(\log p(y_{1:T})\) computed by gaussx.kalman_filter, in \(O(T N^3)\) for a state of size \(N\). Each matrix is shared by all steps or stacked over time. With masked=True it takes a boolean \((T, M)\) observation mask as its condition and scores only the observed entries, which is the masked base normalizing_kalman_filter expects. LinearGaussianSSM.from_sde builds the Gaussian process of a gaussx SDEKernel (such as gaussx.MaternSDE) at irregular times, so its density equals \(\mathcal{N}(y; 0, K + \sigma_v^2 I)\) with \(K\) the kernel matrix at those times.
LinearGaussianSSM
¶
Bases: AbstractDistribution
p(y_1:T) of a linear-Gaussian state-space model; event shape (T, M).
s_t = A_t s_{t−1} + q_t, q_t ~ 𝒩(0, Q_t)
y_t = H_t s_t + v_t, v_t ~ 𝒩(0, R_t)
with s_0 ~ 𝒩(m₀, P₀), a state s_t ∈ ℝᴺ, an observation y_t ∈ ℝᴹ and
t = 1, …, T. The density is log p(y_1:T), the log_likelihood of
gaussx.kalman_filter. The filter predicts before each update, so row 0
of an event is y₁, scored against A₁ s₀ rather than against s₀.
Each of A_t, H_t, Q_t and R_t is either one matrix shared by every step or
a stack over the T steps (a time-varying model). The matrices are plain
array leaves, so they train; keeping Q_t, R_t and P₀ positive
semi-definite is the caller's job (for instance through
gauss_flows_maps.reparam.CholeskyFactor).
With masked=True the distribution consumes a boolean observation mask
of shape (T, M) as its condition, and log_prob is the exact
marginal log p(y_obs) over the entries where the mask is true; masked
entries are never read, so they may hold NaN. A non-None
cond_shape is how gauss_flows_models.filters.normalizing_kalman_filter
recognises a masked base. Sampling ignores the mask and draws every entry,
which is the model's imputation of the unobserved ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transition
|
ArrayLike
|
Dynamics A_t, (N, N) or (T, N, N). |
required |
obs_model
|
ArrayLike
|
Observation operator H_t, (M, N) or (T, M, N). |
required |
process_noise
|
ArrayLike
|
Process-noise covariance Q_t, (N, N) or (T, N, N). |
required |
obs_noise
|
ArrayLike
|
Observation-noise covariance R_t, (M, M) or (T, M, M). |
required |
init_mean
|
ArrayLike
|
Prior mean m₀ of s₀, (N,). |
required |
init_cov
|
ArrayLike
|
Prior covariance P₀ of s₀, (N, N). |
required |
n_steps
|
int
|
Number of steps T. |
required |
masked
|
bool
|
Whether the distribution consumes an observation mask of shape
(T, M) as its condition. Defaults to |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Shape
log_prob: (T, M) → scalar, with condition (T, M) when maskedsample(key, sample_shape): (*sample_shape, T, M)
Examples:
A damped random walk in four channels, observed with noise:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import LinearGaussianSSM
>>> ssm = LinearGaussianSSM(
... transition=0.9 * jnp.eye(4), obs_model=jnp.eye(4),
... process_noise=0.1 * jnp.eye(4), obs_noise=0.1 * jnp.eye(4),
... init_mean=jnp.zeros(4), init_cov=jnp.eye(4), n_steps=8,
... )
>>> y = ssm.sample(jr.key(0), (3,))
>>> y.shape, ssm.log_prob(y).shape
((3, 8, 4), (3,))
The masked form marginalises the entries where the mask is false:
>>> masked = LinearGaussianSSM(
... transition=0.9 * jnp.eye(4), obs_model=jnp.eye(4),
... process_noise=0.1 * jnp.eye(4), obs_noise=0.1 * jnp.eye(4),
... init_mean=jnp.zeros(4), init_cov=jnp.eye(4), n_steps=8,
... masked=True,
... )
>>> mask = jr.bernoulli(jr.key(1), 0.7, (8, 4))
>>> masked.cond_shape, masked.log_prob(y[0], condition=mask).shape
((8, 4), ())
References
Särkkä, S. and Svensson, L. (2023). Bayesian Filtering and Smoothing, 2nd edition. Cambridge University Press.
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/linear_gaussian_ssm.py
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 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 | |
from_sde
classmethod
¶
from_sde(kernel: SDEKernel, times: ArrayLike, obs_noise: ArrayLike, *, masked: bool = False) -> LinearGaussianSSM
A Gaussian process at times from a gaussx SDE kernel; event (T, 1).
y = f(t_1:T) + v, f ~ 𝒢𝒫(0, k), v ~ 𝒩(0, σ_v² I)
The kernel's continuous-time SDE is discretised over the gaps
Δ_t = t_t − t_{t−1} by kernel.discretise_sequence, giving (A_t,
Q_t) for t = 2, …, T. The first observation sees the stationary prior
directly, so A₁ = I and Q₁ = 0 (the convention gaussx.kalman_filter
gives for observing the prior at the first step), with m₀ = 0,
P₀ = Σ_∞ from kernel.initial_covariance(), H from
kernel.sde_params().H and R = σ_v² I. The result is the Gaussian
process whose covariance at times is the kernel matrix, evaluated
in O(T N³) for a state of size N rather than O(T³).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
SDEKernel
|
A stationary gaussx |
required |
times
|
ArrayLike
|
Observation times t_1:T, sorted increasing, (T,). |
required |
obs_noise
|
ArrayLike
|
Observation-noise variance σ_v², a scalar. |
required |
masked
|
bool
|
Whether the result consumes an observation mask of shape
(T, 1) as its condition. Defaults to |
False
|
Returns:
| Type | Description |
|---|---|
LinearGaussianSSM
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Shape
times: (T,)- Returned event: (T, 1)
Examples:
A Matérn-3/2 process at eight irregular times, observed with noise variance 0.01:
>>> import gaussx as gx
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import LinearGaussianSSM
>>> times = jnp.sort(jr.uniform(jr.key(2), (8,)) * 30.0)
>>> kernel = gx.MaternSDE(variance=1.0, lengthscale=5.0, order=1)
>>> gp = LinearGaussianSSM.from_sde(kernel, times, obs_noise=0.01)
>>> gp.shape, gp.log_prob(gp.sample(jr.key(3))).shape
((8, 1), ())
References
Särkkä, S. and Solin, A. (2019). Applied Stochastic Differential Equations. Cambridge University Press.
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/linear_gaussian_ssm.py
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 | |
Gaussian Markov random fields¶
GMRFBase wraps one of gaussx's Gaussian Markov random fields (GaussianMRF, IntrinsicGMRF, BYM2GMRF or ConstrainedGMRF), \(x \sim \mathcal{N}(\mu, \Lambda^{-1})\) with a sparse or structured precision \(\Lambda\), so that a flow over a gridded field starts from a Matérn or AR(1) field and its bijections only learn what the Gaussian field cannot express. log_prob and sample are the field's, so they use whatever structure the precision has; the field's array leaves (\(\mu\) and the arrays inside \(\Lambda\), such as \(\kappa\) and \(\tau\)) are trainable like any other flow parameter. An intrinsic field is improper and is a valid base only on its constrained subspace, so GMRFBase raises ValueError for an IntrinsicGMRF or BYM2GMRF with constraint="none". GaussianFieldLike is the Protocol that says what the wrapper uses: an event_shape, log_prob and sample.
A Matérn field on a regular grid solves \((\kappa^2 - \Delta)^{\alpha/2}\, \tau\, x = \mathcal{W}\) (Lindgren, Rue and Lindström, 2011), and gaussx's spde_precision_grid builds its precision; an AR(1) chain comes from ar1_precision. Here the field is a Matérn field on a 64 × 64 grid (\(\alpha = 2\), \(\kappa = 0.2\) per cell, \(\tau = 1\)), the base of a flow over the flattened grid:
import gaussx as gx
import jax.numpy as jnp
import jax.random as jr
from flowjax.bijections import Affine
from flowjax.distributions import Transformed
from gauss_flows_models.distributions import GMRFBase
# Λ: Matérn SPDE precision on the grid, as an operator on the 4096 cells
precision = gx.spde_precision_grid((64, 64), kappa=0.2, tau=1.0, alpha=2)
# x ~ 𝒩(0, Λ⁻¹), the base of a flow over the grid; event shape (4096,)
base = GMRFBase(gx.GaussianMRF(jnp.zeros(64 * 64), precision))
# a flow whose bijections learn what the Gaussian field cannot express
flow = Transformed(base, Affine(jnp.zeros(64 * 64), jnp.ones(64 * 64)))
samples = flow.sample(jr.key(0), (4,)) # (4, 4096)
log_prob = flow.log_prob(samples) # (4,)
GMRFBase
¶
Bases: AbstractDistribution
A flow base over a gaussx Gaussian Markov random field.
The base is the field x ~ 𝒩(μ, Λ⁻¹) with a sparse or structured precision Λ,
log p(x) = ½ log det Λ − ½ (x − μ)ᵀ Λ (x − μ) − ½ N log 2π,
and both log_prob and sample are the wrapped field's, so they use
whatever structure its precision has (a sparse or dense factorisation,
per-factor eigenvalues for a Kronecker-structured Λ such as
gaussx.spde_precision_grid, or matrix-free perturbation-optimisation).
The field's array leaves (μ, and the arrays inside its precision such as κ
and τ) are trainable like any other flow parameter. An intrinsic field is
improper, so it is a valid base only on its constrained subspace:
IntrinsicGMRF (and BYM2GMRF, its subclass) with constraint="none"
is refused.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
GaussianFieldLike
|
A gaussx |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Shape
- log_prob:
(N,)→ scalar (batch via vmap / leading axes) - sample:
(key, sample_shape)→(*sample_shape, N)
Examples:
A Matérn field on a 16 × 16 grid (α = 2, κ = 0.2 per cell, τ = 1) as the base of a flow over the flattened grid:
>>> import gaussx as gx
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import GMRFBase
>>> precision = gx.spde_precision_grid((16, 16), kappa=0.2, tau=1.0, alpha=2)
>>> base = GMRFBase(gx.GaussianMRF(jnp.zeros(16 * 16), precision))
>>> base.sample(jr.key(0), (3,)).shape
(3, 256)
>>> base.log_prob(jnp.zeros(256)).shape
()
Inside a flow, through FlowJax's Transformed:
>>> from flowjax.bijections import Affine
>>> from flowjax.distributions import Transformed
>>> flow = Transformed(base, Affine(jnp.zeros(256), 2.0 * jnp.ones(256)))
>>> flow.log_prob(jnp.zeros(256)).shape
()
References
Lindgren, Rue and Lindström 2011, An explicit link between Gaussian fields and Gaussian Markov random fields: the stochastic partial differential equation approach, JRSS B 73(4), 423–498.
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/gmrf.py
GaussianFieldLike
¶
Bases: Protocol
What GMRFBase uses of a Gaussian field.
The three members are an event shape, log_prob and sample.
gaussx's GaussianMRF, IntrinsicGMRF, BYM2GMRF and ConstrainedGMRF
all fit; they share no base class, so the wrapper types them structurally.
Shape
- event_shape:
(N,) - log_prob:
(*sample, N)→(*sample,) - sample:
(key, sample_shape)→(*sample_shape, N)
Examples:
>>> import gaussx as gx
>>> import jax.numpy as jnp
>>> from gauss_flows_models.distributions import GaussianFieldLike
>>> precision = gx.spde_precision_grid((4, 4), kappa=0.5, tau=1.0, alpha=2)
>>> field = gx.GaussianMRF(jnp.zeros(16), precision)
>>> isinstance(field, GaussianFieldLike)
True
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/gmrf.py
Structured Gaussian bases¶
StructuredGaussian is \(\mathcal{N}(\gvect{\mu}, \gmat{\Sigma})\) for any lineax or gaussx covariance operator, so a flow over a gridded field or a long series can start from a base that already carries its correlation, and the bijections only learn what a Gaussian cannot express. Like LowRankGaussian, it is an AbstractOperatorGaussian: gaussx.sample_mvn draws \(\vect{x} = \gvect{\mu} + \mat{L} \vect{z}\) with \(\mat{L} \mat{L}^\top = \gmat{\Sigma}\) chosen by structure, and gaussx.gaussian_log_prob chooses the solve and the log-determinant by structure. The operator's array leaves (a Toeplitz column, Kronecker factors, …) are trainable; keeping \(\gmat{\Sigma}\) positive definite while they train is the caller's choice of parameterisation.
| Covariance | Typical base | Exact draw | Log-density |
|---|---|---|---|
gaussx.Toeplitz |
stationary series on a regular grid | \(O(D \log D)\), by FFT | dense, \(O(D^3)\) |
gaussx.Kronecker |
separable space × time | per-factor eigendecompositions | structured |
gaussx.KroneckerSum |
separable 2-D field | per-factor eigendecompositions | structured |
gaussx.BlockTriDiag |
Markov chain | \(O(B d^3)\); dense inside a flow | \(O(B d^3)\) |
gaussx.LowRankUpdate |
LowRankGaussian |
base's cost + \(O(DK)\) | \(O(DK^2)\) |
The "dense" entries are gaussx v0.8.4's: it has no structured solve or log-determinant for a Toeplitz operator, and its block-tridiagonal draw falls back to the dense square root of \(\gmat{\Sigma}\) in a way that jax.vmap evaluates for every draw, which is how a FlowJax Transformed samples its base. The class docstring has the details.
StructuredGaussian
¶
Bases: AbstractOperatorGaussian
𝒩(μ, Σ) for a structured covariance operator whose array leaves are trainable.
x = μ + L z, z ~ 𝒩(0, I), L Lᵀ = Σ, log p(x) = log 𝒩(x; μ, Σ)
gaussx.sample_mvn chooses the factor L and gaussx.gaussian_log_prob
the solve and the log-determinant, both by the structure of Σ (gaussx
v0.8.4; measured at D = 4096 by the tests):
| Covariance Σ | Exact draw | Log-density |
|---|---|---|
gaussx.Toeplitz |
O(D log D), by FFT | dense, O(D³) |
gaussx.Kronecker |
per-factor eigendecompositions | structured |
gaussx.KroneckerSum |
per-factor eigendecompositions | structured |
gaussx.BlockTriDiag |
O(B d³); dense inside a flow (below) | O(B d³) |
gaussx.LowRankUpdate |
base's cost + O(DK) | O(DK²) |
Two structures still form a D × D array:
- Toeplitz log-density. gaussx has no structured solve or
log-determinant for a Toeplitz operator, so
log_probforms Σ and factors it (O(D²) memory, O(D³) time). Its draws are structured, but the traced program also holds the dense square root that gaussx falls back to when the circulant embedding is not positive. - Block-tridiagonal draws. gaussx guards the banded-Cholesky draw with
a fallback to the dense square root of Σ, chosen by whether the draws
are finite.
sampledraws all events in onegaussx.sample_mvncall, where the choice is onelax.condand the dense branch only sits in the compiled program. Inside a flow, though, FlowJax'sTransformedmaps_sampleover one key per event withjax.vmap, which turns the choice into a select that computes the dense root (O(D³)) for every draw: at D = 256, a hundred draws took about 40 s that way and 10⁵ draws throughsampleabout 3 s. The log-density is structured.
Keeping Σ positive definite while its leaves are trained is the caller's choice of parameterisation (a Toeplitz column from a positive spectrum, Kronecker factors from Cholesky factors, …): neither this class nor gaussx checks it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
loc
|
ArrayLike
|
Mean μ, shape |
required |
covariance
|
AbstractLinearOperator
|
Covariance Σ, a square D × D lineax operator. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Shape
- log_prob:
(D,)→ scalar (batch via vmap / leading axes) - sample:
(key, sample_shape)→(*sample_shape, D) - covariance_operator: → the D × D operator Σ
Examples:
A stationary daily series, Σ = toeplitz(t) with t_k = 0.8^k:
>>> import gaussx as gx
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import StructuredGaussian
>>> lags = jnp.arange(365.0)
>>> series_base = StructuredGaussian(
... loc=jnp.zeros(365), covariance=gx.Toeplitz(0.8**lags)
... )
>>> series_base.sample(jr.key(0), (4,)).shape
(4, 365)
A separable 2-D field, Σ = A₁ ⊗ A₂ on a 16 × 32 grid:
>>> import lineax as lx
>>> psd = lx.positive_semidefinite_tag
>>> rows = lx.MatrixLinearOperator(jnp.eye(16) + 0.5, psd)
>>> columns = lx.MatrixLinearOperator(jnp.eye(32) + 0.1, psd)
>>> field_base = StructuredGaussian(
... loc=jnp.zeros(512), covariance=gx.Kronecker(rows, columns)
... )
>>> field_base.log_prob(jnp.zeros(512)).shape
()
As the base of a FlowJax flow:
>>> from flowjax.bijections import Affine
>>> from flowjax.distributions import Transformed
>>> flow = Transformed(field_base, Affine(loc=1.0, scale=2.0 * jnp.ones(512)))
>>> flow.sample(jr.key(1), (2,)).shape
(2, 512)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/structured.py
19 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 131 132 133 134 | |
covariance_operator
¶
The covariance Σ, as given.
Returns:
| Type | Description |
|---|---|
AbstractLinearOperator
|
The operator |
Manifold (sphere) distributions¶
Distributions on the unit sphere \(\mathbb{S}^{d}\subset\mathbb{R}^{d+1}\) for directional data
and global flows. The von Mises–Fisher density \(p(x)\propto\exp(\kappa\,\mu^\top x)\)
concentrates around a mean direction \(\mu\) with concentration \(\kappa\); UniformOnSphere is
its \(\kappa\to 0\) limit. The exp/log maps and tangent basis below move between the manifold
and its tangent plane for building flows in local coordinates.
VonMisesFisher
¶
Bases: AbstractDistribution
Von Mises–Fisher distribution on the unit sphere Sᵈ ⊂ ℝ^{d+1}.
Density p(x) ∝ exp(κ · μᵀx) on the sphere: the spherical analogue of
an isotropic Gaussian, peaked at the mean direction μ with
concentration κ (κ = 0 recovers UniformOnSphere). The
normaliser involves a modified Bessel function I_ν(κ), evaluated
here via a hybrid power-series / asymptotic expansion. Sampling uses
Wood's (1994) rejection scheme. Useful as a flow base for concentrated
directional data.
Invalid inputs (zero-vector mean or negative concentration) are
propagated as NaN through log_prob / sample rather than being
rejected at construction, so the constructor stays jit / vmap-safe
(e.g. inside a mixture of VMFs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
ArrayLike
|
Mean direction |
required |
concentration
|
ArrayLike
|
Non-negative scalar concentration |
required |
Shape
- log_prob:
(d+1,)→ scalar (batch via vmap / leading axes) - sample:
(key, sample_shape)→(*sample_shape, d+1)
Examples:
>>> import jax.numpy as jnp
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import VonMisesFisher
>>> dist = VonMisesFisher(jnp.array([0.0, 0.0, 1.0]), 3.0)
>>> dist.sample(jr.key(0), (2,)).shape
(2, 3)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/sphere.py
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 | |
UniformOnSphere
¶
Bases: AbstractDistribution
Uniform distribution on the unit sphere Sᵈ ⊂ ℝ^{d+1}.
Constant density 1 / A_d over the sphere, where A_d is the
surface area of Sᵈ; log_prob returns −∞ for off-sphere
points. Samples are drawn by normalising an isotropic Gaussian, so
they satisfy ‖x‖₂ = 1 up to numerical precision. Useful as a flow
base for directional / rotation-invariant data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
int
|
Intrinsic sphere dimension. Samples live in |
required |
Shape
- log_prob:
(d+1,)→ scalar (batch via vmap / leading axes) - sample:
(key, sample_shape)→(*sample_shape, d+1)
Examples:
>>> import jax.random as jr
>>> from gauss_flows_models.distributions import UniformOnSphere
>>> dist = UniformOnSphere(d=2)
>>> dist.sample(jr.key(0), (4,)).shape
(4, 3)
Source code in packages/gauss-flows-models/src/gauss_flows_models/_src/distributions/sphere.py
expmap_sphere
¶
Map a tangent vector at x to the sphere via the exponential map.
expmap(x, v) = x·cos(‖v‖) + v·sin(‖v‖) / ‖v‖ with the sin(r) / r
factor evaluated via sinc for stability at r → 0. The component
of v along x is removed first, so v need not be exactly
tangent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
Base point in |
required |
v
|
Array
|
Tangent vector at |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The point |
Shape
x and v are single events of shape (d+1,).
Returns a single point on the sphere with shape (d+1,).
Examples:
>>> import jax.numpy as jnp
>>> from gauss_flows_maps.sphere import expmap_sphere
>>> x = jnp.array([0.0, 0.0, 1.0])
>>> v = jnp.array([0.1, 0.0, 0.0])
>>> expmap_sphere(x, v).shape
(3,)
Source code in packages/gauss-flows-maps/src/gauss_flows_maps/_src/transforms/_sphere_utils.py
logmap_sphere
¶
Return the tangent vector at x whose exp-map reaches y.
Inverse of expmap_sphere: expmap(x, logmap(x, y)) ≈ y. The
log map is not uniquely defined when y is antipodal to x; this
implementation returns π · e for a deterministic tangent direction
e obtained from tangent_basis, which at least satisfies
‖logmap‖ == π (the geodesic distance to the antipode) and is
continuous under perturbations of x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
Base point on the sphere in |
required |
y
|
Array
|
Target point on the sphere, shape |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The tangent vector in |
Shape
x and y are single points on the sphere with shape (d+1,).
Returns a tangent vector in Tₓ Sᵈ with shape (d+1,).
Examples:
>>> import jax.numpy as jnp
>>> from gauss_flows_maps.sphere import expmap_sphere, logmap_sphere
>>> x = jnp.array([0.0, 0.0, 1.0])
>>> v = jnp.array([0.1, 0.0, 0.0])
>>> y = expmap_sphere(x, v)
>>> logmap_sphere(x, y).shape
(3,)
Source code in packages/gauss-flows-maps/src/gauss_flows_maps/_src/transforms/_sphere_utils.py
tangent_basis
¶
Return an orthonormal basis of the tangent space Tₓ Sᵈ.
Uses a Householder reflection that maps x to ±e₁ and then takes
columns 2..d+1 of that orthogonal matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
A point in |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Tangent basis |
Array
|
|
Shape
Input: (d+1,).
Output: (d+1, d) with Eᵀ E = I and xᵀ E = 0.
Examples:
>>> import jax.numpy as jnp
>>> from gauss_flows_maps.sphere import tangent_basis
>>> x = jnp.array([0.0, 0.0, 1.0])
>>> tangent_basis(x).shape
(3, 2)