
    0Ph{                         d Z ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZmZ d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z G d de          ZdS )zGaussian Mixture Model.    N)linalg   )check_array)
StrOptions)	row_norms   )BaseMixture_check_shapec                 2   t          | t          j        t          j        gd          } t	          | |fd           t          t          j        | d                    s"t          t          j        | d                    r8t          dt          j	        |           t          j
        |           fz            t          j        t          j        dt          j        |           z
            d          s$t          dt          j        |           z            | S )a)  Check the user provided 'weights'.

    Parameters
    ----------
    weights : array-like of shape (n_components,)
        The proportions of components of each mixture.

    n_components : int
        Number of components.

    Returns
    -------
    weights : array, shape (n_components,)
    Fdtype	ensure_2dweights              ?z]The parameter 'weights' should be in the range [0, 1], but got max value %.5f, min value %.5fzIThe parameter 'weights' should be normalized, but got sum(weights) = %.5f)r   npfloat64float32r
   anylessgreater
ValueErrorminmaxallcloseabssum)r   n_componentss     a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/mixture/_gaussian_mixture.py_check_weightsr       s     '"*bj)AUSSSG</9555 277C  !! 
SGS)A)A%B%B 
=vgw01
 
 	
 ;rvcBF7OO344c:: 
WfWoo
 
 	
 N    c                 |    t          | t          j        t          j        gd          } t	          | ||fd           | S )a[  Validate the provided 'means'.

    Parameters
    ----------
    means : array-like of shape (n_components, n_features)
        The centers of the current components.

    n_components : int
        Number of components.

    n_features : int
        Number of features.

    Returns
    -------
    means : array, (n_components, n_features)
    Fr   means)r   r   r   r   r
   )r#   r   
n_featuress      r   _check_meansr%   5   s=    $ bj"*%=OOOEz2G<<<Lr!   c                 x    t          j        t          j        | d                    rt          d|z            dS )z.Check a precision vector is positive-definite.r   z!'%s precision' should be positiveN)r   r   
less_equalr   	precisioncovariance_types     r   _check_precision_positivityr+   L   sA    	vbmIs++,, P<NOOOP Pr!   c                     t          j        | | j                  r*t          j        t	          j        |           dk              st          d|z            dS )z<Check a precision matrix is symmetric and positive-definite.r   z5'%s precision' should be symmetric, positive-definiteN)r   r   Tallr   eigvalshr   r(   s     r   _check_precision_matrixr0   R   sb     	Iy{++
02vy7Q7QTW7W0X0X
 CoU
 
 	

 
r!   c                 0    | D ]}t          ||           dS )zACheck the precision matrices are symmetric and positive-definite.N)r0   )
precisionsr*   precs      r   _check_precisions_fullr4   \   s.     7 7o66667 7r!   c                    t          | t          j        t          j        gd|dk              } |||f||f||f|fd}t	          | ||         d|z             t
          t          t          t          d} ||         | |           | S )a  Validate user provided precisions.

    Parameters
    ----------
    precisions : array-like
        'full' : shape of (n_components, n_features, n_features)
        'tied' : shape of (n_features, n_features)
        'diag' : shape of (n_components, n_features)
        'spherical' : shape of (n_components,)

    covariance_type : str

    n_components : int
        Number of components.

    n_features : int
        Number of features.

    Returns
    -------
    precisions : array
    Ffull)r   r   allow_ndr6   tieddiag	sphericalz%s precision)r   r   r   r   r
   r4   r0   r+   )r2   r*   r   r$   precisions_shape_check_precisionss         r   r=   r=   b   s    . z2:& F*	  J z:6Z(z*"_	  $_5~7W  
 ''+0	  'o&z?CCCr!   c                 *   |j         \  }}t          j        |||f          }t          |          D ]a}|||         z
  }	t          j        | dd|f         |	j        z  |	          ||         z  ||<   ||         j        dd|dz   xx         |z  cc<   b|S )a  Estimate the full covariance matrices.

    Parameters
    ----------
    resp : array-like of shape (n_samples, n_components)

    X : array-like of shape (n_samples, n_features)

    nk : array-like of shape (n_components,)

    means : array-like of shape (n_components, n_features)

    reg_covar : float

    Returns
    -------
    covariances : array, shape (n_components, n_features, n_features)
        The covariance matrix of the current components.
    Nr   )shaper   emptyrangedotr-   flat)
