mixle.stats.sets.integer_step_bernoulli_edit module

Integer step Bernoulli edit distributions over pairs of finite sets.

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 a sampler for this integer step Bernoulli edit distribution.

Parameters:

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

Returns:

Sampler bound to this distribution.

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:

Estimator configured with matching support size.

Return type:

IntegerStepBernoulliEditEstimator

dist_to_encoder()[source]

Return a data encoder for integer step Bernoulli edit observations.

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

Sampler for (previous set, next set) pairs from a stepwise integer Bernoulli-edit distribution.

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

Accumulator for removed, added, and kept counts from stepwise integer 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]

Return a data encoder built from the previous-set accumulator.

Return type:

IntegerStepBernoulliEditDataEncoder

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

Bases: IntegerBernoulliEditAccumulatorFactory

Factory for integer step Bernoulli edit accumulators.

Parameters:
  • num_vals (int)

  • init_factory (StatisticAccumulatorFactory | None)

  • keys (str | None)

make()[source]

Return a new integer step Bernoulli edit accumulator.

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

Estimate integer step Bernoulli edit distributions with a two-level edit-probability fit.

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]

Return an accumulator factory configured from this estimator.

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

Encode iid (previous set, next set) observations for vectorized scoring.

Identical to IntegerBernoulliEditDataEncoder; only the reported class name differs.

Parameters:

init_encoder (DataSequenceEncoder)