state.posteriors#

Posterior distributions for state model parameters.

Classes

LatentsPosteriorStatic

Posterior distribution q(X) for static latents.


class LatentsPosteriorStatic(
mean: ndarray | None = None,
cov: ndarray | None = None,
moment: ndarray | None = None,
)[source]#

Posterior distribution q(X) for static latents.

Parameters:
meanndarray of float, shape (x_dim, n_samples) or None, default None

Posterior mean.

covndarray of float, shape (x_dim, x_dim) or None, default None

Posterior covariance (shared across samples).

momentndarray of float, shape (x_dim, x_dim) or None, default None

Posterior second moments.

Attributes:
meanndarray of float, shape (x_dim, n_samples) or None

Posterior mean.

covndarray of float, shape (x_dim, x_dim) or None

Posterior covariance (shared across samples).

momentndarray of float, shape (x_dim, x_dim) or None

Posterior second moments.

Examples

After fitting a GFA model, access the latents posterior:

>>> model = GFAModel()
>>> model.fit(Y)
>>> latents = model.latents_posterior
>>> latents.mean.shape
(5, 100)

Get posterior mean as a realization:

>>> X = latents.posterior_mean
>>> X.data.shape
(5, 100)

Sample from the posterior:

>>> rng = np.random.default_rng(42)
>>> X_sample = latents.sample(rng)
property x_dim: int | None#

Number of latent dimensions.

property n_samples: int | None#

Number of samples.

is_initialized() bool[source]#

Check if posterior has been initialized.

Returns:
bool

True if mean is not None.

property posterior_mean: LatentsRealization#

Return posterior mean as a realization.

Returns:
LatentsRealization

Posterior mean wrapped as a realization.

sample(
rng: Generator,
) LatentsRealization[source]#

Draw X from the posterior distribution.

Parameters:
rngnumpy.random.Generator

Random number generator.

Returns:
LatentsRealization

Sampled latent values.

compute_moment(in_place: bool = True) ndarray[source]#

Compute the posterior second moments.

E[X X^T] = n_samples * cov + mean @ mean^T

Parameters:
in_placebool, default True

If True, store result in self.moment and return reference to it. If False, return a new array without modifying self.

Returns:
ndarray of float, shape (x_dim, x_dim)

Posterior second moments.

get_subset_dims(
x_indices: ndarray,
in_place: bool = True,
) Self[source]#

Keep only a subset of the latent dimensions.

Parameters:
x_indicesndarray of int

Indices of the latent dimensions to keep, at most length x_dim.

in_placebool, default True

If True, modify self in place and return self. If False, return a new instance with the subset.

Returns:
Self

The modified instance (if in_place=True) or a new instance with only the specified latent dimensions.