mixle.stats.latent.probabilistic_pca module

Probabilistic PCA latent-factor distributions and estimators.

Observations are length-d real vectors represented as np.ndarray or a compatible sequence of floats.

Probabilistic PCA is the latent linear-Gaussian model

z ~ N(0, I_q), x | z ~ N(W z + mu, sigma2 * I_d),

so marginally x ~ N(mu, C) with the structured covariance C = W W^T + sigma2 * I_d (a rank-q factor structure plus isotropic noise). It is the probabilistic foundation of PCA / factor analysis and gives a generative model, a likelihood, and a posterior over the latent factors E[z | x] = M^{-1} W^T (x - mu) (the low-dimensional embedding, exposed by transform), with M = W^T W + sigma2 * I_q.

Scoring uses the Woodbury identity, so the d-by-d inverse and log-determinant are obtained from a small q-by-q solve (C^{-1} = (I_d - W M^{-1} W^T) / sigma2 and log|C| = (d-q) log sigma2 + log|M|); the reduction is engine-neutral, so the model scores on NumPy and Torch. Estimation is the closed-form maximum-likelihood solution of Tipping & Bishop (1999): sigma2 is the mean of the discarded eigenvalues of the sample covariance and W is built from its top-q eigenpairs – no EM iteration.

class ProbabilisticPCADistribution(w, mu, sigma2, name=None, keys=None)[source]

Bases: SequenceEncodableProbabilityDistribution

Probabilistic PCA: x ~ N(mu, W W^T + sigma2 I) with q latent factors.

Parameters:
classmethod compute_capabilities()[source]

Return compute-backend metadata for PPCA scoring.

transform(x)[source]

Return the posterior mean of the latent factors E[z | x] = M^{-1} W^T (x - mu).

Parameters:

x (Sequence[float] | ndarray)

Return type:

ndarray

density(x)[source]

Return the probability density at a single observation.

Parameters:

x (Sequence[float] | ndarray)

Return type:

float

log_density(x)[source]

Return the log-density at a single observation.

Parameters:

x (Sequence[float] | ndarray)

Return type:

float

seq_log_density(x)[source]

Return vectorized log-density values for sequence-encoded observations.

Parameters:

x (ndarray)

Return type:

ndarray

backend_seq_log_density(x, engine)[source]

Engine-neutral vectorized log-density for encoded data.

Parameters:
Return type:

Any

sampler(seed=None)[source]

Return a sampler for drawing observations from this distribution.

Parameters:

seed (int | None)

Return type:

ProbabilisticPCASampler

estimator(pseudo_count=None)[source]

Return a closed-form ML estimator with the latent dimension fixed at this model’s q.

Parameters:

pseudo_count (float | None)

Return type:

ProbabilisticPCAEstimator

dist_to_encoder()[source]

Return the data encoder used by this distribution for vectorized methods.

Return type:

ProbabilisticPCADataEncoder

class ProbabilisticPCASampler(dist, seed=None)[source]

Bases: DistributionSampler

Draw iid observations x = mu + W z + sigma * eps from a PPCA model.

Parameters:
  • dist (ProbabilisticPCADistribution)

  • seed (int | None)

sample(size=None)[source]

Draw size iid vectors (shape (d,) when size is None, else (size, d)).

Parameters:

size (int | None)

Return type:

ndarray

class ProbabilisticPCAAccumulator(dim=None, keys=None)[source]

Bases: SequenceEncodableStatisticAccumulator

Accumulate the weighted count, mean, and second-moment matrix (the PPCA sufficient statistics).

Parameters:
  • dim (int | None)

  • keys (str | None)

update(x, weight, estimate)[source]

Accumulate weighted count, sum, and second moment for one vector.

Parameters:
  • x (ndarray)

  • weight (float)

  • estimate (ProbabilisticPCADistribution | None)

Return type:

None

initialize(x, weight, rng)[source]

Initialize the sufficient statistics with one weighted vector.

Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]

Accumulate weighted count, sum, and second moment for encoded vectors.

Parameters:
  • x (ndarray)

  • weights (ndarray)

  • estimate (ProbabilisticPCADistribution | None)

Return type:

None

seq_initialize(x, weights, rng)[source]

Initialize the sufficient statistics from encoded vectors.

Parameters:
Return type:

None

combine(suff_stat)[source]

Merge serialized PPCA sufficient statistics into this accumulator.

Parameters:

suff_stat (tuple[float, ndarray | None, ndarray | None])

Return type:

ProbabilisticPCAAccumulator

value()[source]

Return the total weight, weighted sum, and weighted second moment.

Return type:

tuple[float, ndarray | None, ndarray | None]

from_value(x)[source]

Restore the accumulator from serialized PPCA sufficient statistics.

Parameters:

x (tuple[float, ndarray | None, ndarray | None])

Return type:

ProbabilisticPCAAccumulator

key_merge(stats_dict)[source]

Merge this accumulator into a keyed statistics dictionary.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator from a keyed statistics dictionary.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

acc_to_encoder()[source]

Return an encoder compatible with PPCA vector observations.

Return type:

ProbabilisticPCADataEncoder

class ProbabilisticPCAAccumulatorFactory(dim=None, keys=None)[source]

Bases: StatisticAccumulatorFactory

Factory for ProbabilisticPCAAccumulator.

Parameters:
  • dim (int | None)

  • keys (str | None)

make()[source]

Create an empty PPCA accumulator.

Return type:

ProbabilisticPCAAccumulator

class ProbabilisticPCAEstimator(latent_dim, dim=None, min_sigma2=_MIN_SIGMA2, name=None, keys=None)[source]

Bases: ParameterEstimator

Closed-form maximum-likelihood estimator for PPCA (Tipping & Bishop eigen-solution).

Parameters:
  • latent_dim (int)

  • dim (int | None)

  • min_sigma2 (float)

  • name (str | None)

  • keys (str | None)

accumulator_factory()[source]

Return a factory for PPCA sufficient-statistic accumulators.

Return type:

ProbabilisticPCAAccumulatorFactory

estimate(nobs, suff_stat)[source]

Estimate PPCA parameters from weighted first and second moments.

Parameters:
Return type:

ProbabilisticPCADistribution

class ProbabilisticPCADataEncoder[source]

Bases: DataSequenceEncoder

Encode a sequence of length-d real vectors into an (n, d) float array.

seq_encode(x)[source]

Validate and encode observations as a two-dimensional float array.

Parameters:

x (Sequence[Sequence[float]] | ndarray)

Return type:

ndarray