MixtureModel#
- class MixtureModel(components, weights=None)[source]#
Bases:
objectRepresents a finite mixture of continuous probability distributions.
This class encapsulates a collection of distribution components and their corresponding weights.
Instances of this class can be compared for equality (
==) and inequality (!=). Two models are considered equal if they have the same set of components and weights, regardless of the order in which components were added.- Parameters:
components (Sequence[ContinuousDistribution]) – A sequence of distribution objects that will form the mixture.
weights (Optional[ArrayLike], optional) – An array of initial weights for the components. The weights must be positive and sum to 1. If None, components are assigned equal weights. Defaults to None.
- Variables:
components (tuple[ContinuousDistribution]) – A tuple of the distribution objects that form the mixture.
n_components (int) – The number of components in the mixture.
weights (NDArray[np.float64]) – A NumPy array of the normalized weights for each component. The sum of weights is always 1.
log_weights (NDArray[np.float64]) – A NumPy array of the natural logarithm of the component weights.
- Raises:
ValueError – If the list of components is empty, or if the provided weights are invalid (e.g., negative, wrong number of elements, or do not sum to 1).
Methods
add_component(component, weight)Adds a new component to the mix, preserving the proportions of the existing component weights.
remove_component(component_idx)Removes a component from the mixture by its index.
pdf(X)Probability Density Function of the mixture.
lpdf(X)Logarithms of the Probability Density Function.
Log-likelihood of the complete data
X.generate(size)Generates random samples from the mixture model.