
    -i                         S r SSKrSSKJr  SSKJr  SSKJr  SSK	J
r
  SS	KJrJr  S
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r " S S\5      rg)zGaussian Mixture Model.    N)linalg   )check_array)
StrOptions)	row_norms   )BaseMixture_check_shapec                    [        U [        R                  [        R                  /SS9n [	        X4S5        [        [        R                  " U S5      5      (       d%  [        [        R                  " U S5      5      (       a8  [        S[        R                  " U 5      [        R                  " U 5      4-  5      eU R                  [        R                  :X  a  SOSn[        R                  " [        R                  " S[        R                  " U 5      -
  5      SUS	9(       d"  [        S
[        R                  " U 5      -  5      eU $ )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 %.5fư>g:0yE>)atolzIThe parameter 'weights' should be normalized, but got sum(weights) = %.5f)r   npfloat64float32r
   anylessgreater
ValueErrorminmaxr   allcloseabssum)r   n_componentsr   s      T/var/www/html/venv/lib/python3.13/site-packages/sklearn/mixture/_gaussian_mixture.py_check_weightsr"      s     '"**bjj)AUSG/95 2777C !!SGS)A%B%B=vvgw01
 	
 ==BJJ.4DD;;rvvcBFF7O34cEWffWo
 	
 N    c                 t    [        U [        R                  [        R                  /SS9n [	        XU4S5        U $ )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'   6   s3    $ bjj"**%=OEz2G<Lr#   c                     [         R                  " [         R                  " U S5      5      (       a  [        SU-  5      eg)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-   M   s2    	vvbmmIs+,,<NOO -r#   c                     [         R                  " X R                  5      (       a2  [         R                  " [        R
                  " U 5      S:  5      (       d  [        SU-  5      eg)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_matrixr2   S   sO     	I{{++vy7QTW7W0X0XCoU
 	
 1Yr#   c                 ,    U  H  n[        X!5        M     g)zACheck the precision matrices are symmetric and positive-definite.N)r2   )
precisionsr,   precs      r!   _check_precisions_fullr6   ]   s    6 r#   c                     [        U [        R                  [        R                  /SUS:H  S9n X#U4X34X#4U4S.n[	        XU   SU-  5        [
        [        [        [        S.nXQ   " X5        U $ )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r8   tieddiag	sphericalz%s precision)r   r   r   r   r
   r6   r2   r-   )r4   r,   r    r&   precisions_shape_check_precisionss         r!   r?   r?   c   s    . zz2::& F*	J :6(*"_	 _5~7W
 ''+0	 &zCr#   c                 8   UR                   u  pV[        R                  " XVU4UR                  S9n[	        U5       H[  nXU   -
  n	[        R
                  " U SS2U4   U	R                  -  U	5      X(   -  Xx'   Xx   R                  SSUS-   2==   U-  ss'   M]     U$ )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.
r   Nr   )shaper   emptyr   rangedotr/   flat)
respXnkr%   	reg_covarr    r&   covarianceskdiffs
             r!   #_estimate_gaussian_covariances_fullrN      s    (  %{{L((LjAQK< 8|QT
TVV 3T:RUB-zA~-.);. ! r#   c                    [         R                  " UR                  U5      n[         R                  " X#R                  -  U5      nXV-
  nXrR                  5       -  nUR                  SS[        U5      S-   2==   U-  ss'   U$ )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   rE   r/   r   rF   len)rG   rH   rI   r%   rJ   avg_X2
avg_means2
covariances           r!   #_estimate_gaussian_covariances_tiedrT      sl    ( VVACC^FWWe,J$J&&(JOO*s:**+y8+r#   c                     [         R                  " U R                  X-  5      USS2[         R                  4   -  nUS-  nXV-
  U-   $ )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   rE   r/   newaxis)rG   rH   rI   r%   rJ   rQ   rR   s          r!   #_estimate_gaussian_covariances_diagrW      sC    ( VVDFFAE"R2::%66FJ**r#   c                 :    [        XX#U5      R                  S5      $ )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   )rW   mean)rG   rH   rI   r%   rJ   s        r!   (_estimate_gaussian_covariances_sphericalrZ      s    ( /t9MRRSTUUr#   c                 :   UR                  SS9S[        R                  " UR                  5      R                  -  -   n[        R
                  " UR                  U 5      USS2[        R                  4   -  n[        [        [        [        S.U   " XXEU5      nXEU4$ )a  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
   Nr:   )r   r   finfor   epsrE   r/   rV   rN   rT   rW   rZ   )rH   rG   rJ   r,   rI   r%   rK   s          r!   _estimate_gaussian_parametersra     s    : 
q	B$**!5!9!99	9BFF46611bjj= 11E333=	
 
 96K k!!r#   c           	      \   SnU R                   nU[        R                  :X  a  US-  nUS:X  a  U R                  u  pEn[        R                  " XEU4US9n[        U 5       HO  u  p [        R                  " U	SS9n
[        R                  " U
[        R                  " XSS9SS9R                  Xx'   MQ     U$ US:X  aX  U R                  u  pe [        R                  " U SS9n
[        R                  " U
[        R                  " XSS9SS9R                  nU$ [        R                  " [        R                  " U S5      5      (       a  [        U5      eS	[        R                  " U 5      -  nU$ ! [        R                   a    [        U5      ef = f! [        R                   a    [        U5      ef = f)
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, increase reg_covar, or scale the input data.zX The numerical accuracy can also be improved by passing float64 data instead of float32.r8   rA   Tlowerr;   r   r   )r   r   r   rB   rC   	enumerater   choleskyLinAlgErrorr   solve_triangulareyer/   r   r)   sqrt)rK   r,    estimate_precision_error_messager   r    r&   _precisions_cholrL   rS   cov_chols              r!   _compute_precision_choleskyro   *  s   &	7 % E

((	
(
 & &1&7&7#!((Lj#IQVW&{3MAC!??:TB "(!8!8"&&9"a  4*  
F	"#))	?{$?H !11bffZ5T

! 	  66"--S122=>> 44% %% C !ABBC !! 	?=>>	?s   %E(	F ( F F+c                 V    [         R                  " [         R                  " U 5      5      $ )z)Reverse the rows and columns of an array.)r   flipudfliplr)arrays    r!   	_flipudlrrt   d  s    99RYYu%&&r#   c                 B   US:X  aN  [         R                  " U  Vs/ s H*  n[        [        R                  " [        U5      SS95      PM,     sn5      nU$ US:X  a)  [        [        R                  " [        U 5      SS95      nU$ [         R
                  " U 5      nU$ s  snf )au  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.
r8   Trc   r;   )r   rs   rt   r   rf   rj   )r4   r,   r+   precisions_choleskys       r!   +_compute_precision_cholesky_from_precisionsrw   i  s    D &  hh ",!+I &//)I*>dKL!+
  
F	"'OOIj1>

  !ggj1s   1Bc           
         US:X  aX  U R                   u  n  n[        R                  " [        R                  " U R	                  US5      SS2SSUS-   24   5      SS9nU$ US:X  a@  [        R                  " [        R                  " [        R
                  " U 5      5      5      nU$ US:X  a+  [        R                  " [        R                  " U 5      SS9nU$ U[        R                  " U 5      -  nU$ )aU  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.
r8   Nr   r\   r;   r<   )rB   r   r   logreshaper<   )matrix_cholr,   r&   r    rl   log_det_chols         r!   _compute_log_det_choleskyr~     s    , & (..avvFF;&&|R8<MzA~<M9MNOVW
  
F	"vvbffRWW[%9:;  
F	"vvbff[1:
  "BFF;$77r#   c                 ,   U R                   u  pEUR                   u  pg[        X#U5      nUS:X  a  [        R                  " XF4U R                  S9n	[        [        X5      5       He  u  n
u  p[        R                  " X5      [        R                  " X5      -
  n[        R                  " [        R                  " U5      SS9U	SS2U
4'   Mg     GO|US:X  a  [        R                  " XF4U R                  S9n	[        U5       Hb  u  p[        R                  " X5      [        R                  " X5      -
  n[        R                  " [        R                  " U5      SS9U	SS2U
4'   Md     OUS:X  ao  US-  n[        R                  " US-  U-  S5      S	[        R                  " XU-  R                  5      -  -
  [        R                  " U S-  UR                  5      -   n	OoUS
:X  ai  US-  n[        R                  " US-  S5      U-  S[        R                  " XR                  U-  5      -  -
  [        R                  " [        U SS9U5      -   n	SU[        R                  " S[        R                  -  5      R                  U R                  5      -  W	-   -  U-   $ )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)
r8   rA   r   r\   Nr;   r<   r          @r=   T)squaredg      )rB   r~   r   rC   r   re   ziprE   r   squarer/   outerr   rz   piastype)rH   r%   rm   r,   	n_samplesr&   r    rl   log_detlog_probrL   mu	prec_cholyr4   s                  r!   _estimate_log_gaussian_probr     s    , GGIkkOL
 (*UG& 88Y5QWWE"+C,G"HAq$rvvb'<<AVVBIIaLq9HQTN #I 
F	"88Y5QWWEu%EAq*RVVB-HHAVVBIIaLq9HQTN & 
F	"$a'
FFE1Hz)A.BFF1z144556ffQT:<<() 	 
K	'$a'
FF5!8Q*,"&&GGj0112hhyD1:>? 	 :q255y 1 8 8 AAHLMPWWWr#   c                      ^  \ rS rSr% Sr0 \R                  E\" 1 Sk5      /SS/SS/SS/S.Er\\	S'    S S	S
SSSSSSSSSSSS.U 4S jjjr
S rU 4S jrS rS rS rS rS rS rS rS rS rS rSrU =r$ )!GaussianMixturei  a)  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.

    For an example of using `covariance_type`, refer to
    :ref:`sphx_glr_auto_examples_mixture_plot_gmm_selection.py`.

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'

    For an example of using covariances, refer to
    :ref:`sphx_glr_auto_examples_mixture_plot_gmm_covariances.py`.

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.

lower_bounds_ : array-like of shape (`n_iter_`,)
    The list of lower bound values on the log-likelihood from each
    iteration 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])

For a comparison of Gaussian Mixture with other clustering algorithms, see
:ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py`
>   r<   r8   r;   r=   z
array-likeN)r,   weights_init
means_initprecisions_init_parameter_constraintsr   r8   gMbP?r   d   kmeansFr   r^   )r,   tolrJ   max_itern_initinit_paramsr   r   r   random_state
warm_startverboseverbose_intervalc                b   > [         TU ]  UUUUUUUUUUS9
  X l        Xl        Xl        Xl        g )N)
r    r   rJ   r   r   r   r   r   r   r   )super__init__r,   r   r   r   )selfr    r,   r   rJ   r   r   r   r   r   r   r   r   r   r   	__class__s                  r!   r   GaussianMixture.__init__  sN    $ 	%#%!- 	 	
  /($.r#   c                 h   UR                   u  p#U R                  b%  [        U R                  U R                  5      U l        U R                  b&  [        U R                  U R                  U5      U l        U R                  b2  [        U R                  U R                  U R                  U5      U l        gg)z7Check the Gaussian mixture parameters are well defined.N)	rB   r   r"   r    r   r'   r   r?   r,   )r   rH   rl   r&   s       r!   _check_parameters!GaussianMixture._check_parameters  s    ( .t/@/@$BSBS TD??&*!2!2JDO +#4$$$$!!	$D  ,r#   c                    > U R                   S L =(       d#    U R                  S L =(       d    U R                  S L nU(       a  [        TU ]  X5        g U R                  US 5        g N)r   r   r   r   _initialize_parameters_initialize)r   rH   r   compute_respr   s       r!   r   &GaussianMixture._initialize_parameters  s^     % ,$&,##t+ 	
 G*1;Q%r#   c                    UR                   u  p4Su  pVnUb5  [        XU R                  U R                  5      u  pVnU R                  c  XS-  nU R                  c  UOU R                  U l        U R                  c  UOU R                  U l        U R                  c!  Xpl	        [        XpR                  5      U l        g[        U R                  U R                  5      U l        g)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)rB   ra   rJ   r,   r   weights_r   means_r   covariances_ro   precisions_cholesky_rw   )r   rH   rG   r   rl   r   r%   rK   s           r!   r   GaussianMixture._initialize  s     ww	&6#*G)=)=+'GK   ($#'#4#4#<$BSBS#6eDOO' +(C11)D% )T$$d&:&:)D%r#   c                 :   [        U[        R                  " U5      U R                  U R                  5      u  U l        U l        U l        U =R
                  U R
                  R                  5       -  sl        [        U R                  U R                  5      U l
        g)zM 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)ra   r   exprJ   r,   r   r   r   r   ro   r   )r   rH   log_resps      r!   _m_stepGaussianMixture._m_step3  st     9Vrvvh1E1E9
5t{D$5 	**,,$?t33%
!r#   c                 X    [        XR                  U R                  U R                  5      $ r   )r   r   r   r,   r   rH   s     r!   _estimate_log_prob"GaussianMixture._estimate_log_probF  s&    *{{D55t7K7K
 	
r#   c                 B    [         R                  " U R                  5      $ r   )r   rz   r   r   s    r!   _estimate_log_weights%GaussianMixture._estimate_log_weightsK  s    vvdmm$$r#   c                     U$ r    )r   rl   log_prob_norms      r!   _compute_lower_bound$GaussianMixture._compute_lower_boundN  s    r#   c                 ^    U R                   U R                  U R                  U R                  4$ r   )r   r   r   r   r   s    r!   _get_parametersGaussianMixture._get_parametersQ  s,    MMKK%%	
 	
r#   c                 V   Uu  U l         U l        U l        U l        U R                  R                  u  p#U R                  R
                  nU R                  S:X  aq  [        R                  " U R                  5      U l	        [        U R                  5       H2  u  pV[        R                  " XfR                  5      U R                  U'   M4     g U R                  S:X  a;  [        R                  " U R                  U R                  R                  5      U l	        g U R                  S-  U l	        g )Nr8   r;   r   )r   r   r   r   rB   r   r,   r   
empty_likeprecisions_re   rE   r/   )r   paramsrl   r&   r   rL   r   s          r!   _set_parametersGaussianMixture._set_parametersY  s     	
MK% ))))//6)!}}T-F-FGD )$*C*C D&(ffY&D  # !E !!V+!vv))4+D+D+F+F D  $88!;Dr#   c                    U R                   R                  u  pU R                  S:X  a  U R                  U-  US-   -  S-  nOWU R                  S:X  a  U R                  U-  nO7U R                  S:X  a  X"S-   -  S-  nOU R                  S:X  a  U R                  nX R                  -  n[	        WU-   U R                  -   S-
  5      $ )z2Return the number of free parameters in the model.r8   r   r   r<   r;   r=   )r   rB   r,   r    int)r   rl   r&   
cov_paramsmean_paramss        r!   _n_parametersGaussianMixture._n_parametersq  s    ))6)**Z7:>JSPJ!!V+**Z7J!!V+#A~6<J!![0**J #4#44:+d.?.??!CDDr#   c                     SU R                  U5      -  UR                  S   -  U R                  5       [        R                  " UR                  S   5      -  -   $ )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.

For an example of GMM selection using `bic` information criterion,
refer to :ref:`sphx_glr_auto_examples_mixture_plot_gmm_selection.py`.

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

Returns
-------
bic : float
    The lower the better.
r   )scorerB   r   r   rz   r   s     r!   bicGaussianMixture.bic  sR    & DJJqM!AGGAJ.1C1C1EGGAJI
 2
 
 	
r#   c                 r    SU R                  U5      -  UR                  S   -  SU R                  5       -  -   $ )aN  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   rB   r   r   s     r!   aicGaussianMixture.aic  s7      DJJqM!AGGAJ.T5G5G5I1IIIr#   )	r,   r   r   r   r   r   r   r   r   )r   )__name__
__module____qualname____firstlineno____doc__r	   r   r   dict__annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__)r   s   @r!   r   r     s    AF$

,
,$&'LMN%t,#T*($/$D  "/ !"/ "/H(&>
&

%
<0E
.J Jr#   r   )r   numpyr   scipyr   utilsr   utils._param_validationr   utils.extmathr   _baser	   r
   r"   r'   r-   r2   r6   r?   rN   rT   rW   rZ   ra   ro   rt   rw   r~   r   r   r   r#   r!   <module>r      s    
    0 % ,!H.P
7/l:8+2V.%"P7t'
/h%P;X|cJk cJr#   