MixtureModel#

class MixtureModel(components, weights=None)[исходный код]#

Базовые классы: object

Represents 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.

The model is immutable: its components and weights cannot be changed after creation. Every modification returns a new MixtureModel via one of the with_* methods or without_component(). Because the contents never change in place, instances are hashable and can safely be used as dictionary keys.

Параметры:
  • components (Sequence[ParametricFamilyDistribution]) – A sequence of distribution objects that will form the mixture.

  • weights (ArrayLike | None, optional) – An array of initial weights for the components. The weights must be non-negative and sum to 1. If None, components are assigned equal weights. Defaults to None.

Переменные:
  • components (tuple[ParametricFamilyDistribution, ...]) – A tuple of the distribution objects that form the mixture.

  • n_components (int) – The number of components in the mixture.

  • weights (UnivariateFloatArray) – A NumPy array of the normalized weights for each component. The sum of weights is always 1.

  • log_weights (UnivariateFloatArray) – A read-only NumPy array of normalized logarithmic component weights. New weights are set via with_log_weights().

Исключение:

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

with_component(index, component)

Return a new mixture with the component at index replaced.

with_components(components)

Return a new mixture with all components replaced.

with_log_weights(log_weights)

Return a new mixture with the given log-weights.

with_added_component(component, weight)

Return a new mixture with an appended component.

without_component(index)

Return a new mixture without the component at index.

to_core_mixture()

Convert to a pysatl-core FiniteMixtureDistribution.

pdf(X)

Probability Density Function of the mixture: exp(lpdf(X)).

lpdf(X)

Logarithm of the Probability Density Function of the mixture.

component_lpdf_matrix(X)

Log-densities of every component, without the mixture weights.

loglikelihood(X)

Sum of log-densities for all points in X.

generate([size, random_state])

Sample random variates from the mixture distribution.