mixle.stats.compute.sampling_api module¶
A single sample() entry point that draws from any samplable mixle object.
sample(model, size) dispatches on the kind of model so distributions, conjugate posteriors,
relations, field posteriors and latent posteriors all read the same way:
mixle.stats.sample(gauss, 100) # 100 iid observations
mixle.stats.sample(posterior, 50) # 50 parameter draws from a conjugate posterior
mixle.stats.sample(assignment, 10, temperature=2.0) # 10 Gibbs-weighted relation members
mixle.stats.sample(field_post, 100) # 100 joint field draws (dict per node)
mixle.stats.sample(q_latent, 5) # 5 latent-variable draws
A shared rng (a numpy.random.RandomState) makes a whole pipeline reproducible: it is threaded
into the relation / field / latent draws directly, and for a distribution / conjugate posterior the
per-call stream is seeded from it, so one rng drives independent reproducible streams across many
sample() calls.
- sample(model, size=None, *, seed=None, rng=None, **kwargs)[source]
Draw sample(s) from any samplable mixle object.
- Parameters:
model (Any) – a distribution, conjugate posterior,
Relation,FieldPosteriororLatentPosterior.size (int | None) –
Nonereturns a single draw in the object’s natural type; an int returns a collection (an array for homogeneous leaves, a list / dict-of-arrays for structured draws).seed (int | None) – scalar seed for the draw (ignored if
rngis given).rng (RandomState | None) – a shared
RandomStatefor reproducible, composable streams; takes precedence overseed.**kwargs (Any) – forwarded to the underlying sampler – e.g.
temperature/k/uniformfor a relation,nodesfor a field posterior,batchedfor a distribution.
- Returns:
A single draw (
size=None) or a collection ofsizedraws.- Raises:
TypeError – if
modelis not a recognized samplable object.- Return type:
- register_sample_dispatch(fn)[source]
Register a
sample()handler for a type the core layer must not import. Returnsfn.