mixle.ppl.distributions module

The mixle.ppl distribution dialect — conventional constructors returning symbolic RandomVariables.

Normal(mean, sd), Gamma(shape, rate), Mix([...]), Markov(emission, states=k), MVN(dim), … — each returns a RandomVariable in a registered family (the registrations live in mixle.ppl._lowering). A parameter slot accepts a concrete value, the token free (estimate it), or another RandomVariable. Extracted from mixle/ppl/__init__.py.

Normal(mean, sd, *, name=None, keys=None)[source]

Normal with mean and standard deviation (lowers to GaussianDistribution(mu, sd**2)).

Parameters:
Return type:

RandomVariable

Poisson(rate, *, name=None, keys=None)[source]
Parameters:
  • rate (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Gamma(shape, rate, *, name=None, keys=None)[source]

Gamma with shape and rate (lowers to GammaDistribution(k=shape, theta=1/rate)).

Parameters:
  • shape (Any)

  • rate (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Exponential(rate, *, name=None, keys=None)[source]

Exponential with rate (mean 1/rate; lowers to ExponentialDistribution(beta=1/rate)).

Parameters:
  • rate (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Bernoulli(p, *, name=None, keys=None)[source]
Parameters:
  • p (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Geometric(p, *, name=None, keys=None)[source]
Parameters:
  • p (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Beta(a, b, *, name=None, keys=None)[source]
Parameters:
Return type:

RandomVariable

Dirichlet(alpha, *, dim=None, name=None, keys=None)[source]

Dirichlet over a simplex; used as a prior on Categorical probabilities (VMP). The concentration alpha is also an inferable parameter. Dirichlet(free) learns the concentration by maximum likelihood, inferring the dimension K from the observed simplex data (no dim= needed); pass dim=K to request the explicit positive-K-vector parameter treatment for how='mcmc'|'ensemble'|'map'.

Parameters:
  • alpha (Any)

  • dim (int | None)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Graph()[source]

A VMP factor graph for arbitrary conjugate-Gaussian DAGs with shared variables. See mixle.ppl.vmp.Graph.

StudentT(df, loc, scale, *, name=None, keys=None)[source]

Student-t with degrees of freedom, location, scale (heavy-tailed Normal).

Parameters:
Return type:

RandomVariable

LogNormal(mu, sigma, *, name=None, keys=None)[source]

Log-normal: log(X) ~ Normal(mu, sigma).

Parameters:
Return type:

RandomVariable

EMG(mu, sigma, rate, *, name=None, keys=None)[source]

Exponentially-modified Gaussian: X = Normal(mu, sigma) + Exponential(rate) (right-skewed).

Lowers to ExponentiallyModifiedGaussianDistribution(mu, sigma**2, lam=rate); rate is the exponential component’s rate (its mean is 1/rate). The MLE is iterative with no closed form, so EMG(free, free, free).fit(data) uses a consistent method-of-moments estimate.

Parameters:
Return type:

RandomVariable

NegativeBinomial(r, p, *, name=None, keys=None)[source]

Negative binomial with r failures and success probability p.

Parameters:
Return type:

RandomVariable

HalfNormal(sigma, *, name=None, keys=None)[source]

Half-normal on [0, inf) with scale sigma – the standard weakly-informative scale prior.

Parameters:
  • sigma (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

InverseGamma(alpha, beta, *, name=None, keys=None)[source]

Inverse-gamma(alpha, beta) – the classic conjugate prior for a variance.

Parameters:
  • alpha (Any)

  • beta (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

InverseGaussian(mu, lam, *, name=None, keys=None)[source]

Inverse-Gaussian (Wald) with mean mu and shape lam – a positive, right-skewed law.

Parameters:
Return type:

RandomVariable

Gumbel(loc, scale, *, name=None, keys=None)[source]

Gumbel (type-I extreme-value) with loc and scale – for maxima / extremes.

Parameters:
Return type:

RandomVariable

SkewNormal(loc, scale, shape, *, name=None, keys=None)[source]

Skew-normal with loc, scale, and shape (skewness; shape=0 recovers the Normal).

Parameters:
Return type:

RandomVariable

Skellam(mu1, mu2, *, name=None, keys=None)[source]

Skellam: the difference of two independent Poisson(mu1) and Poisson(mu2) counts.

Parameters:
Return type:

RandomVariable

LogSeries(p, *, name=None, keys=None)[source]

Logarithmic (log-series) distribution on {1, 2, ...} with parameter p in (0, 1).

Parameters:
  • p (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

VonMises(mu, kappa, *, name=None, keys=None)[source]

Von Mises (circular normal) on the angle (-pi, pi] with mean mu and concentration kappa.

Parameters:
Return type:

RandomVariable

GEV(loc, scale, shape, *, name=None, keys=None)[source]

Generalized extreme value with loc, scale, shape (the block-maxima limit law).

Parameters:
Return type:

RandomVariable

Tweedie(mu, phi, *, name=None, keys=None)[source]

Tweedie compound Poisson-Gamma (power p=1.5) with mean mu and dispersion phi.

A positive distribution with an atom at zero – the standard model for non-negative data that is part-zero, part-continuous (insurance claims, rainfall, ecological biomass).

Parameters:
Return type:

RandomVariable

GeneralizedGaussian(mu, alpha, beta, *, name=None, keys=None)[source]

Generalized Gaussian (exponential power) with mu, scale alpha, shape beta.

beta=2 is the Normal and beta=1 is the Laplace, so it interpolates between light and heavy tails – a flexible symmetric error model.

Parameters:
Return type:

RandomVariable

GeneralizedPareto(scale, shape, loc=0.0, *, name=None, keys=None)[source]

Generalized Pareto (scale, tail shape, threshold loc) – the peaks-over-threshold tail law.

Parameters:
Return type:

RandomVariable

Nakagami(m, omega, *, name=None, keys=None)[source]

Nakagami-m distribution with shape m and spread omega (signal-fading amplitudes).

Parameters:
Return type:

RandomVariable

Rician(nu, sigma, *, name=None, keys=None)[source]

Rician (Rice) distribution with non-centrality nu and scale sigma (signal-plus-noise magnitude).

Parameters:
Return type:

RandomVariable

Categorical(probs=None, *, logits=None, dim=None, name=None, keys=None)[source]

Categorical from a probability dict {value: p} or a list of probabilities. The probability vector is also an inferable parameter. Categorical(free) learns the category probabilities by maximum likelihood, discovering the categories (and their count) from the data – no dim= needed; pass dim=K to request the explicit simplex-parameter treatment for how='mcmc'|'ensemble'|'map'.

Categorical(logits=Net(out=K)) is neural classification: p(y|x) = softmax(Net(x)), the softmax-link sibling of logistic regression. Fit with the conditional verb .fit(y, given={"x": X}).

Parameters:
  • probs (Any)

  • logits (Any)

  • dim (int | None)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Weibull(shape, scale, *, name=None, keys=None)[source]

Weibull with shape (k) and scale (lambda).

Parameters:
  • shape (Any)

  • scale (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Laplace(loc, scale, *, name=None, keys=None)[source]

Laplace (double-exponential) with location and scale (b).

Parameters:
Return type:

RandomVariable

Logistic(loc, scale, *, name=None, keys=None)[source]

Logistic with location and scale.

Parameters:
Return type:

RandomVariable

Uniform(low, high, *, name=None, keys=None)[source]

Continuous uniform on [low, high].

Parameters:
Return type:

RandomVariable

Rayleigh(sigma, *, name=None, keys=None)[source]

Rayleigh with scale sigma.

Parameters:
  • sigma (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Pareto(scale, shape, *, name=None, keys=None)[source]

Pareto with minimum value xm (scale) and tail index alpha (shape).

Parameters:
  • scale (Any)

  • shape (Any)

  • name (str | None)

  • keys (str | None)

Return type:

RandomVariable

Binomial(n, p, *, name=None, keys=None)[source]

Binomial with n trials and success probability p (n is fixed/known).

Parameters:
Return type:

RandomVariable

Mix(components, weights=None, *, name=None)[source]

Finite mixture over component RandomVariables (or concrete distributions).

Mix([Normal(free, free), Normal(free, free)]).fit(data) fits a 2-component Gaussian mixture; .posterior(data) returns the responsibilities.

Parameters:

name (str | None)

Return type:

RandomVariable

SemiMix(components, weights=None, *, name=None)[source]

Semi-supervised finite mixture over component RandomVariables (or concrete distributions).

Like Mix(), but each observation is a (value, prior) pair where prior is either None (unlabeled) or a sequence of (component_index, probability) pairs giving a partial label. Labeled rows restrict/re-weight the responsibilities to the listed components, so a few labels can anchor the components. SemiMix([Normal(free, free), Normal(free, free)]).fit(data) fits a 2-component Gaussian mixture from a mix of labeled and unlabeled rows.

Parameters:

name (str | None)

Return type:

RandomVariable

Seq(element, *, name=None)[source]

IID sequence of element. Fit on a list of sequences (each a list/array).

Parameters:

name (str | None)

Return type:

RandomVariable

LocalLevel(*, name=None)[source]

Local-level state-space model (random walk + noise) for a time series. Fit on a 1-D series; recovers level/observation noise and smoothed states (Kalman/RTS + EM).

Parameters:

name (str | None)

Return type:

RandomVariable

AR1(*, name=None)[source]

AR(1)-plus-noise state-space model; estimates the autoregressive coefficient phi.

Parameters:

name (str | None)

Return type:

RandomVariable

MVN(dim, *, mean=None, cov=None, name=None)[source]

Multivariate Gaussian of dimension dim (full covariance). Fit on a list of length-dim vectors; MVN(dim).fit(X) recovers mean and covariance by EM.

The mean vector and covariance matrix are also inferable parameters: pass mean=free (a dim-vector on the real line) or mean=ordered (increasing entries, for identifiability) and/or cov=free (a full SPD covariance via its Cholesky factor) and fit with how='mcmc'|'ensemble'|'map'.

Parameters:
Return type:

RandomVariable

DiagGaussian(dim, *, mean=None, var=None, name=None)[source]

Diagonal-covariance multivariate Gaussian of dimension dim. DiagGaussian(dim).fit(X) recovers mean and per-axis variance by EM; the mean vector (mean=free / ordered) and diagonal variances (var=free, a positive vector) are also inferable parameters via how='mcmc'|'ensemble'|'map'.

Parameters:
Return type:

RandomVariable

LDA(num_topics, vocab_size, *, alpha=1.0, name=None)[source]

Latent Dirichlet allocation. Fit on a list of documents, each a bag of (word_id, count) pairs over word ids 0..vocab_size-1. Topics are recovered as word distributions; alpha (the document-topic Dirichlet) is fixed by default.

Parameters:
Return type:

RandomVariable

Markov(emission, states=None, *, transitions=None, initial=None, name=None)[source]

Hidden Markov model over latent states emitting emission.

Markov(Normal(free, free), states=2).fit(sequences) fits a 2-state Gaussian HMM by EM (emissions k-means++ seeded so states separate); .posterior(sequences) gives state posteriors. For per-state priors pass a list of emissions, one per state: Markov([Normal(m0, 1), Normal(m1, 1)]). The transition matrix and initial distribution are inferable parameters too: pass transitions=free / transitions=Dirichlet(alpha) (each row a simplex) and/or initial=free / initial=Dirichlet(alpha) and fit with how='mcmc'|'ensemble'|'map' (typically with an ordered-emission constraint for identifiability).

Parameters:
  • states (int | None)

  • name (str | None)

Return type:

RandomVariable