state.posteriors
Posterior distributions for state model parameters.
Classes
-
class LatentsPosteriorStatic(
- mean: ndarray | None = None,
- cov: ndarray | None = None,
- moment: ndarray | None = None,
)[source]
Posterior distribution q(X) for static latents.
- Parameters:
- mean
ndarray of float, shape (x_dim, n_samples) or None, default None Posterior mean.
- cov
ndarray of float, shape (x_dim, x_dim) or None, default None Posterior covariance (shared across samples).
- moment
ndarray of float, shape (x_dim, x_dim) or None, default None Posterior second moments.
- Attributes:
- mean
ndarray of float, shape (x_dim, n_samples) or None Posterior mean.
- cov
ndarray of float, shape (x_dim, x_dim) or None Posterior covariance (shared across samples).
- moment
ndarray 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:
LatentsRealizationPosterior mean wrapped as a realization.
-
sample(
- rng: Generator,
) → LatentsRealization[source]
Draw X from the posterior distribution.
- Parameters:
- rng
numpy.random.Generator Random number generator.
- Returns:
LatentsRealizationSampled 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_indices
ndarray 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:
SelfThe modified instance (if in_place=True) or a new instance
with only the specified latent dimensions.