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: _NeuralFamily

A latent-variable p(x) over R^dim via a variational autoencoder.

log_density is the ELBO – a lower bound on log 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. See build_vae() for the full statement.

Parameters:
class Flow(dim, *, hidden=32, layers=4, m_steps=80, lr=5e-3, device='cpu', name=None)[source]

Bases: _NeuralFamily

An exact p(x) over R^dim via a RealNVP coupling flow (invertible map to a standard-normal base).

Parameters:
class MAF(dim, *, hidden=64, blocks=3, m_steps=80, lr=5e-3, device='cpu', name=None)[source]

Bases: _NeuralFamily

An exact p(x) over R^dim via a masked autoregressive flow (richer autoregressive dependence).

Parameters:
class DiscreteAR(dim, cats, *, hidden=64, m_steps=100, lr=5e-3, device='cpu', name=None)[source]

Bases: _NeuralFamily

An exact, normalized p(x) over discrete vectors x in {0..cats-1}^dim (autoregressive, MADE-masked).

Parameters: