mixle.stats.sets.integer_bernoulli_set module¶
Create, estimate, and sample from a integer set Bernoulli distribution.
Defines the IntegerBernoulliSetDistribution, IntegerBernoulliSetSampler, IntegerBernoulliSetAccumulatorFactory, IntegerBernoulliSetAccumulator, IntegerBernoulliSetEstimator, and the IntegerBernoulliSetDataEncoder classes for use with mixle.
Let S = {0,1,2,3…,N-1} be a set if integers. Let x_mat be a random subset of S. The Bernoulli set distribution models random subset of S as
p_k = p_mat(k is in x_mat) , k = 0,2,…,N-1.
- The density for an observed subset of S, x=(x_1,x_2,..,x_m), for m < N) is given by
p_mat(x) = sum_{k=0}^{K-1}( p_k*(k in x) + (1-p_k)*(k not in x)).
- class IntegerBernoulliSetDistribution(log_pvec, log_nvec=None, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionDistribution over finite sets of integer-valued Bernoulli outcomes.
- Parameters:
- classmethod compute_capabilities()[source]
- classmethod compute_declaration()[source]
- density(x)[source]
Return the probability density or mass at a single observation.
- log_density(x)[source]
Return the log-density or log-mass at a single observation.
- seq_log_density(x)[source]
Return vectorized log-density values for sequence-encoded observations.
- backend_seq_log_density(x, engine)[source]
Engine-neutral log-density for encoded integer Bernoulli-set observations.
- classmethod backend_stacked_params(dists, engine)[source]
Return stacked integer Bernoulli-set parameters for shared support size.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of integer Bernoulli-set log densities.
- classmethod backend_stacked_sufficient_statistics(x, weights, params, engine)[source]
Return component-stacked legacy
(inclusion_counts, total_weight)statistics.
- sampler(seed=None)[source]
Return a sampler for drawing observations from this distribution.
- Parameters:
seed (int | None)
- Return type:
IntegerBernoulliSetSampler
- estimator(pseudo_count=None)[source]
Return an estimator for fitting this distribution from data.
- Parameters:
pseudo_count (float | None)
- Return type:
IntegerBernoulliSetEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
IntegerBernoulliSetDataEncoder
- enumerator()[source]
Returns IntegerBernoulliSetEnumerator iterating subsets in descending probability order.
- Return type:
IntegerBernoulliSetEnumerator
- class IntegerBernoulliSetEnumerator(dist)[source]
Bases:
DistributionEnumerator- Parameters:
dist (IntegerBernoulliSetDistribution)
- class IntegerBernoulliSetSampler(dist, seed=None)[source]
Bases:
DistributionSampler- Parameters:
dist (IntegerBernoulliSetDistribution)
seed (int | None)
- sample(size=None)[source]
Draw observations.
Combinator samplers (mixture/sequence/…) accept
batched. Withbatched=True(the default) each child stream is drawn in one vectorized call instead of a per-draw Python loop – far faster. Because every child sampler owns an independentRandomState, batching consumes each stream in the same order as the loop, so the draws are identical to the legacy path.batched=Falseforces that legacy per-draw loop as a guaranteed- stable reference. Leaf samplers are already vectorized and ignore the flag.
- class IntegerBernoulliSetAccumulator(num_vals, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulator- update(x, weight, estimate)[source]
- initialize(x, weight, rng)[source]
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- seq_update_engine(x, weights, estimate, engine)[source]
Engine-resident accumulation of per-integer inclusion counts (numpy or torch).
The weighted integer histogram is reduced on the active engine; the fixed-size count vector is host bookkeeping. Matches seq_update.
- seq_initialize(x, weights, rng)[source]
- combine(suff_stat)[source]
- from_value(x)[source]
- scale(c)[source]
Scale linear sufficient statistics in-place by
c.The structural default is correct for ordinary weighted sums, nested tuples/lists/dicts, and numeric arrays. Families whose
value()payload includes non-linear metadata such as support bounds must override this method and leave that metadata unscaled.- Parameters:
c (float)
- Return type:
IntegerBernoulliSetAccumulator
- key_merge(stats_dict)[source]
Pool this accumulator’s statistics into
stats_dictunder its merge key.The structural default implements the common single-key pattern: store the accumulator under
self.keysthe first time the key is seen, elsecombineinto the one already there. Accumulators with several named keys (e.g. an HMM’s init/trans/state keys) or a non-accumulator stats payload override this. AkeysofNone(the default) is a no-op.
- key_replace(stats_dict)[source]
Replace this accumulator’s statistics from the pooled
stats_dictentry (see key_merge).
- acc_to_encoder()[source]
- Return type:
IntegerBernoulliSetDataEncoder
- class IntegerBernoulliSetAccumulatorFactory(num_vals, keys=None)[source]
Bases:
StatisticAccumulatorFactory- make()[source]
- Return type:
IntegerBernoulliSetAccumulator
- class IntegerBernoulliSetEstimator(num_vals=MISSING, min_prob=1.0e-128, pseudo_count=None, suff_stat=None, name=None, keys=None, num_values=MISSING)[source]
Bases:
ParameterEstimator- Parameters:
- accumulator_factory()[source]
- Return type:
IntegerBernoulliSetAccumulatorFactory
- class IntegerBernoulliSetDataEncoder[source]
Bases:
DataSequenceEncoderIntegerBernoulliSetDataEncoder object for encoding sequences of iid integer Bernoulli set observations.
- seq_encode(x)[source]
Encode sequences of iid observations for vectorized calculations.
- Returns ‘rv’:
rv[0] (int): Total number of observations. rv[1] (np.ndarray): Index for flattened values of observations. rv[2] (np.ndarray): Flattened numpy array of integer values.