respXnkr#   	reg_covarr   r$   covarianceskdiffs
             r   #_estimate_gaussian_covariances_fullrK      s    (  %{L*(L*jABBK<   < <58|QQQT
TV 3T::RUBAA--zA~-...);....r!   c                     t          j        |j        |          }t          j        ||j        z  |          }||z
  }||                                z  }|j        ddt          |          dz   xx         |z  cc<   |S )a  Estimate the tied covariance matrix.

    Parameters
    ----------
    resp : array-like of shape (n_samples, n_components)

    X : array-like of shape (n_samples, n_features)

    nk : array-like of shape (n_components,)

    means : array-like of shape (n_components, n_features)

    reg_covar : float

    Returns
    -------
    covariance : array, shape (n_features, n_features)
        The tied covariance matrix of the components.
    Nr   )r   rB   r-   r   rC   len)rD   rE   rF   r#   rG   avg_X2
avg_means2
covariances           r   #_estimate_gaussian_covariances_tiedrQ      s    ( VAC^^FUWe,,J*$J"&&((JO**s:**+++y8+++r!   c                     t          j        | j        ||z            |ddt           j        f         z  }|dz  }|t          j        | j        |          z  |ddt           j        f         z  }|d|z  z
  |z   |z   S )a  Estimate the diagonal covariance vectors.

    Parameters
    ----------
    responsibilities : array-like of shape (n_samples, n_components)

    X : array-like of shape (n_samples, n_features)

    nk : array-like of shape (n_components,)

    means : array-like of shape (n_components, n_features)

    reg_covar : float

    Returns
    -------
    covariances : array, shape (n_components, n_features)
        The covariance vector of the current components.
    Nr   )r   rB   r-   newaxis)rD   rE   rF   r#   rG   rN   rO   avg_X_meanss           r   #_estimate_gaussian_covariances_diagrU      s}    ( VDFAE""R2:%66FJ"&+++bBJ.??KAO#j09<<r!   c                 N    t          | ||||                              d          S )a  Estimate the spherical variance values.

    Parameters
    ----------
    responsibilities : array-like of shape (n_samples, n_components)

    X : array-like of shape (n_samples, n_features)

    nk : array-like of shape (n_components,)

    means : array-like of shape (n_components, n_features)

    reg_covar : float

    Returns
    -------
    variances : array, shape (n_components,)
        The variance values of each components.
    r   )rU   mean)rD   rE   rF   r#   rG   s        r   (_estimate_gaussian_covariances_sphericalrX      s)    ( /tQE9MMRRSTUUUr!   c                 :   |                     d          dt          j        |j                  j        z  z   }t          j        |j        |           |ddt          j        f         z  }	 t          t          t          t          d|         || |||          }|||fS )aX  Estimate the Gaussian distribution parameters.

    Parameters
    ----------
    X : array-like of shape (n_samples, n_features)
        The input data array.

    resp : array-like of shape (n_samples, n_components)
        The responsibilities for each data sample in X.

    reg_covar : float
        The regularization added to the diagonal of the covariance matrices.

    covariance_type : {'full', 'tied', 'diag', 'spherical'}
        The type of precision matrices.

    Returns
    -------
    nk : array-like of shape (n_components,)
        The numbers of data samples in the current components.

    means : array-like of shape (n_components, n_features)
        The centers of the current components.

    covariances : array-like
        The covariance matrix of the current components.
        The shape depends of the covariance_type.
    r   axis
   Nr8   )r   r   finfor   epsrB   r-   rS   rK   rQ   rU   rX   )rE   rD   rG   r*   rF   r#   rH   s          r   _estimate_gaussian_parametersr_     s    : 
