mixle.models.neural_families moduleΒΆ
Constructible neural-density families β VAE(dim=8, latent=2) instead of NeuralDensity(build_vae(...)).
Each class here is a thin subclass of NeuralDensity whose __init__ builds
its torch module from readable hyperparameters. So a neural density is a first-class distribution object you drop
straight into a MixtureDistribution / composite / HMM emission β no ``build_* `` + adapter double-wrap:
from mixle.models import VAE
from mixle.stats import GaussianDistribution, MixtureDistribution
mix = MixtureDistribution([VAE(dim=8, latent=2), GaussianDistribution(...)], [0.5, 0.5])
fitted = optimize(x, mix.estimator()) # one estimator() at the top -- fits the VAE jointly by EM
They fit through the same NeuralDensityEstimator; construct that directly to
build an estimator tree without a dist.estimator() hop:
from mixle.models import NeuralDensityEstimator, build_vae
from mixle.stats import MixtureEstimator, GaussianEstimator
est = MixtureEstimator([NeuralDensityEstimator(build_vae(8, latent=2)), GaussianEstimator()])
The classes live in this module (not neural_density) on purpose: the wrapped nn.Module classes are already
resolved as neural_density.<Name> for pickle, so a distribution class of the same name there would shadow them.
- class VAE(dim, *, latent=2, hidden=32, m_steps=120, lr=5e-3, device='cpu', name=None)[source]
Bases:
_NeuralFamilyA latent-variable
p(x)overR^dimvia a variational autoencoder.log_densityis the ELBO β a lower bound onlog p(x), evaluated deterministically at the encoder mean (so an EM log-likelihood stays monotone). Honest on its own, in a mixture of VAEs, or against another bounded leaf; mixing it with an exact-density leaf (a Gaussian, a flow) compares a bound against an exact value and under-weights the VAE. Seebuild_vae()for the full statement.
- class Flow(dim, *, hidden=32, layers=4, m_steps=80, lr=5e-3, device='cpu', name=None)[source]
Bases:
_NeuralFamilyAn exact
p(x)overR^dimvia a RealNVP coupling flow (invertible map to a standard-normal base).
- class MAF(dim, *, hidden=64, blocks=3, m_steps=80, lr=5e-3, device='cpu', name=None)[source]
Bases:
_NeuralFamilyAn exact
p(x)overR^dimvia a masked autoregressive flow (richer autoregressive dependence).
- class DiscreteAR(dim, cats, *, hidden=64, m_steps=100, lr=5e-3, device='cpu', name=None)[source]
Bases:
_NeuralFamilyAn exact, normalized
p(x)over discrete vectorsx in {0..cats-1}^dim(autoregressive, MADE-masked).