mixle.ppl.density module

Neural densities for mixle.ppl – flexible p(x) and p(y | x) as first-class PPL constructors.

The nonlinear sibling of the plain distribution constructors. mixle.ppl.neural puts a neural predictor (Net/Conv/Transformer) into an outer family’s slot, so the outer family still fixes the likelihood shape (a Gaussian mean, softmax logits). These constructors instead make the neural model be the whole density:

Flow(dim=2).fit(x) # exact p(x) via a normalizing flow VAE(dim=8, latent=2).fit(x) # latent-variable p(x) (ELBO) DiscreteAR(dim=5, cats=4).fit(x) # exact p(x) over discrete vectors EBM(dim=2).fit(x) # energy-based p(x) (NCE-trained, approximately normalized) MDN(x_dim=1, y_dim=1).fit(y, given={“x”: X}) # multimodal p(y|x) CondFlow(x_dim=1, y_dim=2).fit(y, given={“x”: X}) # exact conditional p(y|x)

Each lowers to the composable NeuralDensity / NeuralConditionalDensity leaf and fits through the same optimize EM loop – no loss function, no training loop in user code. A fitted model is a bound RandomVariable whose .dist is the leaf, so it drops into a Mix/composite like any distribution.

Flow(dim, *, hidden=32, layers=4, m_steps=80, lr=5e-3)[source]

An exact p(x) over R^dim via a RealNVP coupling flow. Fit with .fit(x).

Parameters:
Return type:

RandomVariable

MAF(dim, *, hidden=64, blocks=3, m_steps=80, lr=5e-3)[source]

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

Parameters:
Return type:

RandomVariable

VAE(dim, *, latent=2, hidden=32, m_steps=120, lr=5e-3)[source]

A latent-variable p(x) over R^dim via a VAE. log_density is the ELBO (a lower bound); fit .fit(x).

Parameters:
Return type:

RandomVariable

DiscreteAR(dim, cats, *, hidden=64, m_steps=100, lr=5e-3)[source]

An exact p(x) over discrete vectors x in {0..cats-1}^dim (autoregressive). Fit with .fit(x).

Parameters:
Return type:

RandomVariable

EBM(dim, *, hidden=64, layers=3, noise_ratio=2, m_steps=250, lr=5e-3)[source]

An energy-based p(x) exp(-E(x)) over R^dim, trained by NCE (approximately normalized). Fit .fit(x).

Parameters:
Return type:

RandomVariable

MDN(x_dim, y_dim, *, k=5, hidden=32, field='x', m_steps=120, lr=5e-3)[source]

A multimodal, heteroscedastic p(y | x) via a mixture density network. Fit .fit(y, given={"x": X}).

Parameters:
Return type:

RandomVariable

CondFlow(x_dim, y_dim, *, hidden=32, layers=4, field='x', m_steps=100, lr=5e-3)[source]

An exact conditional p(y | x) via a conditional coupling flow (needs y_dim >= 2). Fit with covariates.

Parameters:
Return type:

RandomVariable

CondDiscreteAR(x_dim, y_dim, cats, *, hidden=64, field='x', m_steps=120, lr=5e-3)[source]

An exact conditional p(y | x) over discrete y (autoregressive, conditioned on x). Fit w/ covariates.

Parameters:
Return type:

RandomVariable