q		B$*!5!5!99	9BF461111bj= 11E333=	 
 
 QE96 6K uk!!r!   c                    d}|dk    r| j         \  }}}t          j        |||f          }t          |           D ]p\  }}	 t	          j        |d          }	n"# t          j        $ r t          |          w xY wt	          j        |	t          j	        |          d          j
        ||<   qn|dk    rs| j         \  }}	 t	          j        | d          }	n"# t          j        $ r t          |          w xY wt	          j        |	t          j	        |          d          j
        }nMt          j        t          j        | d                    rt          |          dt          j        |           z  }|S )a	  Compute the Cholesky decomposition of the precisions.

    Parameters
    ----------
    covariances : array-like
        The covariance matrix of the current components.
        The shape depends of the covariance_type.

    covariance_type : {'full', 'tied', 'diag', 'spherical'}
        The type of precision matrices.

    Returns
    -------
    precisions_cholesky : array-like
        The cholesky decomposition of sample precisions of the current
        components. The shape depends of the covariance_type.
    zFitting the mixture model failed because some components have ill-defined empirical covariance (for instance caused by singleton or collapsed samples). Try to decrease the number of components, or increase reg_covar.r6   Tlowerr9   r   r   )r?   r   r@   	enumerater   choleskyLinAlgErrorr   solve_triangulareyer-   r   r'   sqrt)
rH   r*    estimate_precision_error_messager   r$   _precisions_cholrI   rP   cov_chols
             r   _compute_precision_choleskyrm   *  s   &	! % &  &1&7#j!(L*j#IJJ&{33 	 	MAzC!?:TBBB% C C C !ABBBC!'!8"&,,D" " " A	 
F	"	"#):	?{$???HH! 	? 	? 	?=>>>	? 1bfZ((
 
 

 	 6"-S1122 	?=>>> 4 44s    AA6=C C3c                 N    t          j        t          j        |                     S )z)Reverse the rows and columns of an array.)r   flipudfliplr)arrays    r   	_flipudlrrr   ^  s    9RYu%%&&&r!   c                     |dk    rt          j        d | D                       }nK|dk    r1t          t          j        t          |           d                    }nt          j        |           }|S )a  Compute the Cholesky decomposition of precisions using precisions themselves.

    As implemented in :func:`_compute_precision_cholesky`, the `precisions_cholesky_` is
    an upper-triangular matrix for each Gaussian component, which can be expressed as
    the $UU^T$ factorization of the precision matrix for each Gaussian component, where
    $U$ is an upper-triangular matrix.

    In order to use the Cholesky decomposition to get $UU^T$, the precision matrix
    $\Lambda$ needs to be permutated such that its rows and columns are reversed, which
    can be done by applying a similarity transformation with an exchange matrix $J$,
    where the 1 elements reside on the anti-diagonal and all other elements are 0. In
    particular, the Cholesky decomposition of the transformed precision matrix is
    $J\Lambda J=LL^T$, where $L$ is a lower-triangular matrix. Because $\Lambda=UU^T$
    and $J=J^{-1}=J^T$, the `precisions_cholesky_` for each Gaussian component can be
    expressed as $JLJ$.

    Refer to #26415 for details.

    Parameters
    ----------
    precisions : array-like
        The precision matrix of the current components.
        The shape depends on the covariance_type.

    covariance_type : {'full', 'tied', 'diag', 'spherical'}
        The type of precision matrices.

    Returns
    -------
    precisions_cholesky : array-like
        The cholesky decomposition of sample precisions of the current
        components. The shape depends on the covariance_type.
    r6   c           	      n    g | ]2}t          t          j        t          |          d                     3S )Tra   )rr   r   rd   ).0r)   s     r   
