mixle.stats.univariate.continuous.beta module

Beta distributions over values in the unit interval.

Reference: Johnson, Kotz & Balakrishnan, Continuous Univariate Distributions (2nd ed., Wiley, 1994/95).

class BetaFisherView(dist)[source]

Bases: FixedFisherView

Fisher view for Beta sufficient statistics.

Parameters:

dist (Any)

class BetaDistribution(a, b, name=None, keys=None)[source]

Bases: SequenceEncodableProbabilityDistribution

Beta distribution with positive shape parameters a and b.

Parameters:
classmethod compute_capabilities()[source]

Describe backend support for generated Beta kernels.

classmethod compute_declaration()[source]

Return the structured compute declaration for Beta distributions.

static exp_family_sufficient_statistics(x, engine)[source]

Return Beta sufficient statistics for generated scoring.

Scoring needs only log_x and log1m_x (the two natural-parameter partners). The encoder emits the full (log_x, log1m_x, x, x**2) tuple for the M-step, while the symbolic generator supplies just the two scoring symbols from backend_log_density_from_params; indexing the leading two works for both arities.

Parameters:
Return type:

tuple[Any, …]

static exp_family_legacy_sufficient_statistics(x, params, engine)[source]

Return per-row Beta sufficient statistics in accumulator order.

Parameters:
Return type:

tuple[Any, …]

static exp_family_natural_parameters(params, engine)[source]

Return Beta natural parameters for generated scoring.

Parameters:
Return type:

tuple[Any, …]

static exp_family_log_partition(params, engine)[source]

Return Beta log partition for generated scoring.

Parameters:
Return type:

Any

get_parameters()[source]

Return the (a, b) shape pair.

Lets a BetaDistribution serve as a conjugate prior (on a Bernoulli/Geometric/Binomial success probability) under the unified Bayesian estimation protocol.

Return type:

tuple[float, float]

density(x)[source]

Return the probability density or mass at a single observation.

Parameters:

x (float)

Return type:

float

log_density(x)[source]

Return the log-density or log-mass at a single observation.

Parameters:

x (float)

Return type:

float

seq_log_density(x)[source]

Return vectorized log-density values for sequence-encoded observations.

Parameters:

x (tuple[ndarray, ndarray, ndarray, ndarray])

Return type:

ndarray

static backend_log_density_from_params(log_x, log1m_x, a, b, engine)[source]

Engine-neutral Beta log-density from encoded logs and parameters.

Parameters:
Return type:

Any

backend_seq_log_density(x, engine)[source]

Engine-neutral vectorized log-density for encoded data.

Parameters:
Return type:

Any

classmethod backend_stacked_params(dists, engine)[source]

Return stacked Beta parameters for a homogeneous mixture kernel.

Parameters:
Return type:

dict[str, Any]

classmethod backend_stacked_log_density(x, params, engine)[source]

Return an (n, k) matrix of Beta log densities.

Parameters:
Return type:

Any

cdf(x)[source]

Cumulative distribution function P(X <= x) (exact). The continuous ‘index of’ a value.

Parameters:

x (float)

Return type:

float

quantile(q)[source]

Inverse CDF F^{-1}(q): the value at cumulative-probability index q (continuous unranking).

Parameters:

q (float)

Return type:

float

to_fisher(**kwargs)[source]

Return this distribution’s own Fisher view.

mean()[source]

Mean E[X] of the distribution.

Return type:

float

variance()[source]

Variance Var[X] of the distribution.

Return type:

float

entropy()[source]

Differential entropy ln B(a,b) - (a-1)psi(a) - (b-1)psi(b) + (a+b-2)psi(a+b).

Return type:

float

mode()[source]

Mode (a-1)/(a+b-2) for a,b>1; boundary otherwise.

Return type:

float

sampler(seed=None)[source]

Return a sampler for drawing observations from this distribution.

Parameters:

seed (int | None)

Return type:

BetaSampler

estimator(pseudo_count=None)[source]

Return an estimator for fitting this distribution from data.

Parameters:

pseudo_count (float | None)

Return type:

BetaEstimator

dist_to_encoder()[source]

Return the data encoder used by this distribution for vectorized methods.

Return type:

BetaDataEncoder

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

Bases: DistributionSampler

Draw iid beta observations.

Parameters:
  • dist (BetaDistribution)

  • seed (int | None)

sample(size=None)[source]

Draw one sample or an array of iid samples.

Parameters:

size (int | None)

Return type:

float | ndarray

class BetaAccumulator(name=None, keys=None)[source]

Bases: SequenceEncodableStatisticAccumulator

Accumulate sufficient statistics for beta estimation.

Parameters:
  • name (str | None)

  • keys (str | None)

update(x, weight, estimate)[source]

Accumulate weighted statistics for one observation in (0, 1).

Parameters:
  • x (float)

  • weight (float)

  • estimate (BetaDistribution | None)

Return type:

None

initialize(x, weight, rng)[source]

Initialize statistics from one observation.

Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]

Accumulate weighted statistics from encoded observations.

Parameters:
Return type:

None

seq_initialize(x, weights, rng)[source]

Initialize statistics from encoded observations.

Parameters:
Return type:

None

combine(suff_stat)[source]

Merge another Beta sufficient-statistic tuple.

Parameters:

suff_stat (tuple[float, float, float, float, float])

Return type:

BetaAccumulator

value()[source]

Return the accumulated Beta sufficient statistics.

Return type:

tuple[float, float, float, float, float]

from_value(x)[source]

Replace accumulator contents from a sufficient-statistic tuple.

Parameters:

x (tuple[float, float, float, float, float])

Return type:

BetaAccumulator

key_merge(stats_dict)[source]

Merge keyed statistics into stats_dict when keys are configured.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator from keyed statistics when available.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

acc_to_encoder()[source]

Return the encoder used by this accumulator.

Return type:

BetaDataEncoder

class BetaAccumulatorFactory(name=None, keys=None)[source]

Bases: StatisticAccumulatorFactory

Factory for BetaAccumulator.

Parameters:
  • name (str | None)

  • keys (str | None)

make()[source]

Create a fresh Beta accumulator.

Return type:

BetaAccumulator

class BetaEstimator(pseudo_count=None, suff_stat=None, delta=1.0e-8, name=None, keys=None)[source]

Bases: ParameterEstimator

Estimate beta shape parameters from weighted log-moment statistics.

Parameters:
accumulator_factory()[source]

Return an accumulator factory for Beta sufficient statistics.

Return type:

BetaAccumulatorFactory

estimate(nobs, suff_stat)[source]

Estimate Beta shape parameters from weighted sufficient statistics.

Parameters:
Return type:

BetaDistribution

class BetaDataEncoder[source]

Bases: DataSequenceEncoder

Encode beta observations with log x and log(1-x) columns.

seq_encode(x)[source]

Encode observations as log and moment arrays for vectorized updates.

Parameters:

x (Sequence[float])

Return type:

tuple[ndarray, ndarray, ndarray, ndarray]