mixle.inference.mcmc.conjugate module

Exact posterior sampling for conjugate mixle.stats leaves.

The sampler uses each supported distribution’s closed-form conjugate update to draw independent parameter samples, providing an analytic alternative to generic MCMC for Gaussian, count, and Bernoulli-family leaves.

class ConjugateUpdateReceipt(prior_source, prior_status, posterior_status, improper_prior=None, input_mutated=False)[source]

Bases: object

Prior provenance and propriety status for an analytic posterior update.

Parameters:
  • prior_source (str)

  • prior_status (str)

  • posterior_status (str)

  • improper_prior (dict[str, Any] | None)

  • input_mutated (bool)

as_dict()[source]

Return a plain durable receipt.

Return type:

dict[str, Any]

exception ImproperPosteriorError(receipt)[source]

Bases: ValueError

Raised when an explicitly improper prior does not yield a proper posterior.

Parameters:

receipt (ConjugateUpdateReceipt)

Return type:

None

sample_conjugate_posterior(dist, data, draws=1000, seed=None, return_distributions=False, improper_receipt=None)[source]

Draw exact posterior parameter samples for a conjugate mixle.stats leaf.

For mixle.stats distributions carrying a closed-form conjugate prior, the posterior over parameters is available analytically. This runs the distribution’s own conjugate estimator over data to obtain the posterior hyperparameters (read back via the fitted model’s get_prior()), then draws iid parameter samples from that posterior. This is an exact alternative to sample_parameter_posterior().

Supported leaves: Gaussian (NormalGamma posterior, samples (mu, sigma2)), Poisson (Gamma posterior, samples lam), Exponential (Gamma posterior over the rate, samples the scale beta), and Bernoulli, Binomial, and Geometric (Beta posterior, samples p). Binomial draws keep the prototype trial count and support shift fixed.

Parameters:
  • dist (Any) – A mixle.stats distribution; if it carries no conjugate prior, a weak proper family default is attached to an internal copy.

  • data (Any) – Observations for the family.

  • draws (int) – Number of iid posterior samples.

  • seed (int | None) – Seed for the RandomState.

  • return_distributions (bool) – Return rebuilt distributions instead of parameters.

  • improper_receipt (ImproperPriorReceipt | None) – Explicit acknowledgement for a supported zero-hyperparameter limiting prior. Without this receipt, improper priors are rejected. A still-improper posterior cannot be sampled and raises ImproperPosteriorError carrying its status receipt.

Returns:

MCMCResult with iid samples (all accepted, no autocorrelation).

Return type:

MCMCResult