mixle.inference.fisher module¶
Generic Fisher-geometry views for mixle distributions.
The classes here expose a common sufficient-statistic and Fisher-vector interface without requiring every distribution to duplicate plumbing. The generic view is accumulator-backed: for ordinary models it returns observed sufficient statistics, while latent models use the existing update/seq_update E-step to return posterior-expected complete-data sufficient statistics.
Specialized distributions can later override to_fisher() with faster or more canonical views, but this default gives every stats/bstats model a useful and vectorizable baseline.
For latent-variable models, fisher_information() may expose a model or complete-data Fisher metric supplied by the view. When comparing observed data, use observed_fisher_information() / observed_fisher_vectors(): these center posterior-expected complete-data statistics into observed score vectors and use their observed covariance as the metric.
- class SufficientStatisticVectorizer(labels=None)[source]
Bases:
objectFlatten nested sufficient-statistic structures into numeric vectors.
Accumulators in mixle return tuples, arrays, dictionaries, and scalars. This vectorizer learns a stable union schema from a collection of such structures and then maps each structure into the same numeric coordinate system.
- Parameters:
labels (Sequence[Path] | None)
- partial_fit(values)[source]
- transform(values, extend=False)[source]
- class FisherView(dist, estimator=None)[source]
Bases:
objectAccumulator-backed Fisher-geometry view of a distribution.
- Parameters:
dist (Any) – mixle.stats or mixle.bstats distribution.
estimator (Any | None) – Optional estimator. When omitted, dist.estimator() is used.
Notes
The generic encoded-data path obtains per-row statistics by replaying seq_update with one-hot weights. That keeps the interface compatible with existing encoders, but it is a correctness fallback rather than a high-performance implementation. Important families should override to_fisher() with direct seq_expected_statistics kernels.
- structured_statistics(x, estimate=None, weight=1.0)[source]
Structured sufficient stats for one observation.
For latent-variable distributions, this is the posterior-expected complete-data sufficient statistic under estimate (or this view’s distribution when estimate is omitted).
- expected_structured_statistics(x, estimate=None, weight=1.0)[source]
- sufficient_statistics(x, estimate=None, vectorizer=None)[source]
- expected_sufficient_statistics(x, estimate=None, vectorizer=None)[source]
- seq_structured_statistics(enc_data, estimate=None)[source]
Structured per-row stats from encoded data.
This generic implementation is intentionally conservative and may be slow for large data. It exists so every encoder-compatible model has a correct baseline.
- statistics_matrix(data=None, enc_data=None, estimate=None, vectorizer=None, fit=True)[source]
Return an n x d matrix of per-observation sufficient statistics.
- expected_statistics_matrix(data=None, enc_data=None, estimate=None, vectorizer=None, fit=True)[source]
- seq_expected_statistics(enc_data, estimate=None, vectorizer=None, fit=True)[source]
- mean_statistics(stats=None, **kwargs)[source]
- score_center(stats=None, **kwargs)[source]
- fisher_information(stats=None, diagonal=False, ridge=1.0e-8, **kwargs)[source]
Empirical Fisher approximation from per-observation statistic vectors.
- fisher_vectors(stats=None, metric='diagonal', center=None, fisher=None, ridge=1.0e-8, **kwargs)[source]
Return centered/whitened sufficient-statistic vectors.
metric=’identity’ returns centered statistics, ‘diagonal’ divides by per-coordinate Fisher standard deviations, and ‘full’ applies an empirical full-matrix whitening transform.
- observed_fisher_information(stats=None, diagonal=False, center=None, ridge=1.0e-8, **kwargs)[source]
Observed Fisher estimate from score vectors for observed data.
For latent models the statistic rows are posterior-expected complete-data sufficient statistics, so centering them by their model expectation gives observed score vectors. Their covariance is the observed Fisher metric used by Fisher-vector embeddings. If a model center is unavailable, this falls back to the empirical mean.
- observed_fisher_vectors(stats=None, metric='diagonal', center=None, fisher=None, ridge=1.0e-8, **kwargs)[source]
- fisher_vector(x, estimate=None, metric='diagonal', center=None, fisher=None, vectorizer=None, ridge=1.0e-8)[source]
- class FixedFisherView(dist, labels)[source]
Bases:
FisherViewDistribution-specific Fisher view with fixed vector coordinates.
- Parameters:
dist (Any)
labels (Sequence[Path])
- structured_statistics(x, estimate=None, weight=1.0)[source]
Structured sufficient stats for one observation.
For latent-variable distributions, this is the posterior-expected complete-data sufficient statistic under estimate (or this view’s distribution when estimate is omitted).
- sufficient_statistics(x, estimate=None, vectorizer=None)[source]
- seq_structured_statistics(enc_data, estimate=None)[source]
Structured per-row stats from encoded data.
This generic implementation is intentionally conservative and may be slow for large data. It exists so every encoder-compatible model has a correct baseline.
- statistics_matrix(data=None, enc_data=None, estimate=None, vectorizer=None, fit=True)[source]
Return an n x d matrix of per-observation sufficient statistics.
- mean_statistics(stats=None, model=True, **kwargs)[source]
- fisher_information(stats=None, diagonal=False, ridge=1.0e-8, **kwargs)[source]
Empirical Fisher approximation from per-observation statistic vectors.
- fisher_vectors(stats=None, metric='diagonal', center=None, fisher=None, ridge=1.0e-8, **kwargs)[source]
Return centered/whitened sufficient-statistic vectors.
metric=’identity’ returns centered statistics, ‘diagonal’ divides by per-coordinate Fisher standard deviations, and ‘full’ applies an empirical full-matrix whitening transform.
- class CountFisherView(dist, mean_var_fn, data_fn, enc_fn)[source]
Bases:
FixedFisherView
- class EmpiricalMetricFixedFisherView(dist, labels)[source]
Bases:
FixedFisherViewFixed-coordinate view whose whitening falls back to empirical Fisher.
- Parameters:
dist (Any)
labels (Sequence[Path])
- mean_statistics(stats=None, **kwargs)[source]
- fisher_information(stats=None, diagonal=False, ridge=1.0e-8, **kwargs)[source]
Empirical Fisher approximation from per-observation statistic vectors.
- fisher_vectors(stats=None, metric='diagonal', center=None, fisher=None, ridge=1.0e-8, **kwargs)[source]
Return centered/whitened sufficient-statistic vectors.
metric=’identity’ returns centered statistics, ‘diagonal’ divides by per-coordinate Fisher standard deviations, and ‘full’ applies an empirical full-matrix whitening transform.
- to_fisher(dist, **kwargs)[source]
Return a FisherView for
distvia its ownto_fisherhook.Fisher views are co-located with each distribution: a distribution owns its view by overriding
ProbabilityDistribution.to_fisher. This module keeps only the shared base machinery (FisherView/FixedFisherView/SufficientStatisticVectorizer and the reusable CountFisherView / EmpiricalMetricFixedFisherView helpers) plus_legacy_to_fisher(), the type-name dispatch for families not yet migrated to a per-file hook (and the generic fallback).