mixle.reason.model module¶
Trainable cross-modal reasoning model with a shared latent.
This module learns per-modality encoders and decoders jointly from unlabeled multimodal records. The latent is not observed; training maximizes a Product-of-Experts variational lower bound for a multimodal VAE-style model.
Each modality
mhas an encoderq_m(z | x_m) = N(mu_m, diag(sig_m^2)).The belief given any subset of modalities is the product of experts with the prior: precisions add, so more modalities produce a sharper belief. This matches
mixle.inference.belief.GaussianBelief.fuse()with learned experts.Each modality has a decoder
p(x_m | z); training reconstructs every modality from the fused latent. Modality-subset subsampling lets inference work from one modality, all modalities, or any subset between them.
After training: belief(obs) returns q(z | available modalities) as a
GaussianBelief, and predict(obs, target)
generates a missing modality from the available ones. Uncertainty remains part
of the object: the returned belief is a distribution, sharpened by each
modality in proportion to its learned precision.
Torch is imported lazily; mixle.reason exposes this via a deferred attribute.
- class CrossModalModel(latent_dim, *, seed=0)[source]
Bases:
objectA multimodal Product-of-Experts VAE: one shared latent learned from many modalities, unsupervised.
- add_modality(name, in_dim, *, hidden=(64,))[source]
Register a modality with learned encoder
q(z|x)and decoderp(x|z).
- fit(data, *, epochs=600, lr=3e-3, beta=0.5, subsample=True)[source]
Train encoders and decoders jointly on unlabeled multimodal data.
datamaps each registered modality name to an(N, in_dim)array (all modalities share the sameNrows – rowiis one record’s several views).betaweights the KL rate; withsubsample=Truethe ELBO is also evaluated on each single-modality subset so the model can inferzfrom any one modality alone (the MVAE training trick).
- belief(obs)[source]
The belief
q(z | available modalities)as aGaussianBelief(product of experts).
- encode(obs)[source]
The posterior-mean latent code for
obs(a shared-space embedding usable as store keys).
- predict(obs, target)[source]
Generate the
targetmodality from the modalities inobs(cross-modal generation).
- calibrate(cal_data, target, *, alpha=0.1)[source]
Calibrate cross-modal prediction of
targetfor finite-sample coverage (split conformal).On a held-out calibration set, predict
targetfrom the other modalities, normalize the per-dimension residuals, and take theceil((n+1)(1-alpha))-th largest max-normalized residual as the conformal radius. Using the max over dimensions makes the guarantee simultaneous:predict_interval()returns a box whose joint coverage over the whole target vector is>= 1 - alpha– distribution-free, regardless of model specification (unlike the Gaussian posterior interval).
- predict_interval(obs, target)[source]
A conformally-calibrated prediction box
(lower, upper)fortargetgivenobs.Requires a prior
calibrate()call fortarget. Coverage is distribution-free and simultaneous:P(y in box) >= 1 - alphajointly over the whole target vector.