<listcomp>z?_compute_precision_cholesky_from_precisions.<locals>.<listcomp>  sG        &/)I*>*>dKKKLL  r!   r9   Tra   )r   rq   rr   r   rd   rh   )r2   r*   precisions_choleskys      r   +_compute_precision_cholesky_from_precisionsrx   c  s    D &   h !+  
 
 
F	"	"'OIj11>>>
 
 !gj11r!   c           
         |dk    rW| j         \  }}}t          j        t          j        |                     |d          dddd|dz   f                   d          }n|dk    r9t          j        t          j        t          j        |                               }nF|dk    r)t          j        t          j        |           d          }n|t          j        |           z  }|S )a  Compute the log-det of the cholesky decomposition of matrices.

    Parameters
    ----------
    matrix_chol : array-like
        Cholesky decompositions of the matrices.
        'full' : shape of (n_components, n_features, n_features)
        'tied' : shape of (n_features, n_features)
        'diag' : shape of (n_components, n_features)
        'spherical' : shape of (n_components,)

    covariance_type : {'full', 'tied', 'diag', 'spherical'}

    n_features : int
        Number of features.

    Returns
    -------
    log_det_precision_chol : array-like of shape (n_components,)
        The determinant of the precision matrix for each component.
    r6   Nr   r9   r:   rZ   )r?   r   r   logreshaper:   )matrix_cholr*   r$   r   rj   log_det_chols         r   _compute_log_det_choleskyr     s    , &  (.avF;&&|R88<M<MzA~<M9MNOOQR
 
 
F	"	"vbfRW[%9%9::;;	F	"	"vbf[11::: "RVK%8%89r!   c                    | j         \  }}|j         \  }}t          |||          }|dk    rt          j        ||f          }	t	          t          ||                    D ]b\  }
\  }}t          j        | |          t          j        ||          z
  }t          j        t          j        |          d          |	dd|
f<   cn^|dk    rt          j        ||f          }	t	          |          D ]_\  }
}t          j        | |          t          j        ||          z
  }t          j        t          j        |          d          |	dd|
