mixle.stats.sets.integer_step_bernoulli_edit module

Create, estimate, and sample from an integer step Bernoulli edit set distribution.

Defines the IntegerStepBernoulliEditDistribution, IntegerStepBernoulliEditSampler, IntegerStepBernoulliEditAccumulatorFactory, IntegerStepBernoulliEditAccumulator, IntegerStepBernoulliEditEstimator, and the IntegerStepBernoulliEditDataEncoder classes for use with mixle.

Data type: Tuple[Sequence[int], Sequence[int]]: An observation x = (x1, x2) is a pair of integer sets (prev set, next set), each a subset of S = {0,1,2,…N-1}.

The density has the same form as the integer Bernoulli edit set distribution (see mixle.stats.sets.integer_bernoulli_edit): each integer k independently transitions in or out of the set with probabilities p(k in x2 | k in x1), p(k in x2 | k not in x1), etc., and the previous set x1 follows an init distribution,

p(x1, x2) = P_init(x1) * prod_{k=0}^{N-1} p(k in/not-in x2 | k in/not-in x1).

The “step” variant differs only in estimation: after the per-element edit probabilities are computed, the estimator fits a two-level step function to the addition probabilities p(present | missing) and the removal probabilities p(missing | present), so that each element receives one of just two probability levels (a high level for the top-ranked elements and a low level for the rest), chosen to maximize the Bernoulli likelihood of the per-element estimates.

Every class here subclasses its non-step counterpart in mixle.stats.sets.integer_bernoulli_edit and overrides only what genuinely differs: the estimator’s step-fit, the constructor signatures (the step distribution/estimator do not carry the non-step keys plumbing), and the class-name strings used in __str__ and in the types returned by the distribution’s factory methods.

class IntegerStepBernoulliEditDistribution(log_edit_pmat, init_dist=None, name=None)[source]

Bases: IntegerBernoulliEditDistribution

Step Bernoulli edit set distribution: each integer independently transitions in/out between two sets.

Identical in form to IntegerBernoulliEditDistribution; only the estimator (a two-level step fit) differs. The step distribution does not carry the non-step keys plumbing.

Parameters:
sampler(seed=None)[source]

Create an IntegerStepBernoulliEditSampler object from this distribution.

Parameters:

seed (Optional[int]) – Used to set seed in random sampler.

Returns:

IntegerStepBernoulliEditSampler object.

Return type:

IntegerStepBernoulliEditSampler

estimator(pseudo_count=None)[source]

Create an IntegerStepBernoulliEditEstimator with matching num_vals.

Parameters:

pseudo_count (Optional[float]) – Used to re-weight sufficient statistics in estimation.

Returns:

IntegerStepBernoulliEditEstimator object.

Return type:

IntegerStepBernoulliEditEstimator

dist_to_encoder()[source]

Returns an IntegerStepBernoulliEditDataEncoder object for encoding sequences of data.

Return type:

IntegerStepBernoulliEditDataEncoder

enumerator()[source]

Returns IntegerStepBernoulliEditEnumerator iterating set-pairs in descending probability order.

Return type:

IntegerStepBernoulliEditEnumerator

class IntegerStepBernoulliEditEnumerator(dist)[source]

Bases: IntegerBernoulliEditEnumerator

Enumerates finite previous/next integer-set pairs for the step edit-set distribution.

Parameters:

dist (IntegerBernoulliEditDistribution)

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

Bases: IntegerBernoulliEditSampler

IntegerStepBernoulliEditSampler object for drawing (prev set, next set) pairs from an IntegerStepBernoulliEditDistribution instance.

Identical to IntegerBernoulliEditSampler; only the bound distribution type differs.

Parameters:
  • dist (IntegerBernoulliEditDistribution)

  • seed (int | None)

class IntegerStepBernoulliEditAccumulator(num_vals, init_acc=NullAccumulator(), keys=None)[source]

Bases: IntegerBernoulliEditAccumulator

IntegerStepBernoulliEditAccumulator object for accumulating removed/added/kept counts from observed set pairs.

Identical to IntegerBernoulliEditAccumulator; only the encoder type returned by acc_to_encoder() differs.

Parameters:
  • num_vals (int)

  • init_acc (SequenceEncodableStatisticAccumulator | None)

  • keys (str | None)

acc_to_encoder()[source]

Returns an IntegerStepBernoulliEditDataEncoder object for encoding sequences of data.

Return type:

IntegerStepBernoulliEditDataEncoder

class IntegerStepBernoulliEditAccumulatorFactory(num_vals, init_factory=None, keys=None)[source]

Bases: IntegerBernoulliEditAccumulatorFactory

IntegerStepBernoulliEditAccumulatorFactory object for creating IntegerStepBernoulliEditAccumulator objects.

Parameters:
  • num_vals (int)

  • init_factory (StatisticAccumulatorFactory | None)

  • keys (str | None)

make()[source]

Returns a new IntegerStepBernoulliEditAccumulator object.

Return type:

IntegerStepBernoulliEditAccumulator

class IntegerStepBernoulliEditEstimator(num_vals=MISSING, init_estimator=NullEstimator(), min_prob=1.0e-128, pseudo_count=None, suff_stat=None, name=None, keys=None, num_values=MISSING)[source]

Bases: IntegerBernoulliEditEstimator

IntegerStepBernoulliEditEstimator object for estimating an IntegerStepBernoulliEditDistribution from aggregated sufficient statistics, with a two-level step fit to the edit probabilities.

Parameters:
  • num_vals (int)

  • init_estimator (ParameterEstimator | None)

  • min_prob (float)

  • pseudo_count (float | None)

  • suff_stat (ndarray | None)

  • name (str | None)

  • keys (str | None)

  • num_values (int)

accumulator_factory()[source]

Returns an IntegerStepBernoulliEditAccumulatorFactory for creating accumulator objects.

Return type:

IntegerStepBernoulliEditAccumulatorFactory

estimate(nobs, suff_stat)[source]

Estimate an IntegerStepBernoulliEditDistribution from aggregated sufficient statistics.

Per-element edit probabilities are estimated as in the non-step edit estimator, then the addition and removal probabilities are each replaced by a two-level step-function fit.

Parameters:
  • nobs (Optional[float]) – Unused (kept for protocol consistency).

  • suff_stat (Tuple[np.ndarray, float, Optional[SS1]]) – Edit counts, total weight, and init suff stats.

Returns:

IntegerStepBernoulliEditDistribution object.

Return type:

IntegerStepBernoulliEditDistribution

class IntegerStepBernoulliEditDataEncoder(init_encoder)[source]

Bases: IntegerBernoulliEditDataEncoder

IntegerStepBernoulliEditDataEncoder object for encoding sequences of iid (prev set, next set) observations.

Identical to IntegerBernoulliEditDataEncoder; only the reported class name differs.

Parameters:

init_encoder (DataSequenceEncoder)