mixle.stats.univariate.discrete.integer_categorical module¶
Integer-categorical distributions over consecutive bounded supports.
The observation type is int. A distribution is parameterized by min_val
and a probability vector p_vec whose entries correspond to values
min_val, min_val + 1, ..., min_val + len(p_vec) - 1. Values outside that
range have zero probability.
- class IntegerCategoricalFisherView(dist)[source]
Bases:
CategoricalFisherViewFisher view for bounded integer-categorical one-hot statistics.
- Parameters:
dist (Any)
- class IntegerCategoricalDistribution(min_val, p_vec=MISSING, name=None, prob_vec=MISSING, prior=None)[source]
Bases:
SequenceEncodableProbabilityDistributionCategorical distribution over a bounded integer range.
- Parameters:
- classmethod compute_capabilities()[source]
Return compute-backend metadata for integer-categorical scoring.
- classmethod compute_declaration()[source]
Return the symbolic declaration for bounded integer-categorical probabilities.
- static exp_family_sufficient_statistics(x, engine)[source]
Return raw values; category-aware one-hot statistics come from
..._from_params.
- static exp_family_sufficient_statistics_from_params(x, params, engine)[source]
Return the one-hot category indicator
T(x)of shape(n, K)(zeros off support).
- static exp_family_natural_parameters(params, engine)[source]
Return the natural parameter
eta = log(p_vec)(one entry per category).
- static exp_family_log_partition(params, engine)[source]
Return the log partition
A = 0(normalization is carried byeta = log p).
- static exp_family_base_measure_from_params(x, params, engine)[source]
Return
log h(x) = 0on the support[min_val, min_val+K)and-infoutside it.
- get_parameters()[source]
Return the probability vector p_vec (lets it be scored by a Dirichlet conjugate prior).
- Return type:
- get_prior()[source]
Return the conjugate parameter prior over the probability vector (or None).
- Return type:
SequenceEncodableProbabilityDistribution | None
- set_prior(prior)[source]
Attach a parameter prior and precompute conjugate-prior expectations.
With a Dirichlet(alpha) (or SymmetricDirichlet(alpha)) prior over the probability vector this caches the variational expected log-probabilities E[log p_k] = digamma(alpha_k) - digamma(sum_k alpha_k) so that
expected_log_density(x) = E[log p_{x - min_val}] - log(1 + default_value). Any other prior (includingNone) leaves the distribution a plain point model.- Parameters:
prior (SequenceEncodableProbabilityDistribution | None)
- Return type:
None
- expected_log_density(x)[source]
Variational expectation E_q[log p(x)] under the (symmetric) Dirichlet prior.
Falls back to the plug-in
log_density(x)when no conjugate prior is attached.
- seq_expected_log_density(x)[source]
Vectorized
expected_log_densityover sequence-encoded observations.
- density(x)[source]
Evaluate the density of the integer categorical at observation x.
p_mat(x_mat=x) = p_vec[x] if x in support [min_val, max_val], else 0.0.
- log_density(x)[source]
Evaluate the log-density of the integer categorical at observation x.
log_p(x_mat=x) = log_p_vec[x] if x in support [min_val, max_val], else -np.inf.
- seq_log_density(x)[source]
Vectorized evaluation of IntegerCategorical log_density() for sequence encoded iid observations x.
- static backend_log_density_from_params(x, min_val, log_p_vec, engine)[source]
Engine-neutral integer-categorical log-density from explicit parameters.
- backend_seq_log_density(x, engine)[source]
Engine-neutral vectorized log-density for encoded data.
- classmethod backend_stacked_params(dists, engine)[source]
Return stacked integer-categorical parameters for a homogeneous mixture kernel.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of integer-categorical log densities.
- classmethod backend_stacked_sufficient_statistics(x, weights, params, engine)[source]
Return component-stacked legacy
(min_val, count_vec)statistics.
- to_fisher(**kwargs)[source]
Return the integer-categorical one-hot Fisher view.
- sampler(seed=None)[source]
Return a sampler for iid draws from this distribution.
- Parameters:
seed (int | None) – Optional random seed.
- Return type:
IntegerCategoricalSampler
- estimator(pseudo_count=None)[source]
Return an estimator initialized from this distribution.
When
pseudo_countis provided, the distribution’s probabilities are used as prior sufficient statistics during estimation.- Parameters:
pseudo_count (float | None) – Weight assigned to the distribution’s current probability vector during estimation.
- Return type:
IntegerCategoricalEstimator
- dist_to_encoder()[source]
Return the encoder for iid integer categorical observations.
- Return type:
IntegerCategoricalDataEncoder
- enumerator()[source]
Return IntegerCategoricalEnumerator iterating the support in descending probability order.
- Return type:
IntegerCategoricalEnumerator
- quantized_index(max_bits, bin_width_bits=1.0)[source]
Build a bounded bit-quantized index directly from the finite integer support.
- class IntegerCategoricalEnumerator(dist)[source]
Bases:
DistributionEnumeratorEnumerator over bounded integer support in descending probability order.
- Parameters:
dist (IntegerCategoricalDistribution)
- class IntegerCategoricalSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSampler for bounded integer-categorical values.
- Parameters:
dist (IntegerCategoricalDistribution)
seed (int | None)
- class IntegerCategoricalAccumulator(min_val=None, max_val=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulator for weighted counts over a bounded integer support.
- update(x, weight, estimate)[source]
Update sufficient statistics with one weighted observation.
If the observed value falls outside the current support, the count vector is expanded and existing counts are realigned.
- initialize(x, weight, rng)[source]
Initialize sufficient statistics with one weighted observation.
- Parameters:
x (int) – Integer observation.
weight (float) – Observation weight.
rng (RandomState) – Accepted for accumulator API consistency.
- Returns:
None.
- Return type:
None
- seq_initialize(x, weights, rng)[source]
Vectorized initialization of IntegerCategoricalAccumulator sufficient statistics with weighted observations.
This delegates to
seq_update().- Parameters:
x (np.ndarray[int]) – Sequence encoded iid observations of integer categorical distribution.
weights (ndarray) – Numpy array of positive floats.
rng (Optional[RandomState]) – Kept for consistency with SequenceEncodableStatisticAccumulator.
- Returns:
None.
- Return type:
None
- seq_update(x, weights, estimate)[source]
- Vectorized update of IntegerCategoricalAccumulator sufficient statistics with sequence encoded iid
observations x.
Note: Determines the range (support) of integer categorical from the sequence encoded data.
- Parameters:
x (np.ndarray[int]) – Sequence encoded iid observations of integer categorical distribution.
weights (ndarray) – Numpy array of positive floats.
estimate (Optional[IntegerCategoricalDistribution]) – Previous estimate of IntegerCategoricalDistribution.
- Returns:
None.
- 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]
Merge another
(min_val, count_vec)sufficient statistic.Supports are aligned before counts are added, so accumulators built on different observed ranges can be combined safely.
- from_value(x)[source]
Replace accumulator state from a
(min_val, count_vec)statistic.
- scale(c)[source]
Scale count vector while preserving integer support metadata.
- Parameters:
c (float)
- Return type:
IntegerCategoricalAccumulator
- key_merge(stats_dict)[source]
Aggregate member sufficient statistics with sufficient statistics of objects with matching keys.
- Parameters:
stats_dict (Dict[str, Any]) – Dict mapping keys to corresponding sufficient stats.
- Returns:
None.
- Return type:
None
- key_replace(stats_dict)[source]
Set member sufficient statistics to suff stats with matching keys.
- Parameters:
stats_dict (Dict[str, Any]) – Dict mapping keys to corresponding sufficient stats.
- Returns:
None.
- Return type:
None
- acc_to_encoder()[source]
Return the encoder associated with this accumulator.
- Return type:
IntegerCategoricalDataEncoder
- class IntegerCategoricalAccumulatorFactory(min_val=None, max_val=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for integer-categorical count accumulators.
- make()[source]
Return a fresh integer categorical accumulator with this factory’s bounds and keys.
- Return type:
IntegerCategoricalAccumulator
- class IntegerCategoricalEstimator(min_val=None, max_val=None, pseudo_count=None, suff_stat=None, name=None, keys=None, prior=None)[source]
Bases:
ParameterEstimatorEstimator for bounded integer-categorical probability vectors.
- Parameters:
- get_prior()[source]
Return the conjugate parameter prior over the probability vector (or None).
- Return type:
SequenceEncodableProbabilityDistribution | None
- set_prior(prior)[source]
Set the conjugate parameter prior over the probability vector.
- Parameters:
prior (SequenceEncodableProbabilityDistribution | None)
- Return type:
None
- model_log_density(model)[source]
Log-density of the model probability vector under the (symmetric) Dirichlet prior.
- Parameters:
model (IntegerCategoricalDistribution)
- Return type:
- accumulator_factory()[source]
Return an accumulator factory configured from this estimator’s support and keys.
Note: If min_val and max_val are BOTH not None, these values are passed to IntegerCategoricalAccumulatorFactory. Else, they are obtained from member variable suff_stat. One of these conditions must be satisfied.
Returns:
- Return type:
IntegerCategoricalAccumulatorFactory
- estimate(nobs, suff_stat)[source]
Estimate an integer-categorical distribution from weighted counts.
nobsis accepted for estimator API consistency but is not used.suff_statis(min_val, count_vec). Whenpseudo_countand a prior statistic are present, the estimate combines observed counts with the weighted prior probability vector.
- class IntegerCategoricalDataEncoder[source]
Bases:
DataSequenceEncoderData encoder for iid integer-categorical observations.