mixle.reason.encoder module¶
Amortized modality encoders: raw features -> a Gaussian expert about the latent.
A generative proxy models p(x | z) and is exact but expensive for high-dimensional modalities
(images, spectra, long series). The scalable alternative is amortized: learn a network
enc(x) -> N(mu(x), diag(sigma^2(x))) that maps a modality’s features directly to a Gaussian
belief about the shared latent – a soft observation, fused with other modalities as a product
of experts (mixle.inference.belief.GaussianBelief.fuse()) and consumed by
mixle.reason.reason() as evidence.
The encoder is heteroscedastic: it learns to report a smaller variance on informative inputs
and a larger one on ambiguous inputs, so product-of-experts fusion automatically down-weights a
modality exactly where it does not know – the behavior a fixed-noise (homoscedastic) head cannot
express. Training is amortized probabilistic regression (Gaussian negative log-likelihood over
(x, z) pairs); at inference, encoding is a single forward pass.
Torch is imported lazily inside this module, so the encoder’s network is only built when an encoder
is actually constructed (mixle.reason exposes it via a deferred attribute). Domain-neutral:
application-specific encoders (a seismic-trace encoder, a spectra encoder) subclass or configure
this in the mixle_pde layer, not here.
- class AmortizedEncoder(in_dim, latent_dim, *, hidden=(64,), min_sd=1e-3, seed=0)[source]
Bases:
objectA learned encoder mapping modality features to a diagonal-Gaussian belief about the latent.
- Parameters:
in_dim (int) – width of the input feature vector.
latent_dim (int) – dimension of the (sub-)latent this encoder informs.
hidden (tuple[int, ...]) – hidden-layer widths of the MLP trunk.
min_sd (float) – floor on the predicted standard deviation (in latent units), preventing an over-confident zero-variance expert.
seed (int) – torch RNG seed for reproducible initialization/training.
- fit(X, Z, *, epochs=300, lr=1e-2, weight_decay=0.0)[source]
Train the encoder on
(X, Z)pairs by heteroscedastic Gaussian negative log-likelihood.Xis(n, in_dim)modality features,Zis(n, latent_dim)latent targets. Inputs and targets are standardized internally for stable optimization.
- encode(x)[source]
Encode one input into a diagonal-Gaussian belief
N(mu(x), diag(sigma^2(x))).- Parameters:
x (Any)
- Return type:
GaussianBelief
- encode_batch(X)[source]
Encode a batch ->
(means (n, d), variances (n, d))in latent units.
- evidence(x, *, onto=None, name='')[source]
A
LinearGaussianEvidenceformixle.reason.reason()from encodingx.The encoder’s Gaussian output
N(mu, diag(var))is a direct observation of its target latent.ontooptionally maps a larger shared latent onto this encoder’s target space (a readout / selector matrix, shape(latent_dim, full_dim)); by defaultH = I(the encoder targets the whole latent).