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_stateorder.- Parameters:
- Returns:
A length-
sizelist of draws, in the order given bycomp_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: