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)).
- Poisson(rate, *, name=None, keys=None)[source]
- Gamma(shape, rate, *, name=None, keys=None)[source]
Gamma with shape and rate (lowers to GammaDistribution(k=shape, theta=1/rate)).
- Exponential(rate, *, name=None, keys=None)[source]
Exponential with rate (mean 1/rate; lowers to ExponentialDistribution(beta=1/rate)).
- Bernoulli(p, *, name=None, keys=None)[source]
- Geometric(p, *, name=None, keys=None)[source]
- Beta(a, b, *, name=None, keys=None)[source]
- Dirichlet(alpha, *, dim=None, name=None, keys=None)[source]
Dirichlet over a simplex; used as a prior on Categorical probabilities (VMP). The concentration
alphais also an inferable parameter.Dirichlet(free)learns the concentration by maximum likelihood, inferring the dimensionKfrom the observed simplex data (nodim=needed); passdim=Kto request the explicit positive-K-vector parameter treatment forhow='mcmc'|'ensemble'|'map'.
- 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).
- LogNormal(mu, sigma, *, name=None, keys=None)[source]
Log-normal: log(X) ~ Normal(mu, sigma).
- 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);rateis the exponential component’s rate (its mean is1/rate). The MLE is iterative with no closed form, soEMG(free, free, free).fit(data)uses a consistent method-of-moments estimate.
- NegativeBinomial(r, p, *, name=None, keys=None)[source]
Negative binomial with r failures and success probability p.
- HalfNormal(sigma, *, name=None, keys=None)[source]
Half-normal on
[0, inf)with scalesigma– the standard weakly-informative scale prior.
- InverseGamma(alpha, beta, *, name=None, keys=None)[source]
Inverse-gamma(
alpha,beta) – the classic conjugate prior for a variance.
- InverseGaussian(mu, lam, *, name=None, keys=None)[source]
Inverse-Gaussian (Wald) with mean
muand shapelam– a positive, right-skewed law.
- Gumbel(loc, scale, *, name=None, keys=None)[source]
Gumbel (type-I extreme-value) with
locandscale– for maxima / extremes.
- SkewNormal(loc, scale, shape, *, name=None, keys=None)[source]
Skew-normal with
loc,scale, andshape(skewness;shape=0recovers the Normal).
- Skellam(mu1, mu2, *, name=None, keys=None)[source]
Skellam: the difference of two independent
Poisson(mu1)andPoisson(mu2)counts.
- LogSeries(p, *, name=None, keys=None)[source]
Logarithmic (log-series) distribution on
{1, 2, ...}with parameterpin(0, 1).
- VonMises(mu, kappa, *, name=None, keys=None)[source]
Von Mises (circular normal) on the angle
(-pi, pi]with meanmuand concentrationkappa.
- GEV(loc, scale, shape, *, name=None, keys=None)[source]
Generalized extreme value with
loc,scale,shape(the block-maxima limit law).
- Tweedie(mu, phi, *, name=None, keys=None)[source]
Tweedie compound Poisson-Gamma (power
p=1.5) with meanmuand dispersionphi.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).
- GeneralizedGaussian(mu, alpha, beta, *, name=None, keys=None)[source]
Generalized Gaussian (exponential power) with
mu, scalealpha, shapebeta.beta=2is the Normal andbeta=1is the Laplace, so it interpolates between light and heavy tails – a flexible symmetric error model.
- GeneralizedPareto(scale, shape, loc=0.0, *, name=None, keys=None)[source]
Generalized Pareto (
scale, tailshape, thresholdloc) – the peaks-over-threshold tail law.
- Nakagami(m, omega, *, name=None, keys=None)[source]
Nakagami-
mdistribution with shapemand spreadomega(signal-fading amplitudes).
- Rician(nu, sigma, *, name=None, keys=None)[source]
Rician (Rice) distribution with non-centrality
nuand scalesigma(signal-plus-noise magnitude).
- 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 – nodim=needed; passdim=Kto request the explicit simplex-parameter treatment forhow='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}).
- Weibull(shape, scale, *, name=None, keys=None)[source]
Weibull with shape (k) and scale (lambda).
- Laplace(loc, scale, *, name=None, keys=None)[source]
Laplace (double-exponential) with location and scale (b).
- Logistic(loc, scale, *, name=None, keys=None)[source]
Logistic with location and scale.
- Uniform(low, high, *, name=None, keys=None)[source]
Continuous uniform on [low, high].
- Rayleigh(sigma, *, name=None, keys=None)[source]
Rayleigh with scale sigma.
- Pareto(scale, shape, *, name=None, keys=None)[source]
Pareto with minimum value xm (scale) and tail index alpha (shape).
- Binomial(n, p, *, name=None, keys=None)[source]
Binomial with n trials and success probability p (n is fixed/known).
- 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 whereprioris eitherNone(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-dimvectors;MVN(dim).fit(X)recovers mean and covariance by EM.The mean vector and covariance matrix are also inferable parameters: pass
mean=free(adim-vector on the real line) ormean=ordered(increasing entries, for identifiability) and/orcov=free(a full SPD covariance via its Cholesky factor) and fit withhow='mcmc'|'ensemble'|'map'.
- 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 viahow='mcmc'|'ensemble'|'map'.
- 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 ids0..vocab_size-1. Topics are recovered as word distributions; alpha (the document-topic Dirichlet) is fixed by default.
- 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: passtransitions=free/transitions=Dirichlet(alpha)(each row a simplex) and/orinitial=free/initial=Dirichlet(alpha)and fit withhow='mcmc'|'ensemble'|'map'(typically with an ordered-emission constraint for identifiability).