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: SequenceEncodableProbabilityDistribution

Distribution 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.

Parameters:

x (Sequence[int] | ndarray)

Return type:

float

log_density(x)[source]

Return the log-density or log-mass at a single observation.

Parameters:

x (Sequence[int] | ndarray)

Return type:

float

seq_log_density(x)[source]

Return vectorized log-density values for sequence-encoded observations.

Parameters:

x (tuple[int, ndarray, ndarray])

Return type:

ndarray

backend_seq_log_density(x, engine)[source]

Engine-neutral log-density for encoded integer Bernoulli-set observations.

Parameters:
Return type:

Any

classmethod backend_stacked_params(dists, engine)[source]

Return stacked integer Bernoulli-set parameters for shared support size.

Parameters:
  • dists (Sequence[IntegerBernoulliSetDistribution])

  • engine (Any)

Return type:

dict[str, Any]

classmethod backend_stacked_log_density(x, params, engine)[source]

Return an (n, k) matrix of integer Bernoulli-set log densities.

Parameters:
Return type:

Any

classmethod backend_stacked_sufficient_statistics(x, weights, params, engine)[source]

Return component-stacked legacy (inclusion_counts, total_weight) statistics.

Parameters:
Return type:

tuple[Any, Any]

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

Enumerate integer subsets in descending probability order.

Parameters:

dist (IntegerBernoulliSetDistribution)

class IntegerBernoulliSetSampler(dist, seed=None)[source]

Bases: DistributionSampler

Sample finite integer subsets by independent Bernoulli inclusion draws.

Parameters:
  • dist (IntegerBernoulliSetDistribution)

  • seed (int | None)

sample(size=None)[source]

Draw one subset or size iid subsets.

Parameters:

size (int | None)

Return type:

list[Sequence[int]] | Sequence[int]

class IntegerBernoulliSetAccumulator(num_vals, keys=None)[source]

Bases: SequenceEncodableStatisticAccumulator

Accumulate per-integer inclusion counts and total observation weight.

Parameters:
  • num_vals (int)

  • keys (str | None)

update(x, weight, estimate)[source]

Update inclusion counts from one weighted subset.

Parameters:
Return type:

None

initialize(x, weight, rng)[source]

Initialize inclusion counts from one weighted subset.

Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]

Update inclusion counts from encoded subsets and observation weights.

Parameters:
Return type:

None

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.

Parameters:
Return type:

None

seq_initialize(x, weights, rng)[source]

Initialize inclusion counts from encoded subsets.

Parameters:
Return type:

None

combine(suff_stat)[source]

Merge inclusion counts and total observation weight.

Parameters:

suff_stat (tuple[ndarray, float])

Return type:

IntegerBernoulliSetAccumulator

value()[source]

Return inclusion counts and total observation weight.

Return type:

tuple[ndarray, float]

from_value(x)[source]

Restore inclusion counts and total observation weight.

Parameters:

x (tuple[ndarray, float])

Return type:

IntegerBernoulliSetAccumulator

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_dict under its configured key.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator’s state from keyed statistics when present.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

acc_to_encoder()[source]

Return the encoder compatible with Bernoulli-set sufficient statistics.

Return type:

IntegerBernoulliSetDataEncoder

class IntegerBernoulliSetAccumulatorFactory(num_vals, keys=None)[source]

Bases: StatisticAccumulatorFactory

Create accumulators for integer Bernoulli-set sufficient statistics.

Parameters:
  • num_vals (int)

  • keys (str | None)

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: ParameterEstimator

Estimate 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

estimate(nobs, suff_stat=None)[source]

Estimate an integer Bernoulli-set distribution from inclusion-count statistics.

Parameters:
Return type:

IntegerBernoulliSetDistribution

class IntegerBernoulliSetDataEncoder[source]

Bases: DataSequenceEncoder

Data 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.

Parameters:

x (Sequence[Sequence[int]]) – Sequence of integer set observations.

Returns:

See above for details.

Return type:

tuple[int, ndarray, ndarray]