mixle.stats.univariate.continuous.exponential module¶
Create, estimate, and sample from an exponential distribution with scale beta.
Defines the ExponentialDistribution, ExponentialSampler, ExponentialAccumulatorFactory,ExponentialAccumulator, ExponentialEstimator, and the ExponentialDataEncoder classes for use with mixle.
- Data type: (float): The ExponentialDistribution with scale beta > 0.0, has log-density
log(f(x;beta)) = -log(beta) - x/beta, for x >= 0, else -np.inf.
Reference: Johnson, Kotz & Balakrishnan, Continuous Univariate Distributions (2nd ed., Wiley, 1994/95).
- class ExponentialDistribution(beta, name=None, prior=None)[source]
Bases:
SequenceEncodableProbabilityDistributionExponential distribution on non-negative real values with scale
beta.- classmethod compute_capabilities()[source]
- classmethod compute_declaration()[source]
- static exp_family_sufficient_statistics(x, engine)[source]
Return Exponential sufficient statistics for generated scoring.
- static exp_family_legacy_sufficient_statistics(x, params, engine)[source]
Return per-row Exponential sufficient statistics in accumulator order.
- static exp_family_natural_parameters(params, engine)[source]
Return Exponential natural parameters for generated scoring.
- static exp_family_log_partition(params, engine)[source]
Return Exponential log partition for generated scoring.
- static exp_family_base_measure(x, engine)[source]
Return Exponential support base measure for generated scoring.
- set_prior(prior)[source]
Attach a parameter prior and precompute the conjugate Gamma expectations.
The exponential rate is
1/beta; with a Gamma(k, theta) prior on that rate this caches the variational expected natural parameters so thatexpected_log_density(x) = e1*x - eawhere the natural parameter iseta = -rate,E[eta] = -k*thetaandE[-log(-eta)] = psi(k) + ln theta(mapping the prior’s(k, theta)to the bstats[a, b] = [k, 1/theta]form). 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 | rate)] under the Gamma 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 exponential distribution with scale beta.
See log_density() for details.
- log_density(x)[source]
Evaluate the log-density of exponential distribution with scale beta.
log(f(x;beta)) = -log(beta) - x/beta, for x >= 0, else -np.inf.
- seq_log_density(x)[source]
Vectorized evaluation of log-density at sequence encoded input x.
Vectorized call to log-density on each observation value x.
- Parameters:
x (np.ndarray) – Numpy array of floats.
- Returns:
Numpy array of log-density (float) of len(x).
- Return type:
- static backend_log_density_from_params(x, beta, engine)[source]
Engine-neutral exponential 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 Exponential parameters for a homogeneous mixture kernel.
- classmethod backend_stacked_log_density(x, params, engine)[source]
Return an
(n, k)matrix of Exponential log densities.
- classmethod backend_stacked_sufficient_statistics(x, weights, params, engine)[source]
Return stacked Exponential sufficient statistics using engine-resident arrays.
- cdf(x)[source]
Cumulative distribution function
P(X <= x)(exact). The continuous ‘index of’ a value.
- quantile(q)[source]
Inverse CDF
F^{-1}(q): the value at cumulative-probability indexq(continuous unranking).
- to_fisher(**kwargs)[source]
Return the Exponential’s count-family Fisher view.
- sampler(seed=None)[source]
Create an ExponentialSampler object with scale beta.
- Parameters:
seed (Optional[int]) – Used to set seed in random sampler.
- Returns:
ExponentialSampler object.
- Return type:
ExponentialSampler
- estimator(pseudo_count=None)[source]
Create ExponentialEstimator with beta passed as suff_stat.
- Parameters:
pseudo_count (Optional[float]) – Used to inflate sufficient statistics.
- Returns:
ExponentialEstimator.
- Return type:
ExponentialEstimator
- dist_to_encoder()[source]
Returns an ExponentialDataEncoder object.
- Return type:
ExponentialDataEncoder
- class ExponentialSampler(dist, seed=None)[source]
Bases:
DistributionSampler- Parameters:
dist (ExponentialDistribution)
seed (int | None)
- sample(size=None)[source]
Draw ‘size’ iid samples from ExponentialSampler object.
- class ExponentialAccumulator(keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulator- Parameters:
keys (str | None)
- update(x, weight, estimate)[source]
Update sufficient statistics for ExponentialAccumulator with one weighted observation.
- seq_update(x, weights, estimate)[source]
Vectorized update of sufficient statistics from encoded sequence x.
sum increased by sum of weighted observations. count increased by sum of weights.
- Parameters:
x (ndarray) – Numpy array of positvie floats.
weights (ndarray) – Numpy array of positive floats.
estimate (Optional['ExponentialDistribution']) – Kept for consistency with SequenceEncodableStatisticAccumulator.
- Returns:
None.
- Return type:
None
- initialize(x, weight, rng)[source]
Initialize sufficient statistics of ExponentialAccumulator with weighted observation.
Note: Just calls update.
- seq_initialize(x, weights, rng)[source]
Vectorized initialization of ExponentialAccumulator sufficient statistics with weighted observations.
Note: Just calls seq_update().
- Parameters:
x (ndarray) – Numpy array of positive floats.
weights (ndarray) – Numpy array of positive floats.
rng (Optional[RandomState]) – Kept for consistency with SequenceEncodableStatisticAccumulator.
- Returns:
None.
- Return type:
None
- combine(suff_stat)[source]
Aggregates sufficient statistics with ExponentialAccumulator member sufficient statistics.
- value()[source]
Returns Tuple[float, float] containing sufficient statistics (count and sum) of ExponentialAccumulator.
- from_value(x)[source]
Sets sufficient statistics (count and sum) of ExponentialAccumulator to x.
- key_merge(stats_dict)[source]
Merges ExponentialAccumulator sufficient statistics with sufficient statistics contained in suff_stat dict that share the same key.
- Parameters:
stats_dict (Dict[str, Any]) – Dict containing ‘key’ string for ExponentialAccumulator objects that represent the same distribution.
- Returns:
None.
- Return type:
None
- key_replace(stats_dict)[source]
- Set the sufficient statistics of ExponentialAccumulator to stats_key sufficient statistics if key is in
stats_dict.
- Parameters:
stats_dict (Dict[str, Any]) – Map key to sufficient statistics.
- Returns:
None.
- Return type:
None
- acc_to_encoder()[source]
Returns an ExponentialDataEncoder object.
- Return type:
ExponentialDataEncoder
- class ExponentialAccumulatorFactory(keys=None)[source]
Bases:
StatisticAccumulatorFactory- Parameters:
keys (str | None)
- make()[source]
Create ExponentialAccumulator with keys passed.
- Return type:
ExponentialAccumulator
- class ExponentialEstimator(pseudo_count=None, suff_stat=None, name=None, keys=None, prior=None)[source]
Bases:
ParameterEstimator- Parameters:
- accumulator_factory()[source]
Create ExponentialAccumulatorFactory object with keys passed.
- Return type:
ExponentialAccumulatorFactory
- model_log_density(model)[source]
Log-density of the model’s rate (1/beta) under the Gamma prior (ELBO global term).
- Parameters:
model (ExponentialDistribution)
- Return type:
- estimate(nobs, suff_stat)[source]
Estimate ExponentialDistribution from suff_stat arg.
Estimate ExponentialDistribution from sufficient statistic tuple suff_stat, counting a float value for count and sum. If pseudo_count is set, this is used to re-weight the member value “suff_stat”, which is the scale of ExponentialEstimator object.
- class ExponentialDataEncoder[source]
Bases:
DataSequenceEncoderExponentialDataEncoder object for encoding sequences of iid exponential observations with data type float.
- seq_encode(x)[source]
Encode sequence of iid exponential observations.
Data type must be a float. Data must also be non-negative real-valued numbers.