mixle.stats.univariate.discrete.integer_uniform_spike module¶
- Evaluate, estimate, and sample from a uniform distribution over integers in range [min_val, max_val] with a spike
placed on the integer value k.
Defines the IntegerUniformSpikeDistribution, IntegerUniformSpikeSampler, IntegerUniformSpikeAccumulatorFactory, IntegerUniformSpikeAccumulator, IntegerUniformSpikeEstimator, and the IntegerUniformSpikeDataEncoder classes for use with mixle.
Data type: (int): The IntegerUniformSpikeDistribution with a range [min_val, max_val] = [a,b], and spike placed on integer value k with probability p, is given by
P(x_i = k) = p, P(x_i = x) = (1-p)/(b-a), x in [a,b] {k}, P(x_i = else) = 0.0.
- class IntegerUniformSpikeDistribution(k, num_vals, p, min_val=0, name=None)[source]
Bases:
SequenceEncodableProbabilityDistributionIntegerUniformSpikeDistribution object: uniform over an integer range with a spike of mass p at k.
- classmethod compute_capabilities()[source]
- classmethod compute_declaration()[source]
- density(x)[source]
Density of the integer uniform spike distribution at observation x.
See log_density() for details.
- log_density(x)[source]
Log-density of the integer uniform spike distribution at observation x.
Returns log(p) if x equals the spike value k, log((1-p)/(num_vals-1)) for any other integer in [min_val, max_val], and -inf outside the range.
- seq_log_density(x)[source]
Vectorized evaluation of log-density at sequence encoded input x.
- Parameters:
x (np.ndarray) – Numpy array of integer observations.
- Returns:
Numpy array of log-density (float) of len(x).
- Return type:
- backend_seq_log_density(x, engine)[source]
Engine-neutral log-density for encoded integer spike observations.
- classmethod backend_stacked_params(dists, engine)[source]
Return stacked integer-uniform-spike parameters for a shared support.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of integer-uniform-spike log densities.
- classmethod backend_stacked_sufficient_statistics(x, weights, params, engine)[source]
Return component-stacked legacy
(min_val, count_vec)statistics.
- sampler(seed=None)[source]
Create an IntegerUniformSpikeSampler from parameters of this distribution.
- Parameters:
seed (Optional[int]) – Used to set seed in random sampler.
- Returns:
IntegerUniformSpikeSampler object.
- Return type:
IntegerUniformSpikeSampler
- estimator(pseudo_count=None)[source]
Create an IntegerUniformSpikeEstimator for the current integer range.
- Parameters:
pseudo_count (Optional[float]) – Used to inflate sufficient statistics.
- Returns:
IntegerUniformSpikeEstimator object.
- Return type:
IntegerUniformSpikeEstimator
- dist_to_encoder()[source]
Returns an IntegerUniformSpikeDataEncoder for encoding sequences of iid integer observations.
- Return type:
IntegerUniformSpikeDataEncoder
- enumerator()[source]
Returns an IntegerUniformSpikeEnumerator iterating the support in descending probability order.
- Return type:
IntegerUniformSpikeEnumerator
- quantized_index(max_bits, bin_width_bits=1.0)[source]
Build a bounded bit-quantized index directly from the finite integer support.
- class IntegerUniformSpikeEnumerator(dist)[source]
Bases:
DistributionEnumeratorEnumerates the support [min_val, max_val] in descending probability order.
The spike value k is yielded first when p >= (1-p)/(num_vals-1), otherwise last; the remaining values share the same probability and are yielded in ascending integer order. Zero-probability values are skipped.
- Parameters:
dist (IntegerUniformSpikeDistribution)
- class IntegerUniformSpikeSampler(dist, seed=None)[source]
Bases:
DistributionSamplerIntegerUniformSpikeSampler object for sampling from an IntegerUniformSpikeDistribution.
- Parameters:
dist (IntegerUniformSpikeDistribution)
seed (int | None)
- dist
Distribution to sample from.
- Type:
IntegerUniformSpikeDistribution
- rng
Seeded RandomState for sampling.
- Type:
RandomState
- non_k
Integers of the support excluding the spike value k.
- Type:
np.ndarray
- class IntegerUniformSpikeAccumulator(min_val, max_val, keys=None, name=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorIntegerUniformSpikeAccumulator object for accumulating weighted integer counts over a growing range.
- min_val
Smallest integer observed (or configured) so far.
- Type:
Optional[int]
- max_val
Largest integer observed (or configured) so far.
- Type:
Optional[int]
- count_vec
Weighted counts for each integer in [min_val, max_val].
- Type:
Optional[np.ndarray]
- count
Total weighted observation count.
- Type:
- key
Key for merging sufficient statistics across accumulators.
- Type:
Optional[str]
- name
Name for object instance.
- Type:
Optional[str]
- update(x, weight, estimate)[source]
Add weight to the count for integer x, growing the count vector if x is out of range.
- initialize(x, weight, rng)[source]
Initialize the accumulator with observation x and weight (delegates to update).
- Parameters:
x (int)
weight (float)
rng (RandomState)
- Return type:
None
- seq_initialize(x, weights, rng)[source]
Vectorized initialization from encoded observations x (delegates to seq_update).
- seq_update(x, weights, estimate)[source]
Vectorized accumulation of weighted counts from encoded observations x.
- Parameters:
x (np.ndarray) – Sequence encoded integer observations.
weights (np.ndarray) – Weights on the observations.
estimate (Optional[IntegerUniformSpikeDistribution]) – Unused previous estimate.
- Return type:
None
- seq_update_engine(x, weights, estimate, engine)[source]
Engine-resident accumulation: the weighted value histogram is reduced on the active engine (numpy or torch); the dynamic support range is host bookkeeping. Matches seq_update.
- combine(suff_stat)[source]
Combine sufficient statistics (min_val, count_vec) with this accumulator, aligning ranges.
- Parameters:
suff_stat (Tuple[int, np.ndarray]) – Minimum value and count vector of another accumulator.
- Returns:
This IntegerUniformSpikeAccumulator.
- Return type:
IntegerUniformSpikeAccumulator
- value()[source]
Returns sufficient statistics as a tuple (min_val, count_vec).
- from_value(x)[source]
Set sufficient statistics from a (min_val, count_vec) tuple.
- Parameters:
x (Tuple[int, np.ndarray]) – Minimum value and count vector.
- Returns:
This IntegerUniformSpikeAccumulator.
- Return type:
IntegerUniformSpikeAccumulator
- scale(c)[source]
Scale linear counts while preserving the integer support offset.
- Parameters:
c (float)
- Return type:
IntegerUniformSpikeAccumulator
- key_merge(stats_dict)[source]
Merge this accumulator’s sufficient statistics into stats_dict under its key.
- key_replace(stats_dict)[source]
Replace this accumulator’s sufficient statistics from stats_dict under its key.
- acc_to_encoder()[source]
Returns an IntegerUniformSpikeDataEncoder for encoding sequences of iid integer observations.
- Return type:
IntegerUniformSpikeDataEncoder
- class IntegerUniformSpikeAccumulatorFactory(min_val=None, max_val=None, keys=None, name=None)[source]
Bases:
StatisticAccumulatorFactoryIntegerUniformSpikeAccumulatorFactory object for creating IntegerUniformSpikeAccumulator objects.
- Parameters:
- min_val
Smallest integer value in the range, if known.
- Type:
Optional[int]
- max_val
Largest integer value in the range, if known.
- Type:
Optional[int]
- keys
Key for merging sufficient statistics.
- Type:
Optional[str]
- name
Name for object instance.
- Type:
Optional[str]
- make()[source]
Returns a new IntegerUniformSpikeAccumulator object.
- Return type:
IntegerUniformSpikeAccumulator
- class IntegerUniformSpikeEstimator(min_val=None, max_val=None, pseudo_count=None, suff_stat=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorIntegerUniformSpikeEstimator object for estimating IntegerUniformSpikeDistribution objects from counts.
- Parameters:
- accumulator_factory()[source]
Returns an IntegerUniformSpikeAccumulatorFactory consistent with this estimator.
- Return type:
IntegerUniformSpikeAccumulatorFactory
- estimate(nobs, suff_stat)[source]
Estimate an IntegerUniformSpikeDistribution by maximizing the spike location and weight.
The spike location k is chosen to maximize the likelihood of the accumulated counts (with optional pseudo_count regularization from the estimator configuration).
- class IntegerUniformSpikeDataEncoder[source]
Bases:
DataSequenceEncoderIntegerUniformSpikeDataEncoder object for encoding sequences of iid integer observations.