fcaz.stats.Mixture#
- class fcaz.stats.Mixture(dists: Sequence[FrozenDistribution], weights: float | floating[Any] | NDArray[number[Any]] | Sequence[float | floating[Any] | NDArray[number[Any]]])[source]#
Finite mixture of frozen distributions (i.e., those with parameters already fixed).
- Parameters:
dists (sequence of frozen distributions) – Component distributions, e.g.
scipy.stats.expon(scale=8).weights (array_like) – Non-negative mixing weights, one per component, summing to 1.
- Raises:
ValueError – If
distsandweightsdiffer in length, or the weights are negative or do not sum to 1.
Notes
The survival function is \(S(x) = \sum_i w_i S_i(x)\);
pdf,cdfandmeanmix in the same way.hfandchfare derived from the mixedpdfandsf.Examples
A 40% exponential, 60% inverse exponential mixture:
>>> from scipy import stats >>> from fcaz.stats import invexpon, Mixture >>> X = Mixture([stats.expon(scale=8), invexpon(scale=3)], [0.4, 0.6]) >>> round(float(X.chf(2.5)), 4) 0.3398
- __init__(dists: Sequence[FrozenDistribution], weights: float | floating[Any] | NDArray[number[Any]] | Sequence[float | floating[Any] | NDArray[number[Any]]]) None[source]#
Methods
__init__(dists, weights)cdf(x)Cumulative distribution function.
chf(x)Cumulative hazard function, -log sf.
hf(x)Hazard function, pdf / sf.
logsf(x)Log of the survival function.
mean()Mean of the mixture, the weighted mean of the component means.
pdf(x)Probability density function.
ppf(q)Percent point function (inverse cdf), solved numerically.
rvs([size, random_state])Random variates;
sizeandrandom_stateas in scipy.sf(x)Survival function, 1 - cdf.