mixle.stats.compute._sampling moduleΒΆ

Shared sampling helpers for vectorizing per-draw sampler loops.

The recurring pattern across mixture-like models is: draw a length-size vector of component indices, then sample each chosen component. The naive [comp_samplers[i].sample() for i in comp_state] loop is slow; scatter_component_draws() instead samples each component once with its assigned count and scatters the results back into draw order. Because every mixle component sampler owns an independent RandomState and satisfies sample(n) == n sequential sample() calls, the scattered result is bit-identical to the per-draw loop, just far faster.

scatter_component_draws(comp_state, comp_samplers, size)[source]

Sample each component once (by its assigned count) and scatter into comp_state order.

Parameters:
  • comp_state (Any) – Length-size array of component indices (already drawn).

  • comp_samplers (list) – One sampler per component; each must own an independent RNG.

  • size (int) – Number of draws.

Returns:

A length-size list of draws, in the order given by comp_state. When every component returns ndarrays (leaf / multivariate components), the list is backed by one contiguous array so the trailing sample shape (e.g. D-vectors) is preserved.

Return type:

list[Any]