mixle.stats.sets.integer_bernoulli_set module¶
Integer Bernoulli-set distributions over finite integer supports.
Let S = {0, 1, ..., N-1} be a finite integer support and let X be a random subset of S.
The Bernoulli-set distribution gives each integer an independent inclusion probability p_k.
The probability of an observed subset x is
p(x) = prod_{k in x} p_k * prod_{k not in x} (1 - p_k).
- 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]
Declare the generic table-kernel capabilities for integer-set likelihoods.
- classmethod compute_declaration()[source]
Return the structured compute declaration for Bernoulli-set statistics.
- 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:
DistributionEnumeratorEnumerate integer subsets in descending probability order.
- Parameters:
dist (IntegerBernoulliSetDistribution)
- class IntegerBernoulliSetSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSample finite integer subsets by independent Bernoulli inclusion draws.
- Parameters:
dist (IntegerBernoulliSetDistribution)
seed (int | None)
- class IntegerBernoulliSetAccumulator(num_vals, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate per-integer inclusion counts and total observation weight.
- update(x, weight, estimate)[source]
Update inclusion counts from one weighted subset.
- initialize(x, weight, rng)[source]
Initialize inclusion counts from one weighted subset.
- Parameters:
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Update inclusion counts from encoded subsets and observation weights.
- 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]
Initialize inclusion counts from encoded subsets.
- combine(suff_stat)[source]
Merge inclusion counts and total observation weight.
- value()[source]
Return inclusion counts and total observation weight.
- from_value(x)[source]
Restore inclusion counts and total observation weight.
- scale(c)[source]
Scale inclusion counts and total observation weight by a constant.
- Parameters:
c (float)
- Return type:
IntegerBernoulliSetAccumulator
- key_merge(stats_dict)[source]
Merge this accumulator’s state into
stats_dictunder its configured key.
- key_replace(stats_dict)[source]
Replace this accumulator’s state from keyed statistics when present.
- acc_to_encoder()[source]
Return the encoder compatible with Bernoulli-set sufficient statistics.
- Return type:
IntegerBernoulliSetDataEncoder
- class IntegerBernoulliSetAccumulatorFactory(num_vals, keys=None)[source]
Bases:
StatisticAccumulatorFactoryCreate accumulators for integer Bernoulli-set sufficient statistics.
- make()[source]
Create an empty integer Bernoulli-set accumulator.
- 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:
ParameterEstimatorEstimate per-integer Bernoulli inclusion probabilities from aggregate counts.
- Parameters:
- accumulator_factory()[source]
Return a factory for integer Bernoulli-set sufficient-statistic accumulators.
- Return type:
IntegerBernoulliSetAccumulatorFactory
- class IntegerBernoulliSetDataEncoder[source]
Bases:
DataSequenceEncoderData encoder for 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.