f<   `n|dk    r`|dz  }t          j        |dz  |z  d          dt          j        | ||z  j	                  z  z
  t          j        | dz  |j	                  z   }	nl|d	k    rf|dz  }t          j        |dz  d          |z  dt          j        | |j	        |z            z  z
  t          j
        t          | d
          |          z   }	d|t          j        dt          j        z            z  |	z   z  |z   S )a{  Estimate the log Gaussian probability.

    Parameters
    ----------
    X : array-like of shape (n_samples, n_features)

    means : array-like of shape (n_components, n_features)

    precisions_chol : array-like
        Cholesky decompositions of the precision matrices.
        'full' : shape of (n_components, n_features, n_features)
        'tied' : shape of (n_features, n_features)
        'diag' : shape of (n_components, n_features)
        'spherical' : shape of (n_components,)

    covariance_type : {'full', 'tied', 'diag', 'spherical'}

    Returns
    -------
    log_prob : array, shape (n_samples, n_components)
    r6   r   rZ   Nr9   r:   r          @r;   T)squaredg      )r?   r   r   r@   rc   ziprB   r   squarer-   outerr   r{   pi)rE   r#   rk   r*   	n_samplesr$   r   rj   log_detlog_probrI   mu	prec_cholyr2   s                  r   _estimate_log_gaussian_probr     sg   , GIzkOL!
 (*UUG&  8Y566"+C,G,G"H"H 	: 	:AIq)$$rvb)'<'<<AVBIaLLq999HQQQTNN	: 
F	"	"8Y566u%% 	: 	:EArq/**RVB-H-HHAVBIaLLq999HQQQTNN	: 
F	"	"$a'
FE1Hz)A..BF1uz145556fQT:<(() 	 
K	'	'$a'
F5!8Q*,"&EGj01112hyD111:>>? 	 :q25y 1 11H<=GGr!   c                        e Zd ZU dZi ej         eh d          gddgddgddgdZeed<   	 ddd	d
ddddddddddd fdZ	d Z
 fdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )GaussianMixtureaF  Gaussian Mixture.

    Representation of a Gaussian mixture model probability distribution.
    This class allows to estimate the parameters of a Gaussian mixture
    distribution.

    Read more in the :ref:`User Guide <gmm>`.

    .. versionadded:: 0.18

    Parameters
    ----------
    n_components : int, default=1
        The number of mixture components.

    covariance_type : {'full', 'tied', 'diag', 'spherical'}, default='full'
        String describing the type of covariance parameters to use.
        Must be one of:

        - 'full': each component has its own general covariance matrix.
        - 'tied': all components share the same general covariance matrix.
        - 'diag': each component has its own diagonal covariance matrix.
        - 'spherical': each component has its own single variance.

    tol : float, default=1e-3
        The convergence threshold. EM iterations will stop when the
        lower bound average gain is below this threshold.

    reg_covar : float, default=1e-6
        Non-negative regularization added to the diagonal of covariance.
        Allows to assure that the covariance matrices are all positive.

    max_iter : int, default=100
        The number of EM iterations to perform.

    n_init : int, default=1
        The number of initializations to perform. The best results are kept.

    init_params : {'kmeans', 'k-means++', 'random', 'random_from_data'},     default='kmeans'
        The method used to initialize the weights, the means and the
        precisions.
        String must be one of:

        - 'kmeans' : responsibilities are initialized using kmeans.
        - 'k-means++' : use the k-means++ method to initialize.
        - 'random' : responsibilities are initialized randomly.
        - 'random_from_data' : initial means are randomly selected data points.

        .. versionchanged:: v1.1
            `init_params` now accepts 'random_from_data' and 'k-means++' as
            initialization methods.

    weights_init : array-like of shape (n_components, ), default=None
        The user-provided initial weights.
        If it is None, weights are initialized using the `init_params` method.

    means_init : array-like of shape (n_components, n_features), default=None
        The user-provided initial means,
        If it is None, means are initialized using the `init_params` method.

    precisions_init : array-like, default=None
        The user-provided initial precisions (inverse of the covariance
        matrices).
        If it is None, precisions are initialized using the 'init_params'
        method.
        The shape depends on 'covariance_type'::

            (n_components,)                        if 'spherical',
            (n_features, n_features)               if 'tied',
            (n_components, n_features)             if 'diag',
            (n_components, n_features, n_features) if 'full'

    random_state : int, RandomState instance or None, default=None
        Controls the random seed given to the method chosen to initialize the
        parameters (see `init_params`).
        In addition, it controls the generation of random samples from the
        fitted distribution (see the method `sample`).
        Pass an int for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    warm_start : bool, default=False
        If 'warm_start' is True, the solution of the last fitting is used as
        initialization for the next call of fit(). This can speed up
        convergence when fit is called several times on similar problems.
        In that case, 'n_init' is ignored and only a single initialization
        occurs upon the first call.
        See :term:`the Glossary <warm_start>`.

    verbose : int, default=0
        Enable verbose output. If 1 then it prints the current
        initialization and each iteration step. If greater than 1 then
        it prints also the log probability and the time needed
        for each step.

    verbose_interval : int, default=10
        Number of iteration done before the next print.

    Attributes
    ----------
    weights_ : array-like of shape (n_components,)
        The weights of each mixture components.

    means_ : array-like of shape (n_components, n_features)
        The mean of each mixture component.

    covariances_ : array-like
        The covariance of each mixture component.
        The shape depends on `covariance_type`::

            (n_components,)                        if 'spherical',
            (n_features, n_features)               if 'tied',
            (n_components, n_features)             if 'diag',
            (n_components, n_features, n_features) if 'full'

    precisions_ : array-like
        The precision matrices for each component in the mixture. A precision
        matrix is the inverse of a covariance matrix. A covariance matrix is
        symmetric positive definite so the mixture of Gaussian can be
        equivalently parameterized by the precision matrices. Storing the
        precision matrices instead of the covariance matrices makes it more
        efficient to compute the log-likelihood of new samples at test time.
        The shape depends on `covariance_type`::

            (n_components,)                        if 'spherical',
            (n_features, n_features)               if 'tied',
            (n_components, n_features)             if 'diag',
            (n_components, n_features, n_features) if 'full'

    precisions_cholesky_ : array-like
        The cholesky decomposition of the precision matrices of each mixture
        component. A precision matrix is the inverse of a covariance matrix.
        A covariance matrix is symmetric positive definite so the mixture of
        Gaussian can be equivalently parameterized by the precision matrices.
        Storing the precision matrices instead of the covariance matrices makes
        it more efficient to compute the log-likelihood of new samples at test
        time. The shape depends on `covariance_type`::

            (n_components,)                        if 'spherical',
            (n_features, n_features)               if 'tied',
            (n_components, n_features)             if 'diag',
            (n_components, n_features, n_features) if 'full'

    converged_ : bool
        True when convergence of the best fit of EM was reached, False otherwise.

    n_iter_ : int
        Number of step used by the best fit of EM to reach the convergence.

    lower_bound_ : float
        Lower bound value on the log-likelihood (of the training data with
        respect to the model) of the best fit of EM.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    BayesianGaussianMixture : Gaussian mixture model fit with a variational
        inference.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.mixture import GaussianMixture
    >>> X = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]])
    >>> gm = GaussianMixture(n_components=2, random_state=0).fit(X)
    >>> gm.means_
    array([[10.,  2.],
           [ 1.,  2.]])
    >>> gm.predict([[0, 0], [12, 3]])
    array([1, 0])
    >   r:   r6   r9   r;   z
array-likeN)r*   weights_init
means_initprecisions_init_parameter_constraintsr   r6   gMbP?gư>d   kmeansFr   r\   )r*   tolrG   max_itern_initinit_paramsr   r   r   random_state
warm_startverboseverbose_intervalc                    t                                          ||||||||||
  
         || _        || _        |	| _        |
| _        d S )N)
r   r   rG   r   r   r   r   r   r   r   )super__init__r*   r   r   r   )selfr   r*   r   rG   r   r   r   r   r   r   r   r   r   r   	__class__s                  r   r   zGaussianMixture.__init__  sk    $ 	%#%!- 	 	
 	
 	
  /($.r!   c                    |j         \  }}| j        t          | j        | j                  | _        | j         t          | j        | j        |          | _        | j        (t          | j        | j        | j        |          | _        dS dS )z7Check the Gaussian mixture parameters are well defined.N)	r?   r   r    r   r   r%   r   r=   r*   )r   rE   rj   r$   s       r   _check_parametersz!GaussianMixture._check_parameters  s    :( .t/@$BS T TD?&*!2J DO +#4$$!	$ $D    ,+r!   c                     | j         d u p| j        d u p| j        d u }|r$t                                          ||           d S |                     |d            d S N)r   r   r   r   _initialize_parameters_initialize)r   rE   r   compute_respr   s       r   r   z&GaussianMixture._initialize_parameters  sz     % ,$&,#t+ 	
  	&GG**1l;;;;;Q%%%%%r!   c                 h   |j         \  }}d\  }}}|,t          ||| j        | j                  \  }}}| j        ||z  }| j        |n| j        | _        | j        |n| j        | _        | j        #|| _	        t          || j                  | _        dS t          | j        | j                  | _        dS )zInitialization of the Gaussian mixture parameters.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)

        resp : array-like of shape (n_samples, n_components)
        )NNNN)r?   r_   rG   r*   r   weights_r   means_r   covariances_rm   precisions_cholesky_rx   )r   rE   rD   r   rj   r   r#   rH   s           r   r   zGaussianMixture._initialize  s     w	1&6#*G4)=+ +'GUK  (9$#'#4#<$BS#6eeDO' +D(CT1) )D%%% )T$d&:) )D%%%r!   c                    t          |t          j        |          | j        | j                  \  | _        | _        | _        | xj        | j                                        z  c_        t          | j        | j                  | _
        dS )a*  M step.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)

        log_resp : array-like of shape (n_samples, n_components)
            Logarithm of the posterior probabilities (or responsibilities) of
            the point of each sample in X.
        N)r_   r   exprG   r*   r   r   r   r   rm   r   )r   rE   log_resps      r   _m_stepzGaussianMixture._m_step   s}     9Vrvh1E9
 9
5t{D$5 	**,,,$?t3%
 %
!!!r!   c                 D    t          || j        | j        | j                  S r   )r   r   r   r*   r   rE   s     r   _estimate_log_probz"GaussianMixture._estimate_log_prob3  s%    *t{D5t7K
 
 	
r!   c                 4    t          j        | j                  S r   )r   r{   r   r   s    r   _estimate_log_weightsz%GaussianMixture._estimate_log_weights8  s    vdm$$$r!   c                     |S r    )r   rj   log_prob_norms      r   _compute_lower_boundz$GaussianMixture._compute_lower_bound;  s    r!   c                 6    | j         | j        | j        | j        fS r   )r   r   r   r   r   s    r   _get_parameterszGaussianMixture._get_parameters>  s"    MK%	
 	
r!   c                    |\  | _         | _        | _        | _        | j        j        \  }}| j        dk    rat          j        | j        j                  | _        t          | j                  D ]'\  }}t          j
        ||j                  | j        |<   (d S | j        dk    r+t          j
        | j        | j        j                  | _        d S | j        dz  | _        d S )Nr6   r9   r   )r   r   r   r   r?   r*   r   r@   precisions_rc   rB   r-   )r   paramsrj   r$   rI   r   s         r   _set_parameterszGaussianMixture._set_parametersF  s     	
MK% ):6))!x(A(GHHD )$*C D D E E9&(fY	&D&D ##E E !V++!v)4+D+F   D  $8!;Dr!   c                 *   | j         j        \  }}| j        dk    r| j        |z  |dz   z  dz  }n?| j        dk    r| j        |z  }n)| j        dk    r||dz   z  dz  }n| j        dk    r| j        }|| j        z  }t	          ||z   | j        z   dz
            S )z2Return the number of free parameters in the model.r6   r   r   r:   r9   r;   )r   r?   r*   r   int)r   rj   r$   
cov_paramsmean_paramss        r   _n_parameterszGaussianMixture._n_parameters]  s    ):6))*Z7:>JSPJJ!V++*Z7JJ!V++#zA~6<JJ![00*J 4#44:+d.??!CDDDr!   c                     d|                      |          z  |j        d         z  |                                 t          j        |j        d                   z  z   S )a  Bayesian information criterion for the current model on the input X.

        You can refer to this :ref:`mathematical section <aic_bic>` for more
        details regarding the formulation of the BIC used.

        Parameters
        ----------
        X : array of shape (n_samples, n_dimensions)
            The input samples.

        Returns
        -------
        bic : float
            The lower the better.
        r   )scorer?   r   r   r{   r   s     r   biczGaussianMixture.bick  sW      DJJqMM!AGAJ.1C1C1E1EGAJI
 I
 2
 
 	
r!   c                 ~    d|                      |          z  |j        d         z  d|                                 z  z   S )a  Akaike information criterion for the current model on the input X.

        You can refer to this :ref:`mathematical section <aic_bic>` for more
        details regarding the formulation of the AIC used.

        Parameters
        ----------
        X : array of shape (n_samples, n_dimensions)
            The input samples.

        Returns
        -------
        aic : float
            The lower the better.
        r   r   r   )r   r?   r   r   s     r   aiczGaussianMixture.aic  s:      DJJqMM!AGAJ.T5G5G5I5I1IIIr!   )r   )__name__
__module____qualname____doc__r	   r   r   dict__annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r     s        t tl$

,$&J'L'L'LMMN%t,#T*($/$ $ $D    "/ !"/ "/ "/ "/ "/ "/ "/H  (& & & & &  >
 
 
&
 
 

% % %  
 
 
< < <.E E E
 
 
(J J J J J J Jr!   r   )r   numpyr   scipyr   utilsr   utils._param_validationr   utils.extmathr   _baser	   r
   r    r%   r+   r0   r4   r=   rK   rQ   rU   rX   r_   rm   rr   rx   r   r   r   r   r!   r   <module>r      s    
                 0 0 0 0 0 0 % % % % % % , , , , , , , ,     F  .P P P
 
 
7 7 7/ / /l  :  8= = =4V V V.%" %" %"P1 1 1h' ' '
/ / /h% % %P;H ;H ;H|RJ RJ RJ RJ RJk RJ RJ RJ RJ RJr!   