
    -i%                         S r SSKrSSKJr  SSKrSSKJrJrJ	r	  SSK
Jr  SSKJrJr  SS	KJrJr  SS
KJrJrJrJrJrJr  S rS r " S S\5      rg)z Bayesian Gaussian Mixture Model.    N)Real)betalndigammagammaln   )check_array)Interval
StrOptions   )BaseMixture_check_shape)_check_precision_matrix_check_precision_positivity_compute_log_det_cholesky_compute_precision_cholesky_estimate_gaussian_parameters_estimate_log_gaussian_probc                     [        [        R                  " U 5      5      [        R                  " [        U 5      5      -
  $ )a2  Compute the log of the Dirichlet distribution normalization term.

Parameters
----------
dirichlet_concentration : array-like of shape (n_samples,)
    The parameters values of the Dirichlet distribution.

Returns
-------
log_dirichlet_norm : float
    The log normalization of the Dirichlet distribution.
)r   npsum)dirichlet_concentrations    T/var/www/html/venv/lib/python3.13/site-packages/sklearn/mixture/_bayesian_mixture.py_log_dirichlet_normr      s4     266123bff'(7      c           
          X-  X-  S-  [         R                  " S5      -  -   [        R                  " [	        SU [        R
                  " U5      SS2[        R                  4   -
  -  5      S5      -   * $ )a  Compute the log of the Wishart distribution normalization term.

Parameters
----------
degrees_of_freedom : array-like of shape (n_components,)
    The number of degrees of freedom on the covariance Wishart
    distributions.

log_det_precision_chol : array-like of shape (n_components,)
     The determinant of the precision matrix for each component.

n_features : int
    The number of features.

Return
------
log_wishart_norm : array-like of shape (n_components,)
    The log normalization of the Wishart distribution.
      ?       @Nr   )mathlogr   r   r   arangenewaxis)degrees_of_freedomlog_det_precisions_chol
n_featuress      r   _log_wishart_normr%   +   so    , 	4

)C
/$((3-
?	@
&&C-		*0Eam0TTUV
	
 r   c                   t  ^  \ rS rSr% Sr0 \R                  E\" 1 Sk5      /\" SS15      /S\" \	SSSS	9/S\" \	SSSS	9/SS
/S\" \	SSSS	9/SS
\" \	SSSS	9/S.Er\
\S'   SSSSSSSSSSSSSSSSSS.U 4S j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( rS) rS* rS+r U =r!$ ),BayesianGaussianMixtureJ   ai,  Variational Bayesian estimation of a Gaussian mixture.

This class allows to infer an approximate posterior distribution over the
parameters of a Gaussian mixture distribution. The effective number of
components can be inferred from the data.

This class implements two types of prior for the weights distribution: a
finite mixture model with Dirichlet distribution and an infinite mixture
model with the Dirichlet Process. In practice Dirichlet Process inference
algorithm is approximated and uses a truncated distribution with a fixed
maximum number of components (called the Stick-breaking representation).
The number of components actually used almost always depends on the data.

.. versionadded:: 0.18

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

Parameters
----------
n_components : int, default=1
    The number of mixture components. Depending on the data and the value
    of the `weight_concentration_prior` the model can decide to not use
    all the components by setting some component `weights_` to values very
    close to zero. The number of effective components is therefore smaller
    than n_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 on the likelihood (of the training data with
    respect to the model) 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 result with the highest
    lower bound value on the likelihood is kept.

init_params : {'kmeans', 'k-means++', 'random', 'random_from_data'},     default='kmeans'
    The method used to initialize the weights, the means and the
    covariances. 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.

weight_concentration_prior_type : {'dirichlet_process', 'dirichlet_distribution'},             default='dirichlet_process'
    String describing the type of the weight concentration prior.

weight_concentration_prior : float or None, default=None
    The dirichlet concentration of each component on the weight
    distribution (Dirichlet). This is commonly called gamma in the
    literature. The higher concentration puts more mass in
    the center and will lead to more components being active, while a lower
    concentration parameter will lead to more mass at the edge of the
    mixture weights simplex. The value of the parameter must be greater
    than 0. If it is None, it's set to ``1. / n_components``.

mean_precision_prior : float or None, default=None
    The precision prior on the mean distribution (Gaussian).
    Controls the extent of where means can be placed. Larger
    values concentrate the cluster means around `mean_prior`.
    The value of the parameter must be greater than 0.
    If it is None, it is set to 1.

mean_prior : array-like, shape (n_features,), default=None
    The prior on the mean distribution (Gaussian).
    If it is None, it is set to the mean of X.

degrees_of_freedom_prior : float or None, default=None
    The prior of the number of degrees of freedom on the covariance
    distributions (Wishart). If it is None, it's set to `n_features`.

covariance_prior : float or array-like, default=None
    The prior on the covariance distribution (Wishart).
    If it is None, the emiprical covariance prior is initialized using the
    covariance of X. The shape depends on `covariance_type`::

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

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.
    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 inference was reached, False otherwise.

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

lower_bound_ : float
    Lower bound value on the model evidence (of the training data) of the
    best fit of inference.

lower_bounds_ : array-like of shape (`n_iter_`,)
    The list of lower bound values on the model evidence from each iteration
    of the best fit of inference.

weight_concentration_prior_ : tuple or float
    The dirichlet concentration of each component on the weight
    distribution (Dirichlet). The type depends on
    ``weight_concentration_prior_type``::

        (float, float) if 'dirichlet_process' (Beta parameters),
        float          if 'dirichlet_distribution' (Dirichlet parameters).

    The higher concentration puts more mass in
    the center and will lead to more components being active, while a lower
    concentration parameter will lead to more mass at the edge of the
    simplex.

weight_concentration_ : array-like of shape (n_components,)
    The dirichlet concentration of each component on the weight
    distribution (Dirichlet).

mean_precision_prior_ : float
    The precision prior on the mean distribution (Gaussian).
    Controls the extent of where means can be placed.
    Larger values concentrate the cluster means around `mean_prior`.
    If mean_precision_prior is set to None, `mean_precision_prior_` is set
    to 1.

mean_precision_ : array-like of shape (n_components,)
    The precision of each components on the mean distribution (Gaussian).

mean_prior_ : array-like of shape (n_features,)
    The prior on the mean distribution (Gaussian).

degrees_of_freedom_prior_ : float
    The prior of the number of degrees of freedom on the covariance
    distributions (Wishart).

degrees_of_freedom_ : array-like of shape (n_components,)
    The number of degrees of freedom of each components in the model.

covariance_prior_ : float or array-like
    The prior on the covariance distribution (Wishart).
    The shape depends on `covariance_type`::

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

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
--------
GaussianMixture : Finite Gaussian mixture fit with EM.

References
----------

.. [1] `Bishop, Christopher M. (2006). "Pattern recognition and machine
   learning". Vol. 4 No. 4. New York: Springer.
   <https://www.springer.com/kr/book/9780387310732>`_

.. [2] `Hagai Attias. (2000). "A Variational Bayesian Framework for
   Graphical Models". In Advances in Neural Information Processing
   Systems 12.
   <https://citeseerx.ist.psu.edu/doc_view/pid/ee844fd96db7041a9681b5a18bff008912052c7e>`_

.. [3] `Blei, David M. and Michael I. Jordan. (2006). "Variational
   inference for Dirichlet process mixtures". Bayesian analysis 1.1
   <https://www.cs.princeton.edu/courses/archive/fall11/cos597C/reading/BleiJordan2005.pdf>`_

Examples
--------
>>> import numpy as np
>>> from sklearn.mixture import BayesianGaussianMixture
>>> X = np.array([[1, 2], [1, 4], [1, 0], [4, 2], [12, 4], [10, 7]])
>>> bgm = BayesianGaussianMixture(n_components=2, random_state=42).fit(X)
>>> bgm.means_
array([[2.49 , 2.29],
       [8.45, 4.52 ]])
>>> bgm.predict([[0, 0], [9, 3]])
array([0, 1])
>   diagfulltied	sphericaldirichlet_processdirichlet_distributionNg        neither)closedz
array-like)covariance_typeweight_concentration_prior_typeweight_concentration_priormean_precision_prior
mean_priordegrees_of_freedom_priorcovariance_prior_parameter_constraintsr   r*   gMbP?gư>d   kmeansFr   
   )n_componentsr1   tol	reg_covarmax_itern_initinit_paramsr2   r3   r4   r5   r6   r7   random_state
warm_startverboseverbose_intervalc                   > [         TU ]  UUUUUUUUUUS9
  X l        Xl        Xl        Xl        Xl        Xl        Xl        g )N)
r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   )	super__init__r1   r2   r3   r4   r5   r6   r7   )selfr<   r1   r=   r>   r?   r@   rA   r2   r3   r4   r5   r6   r7   rB   rC   rD   rE   	__class__s                     r   rH    BayesianGaussianMixture.__init__s  s`    * 	%#%!- 	 	
  //N,*D'$8!$(@% 0r   c                     U R                  5         U R                  U5        U R                  U5        U R                  U5        g)zsCheck that the parameters are well defined.

Parameters
----------
X : array-like of shape (n_samples, n_features)
N)_check_weights_parameters_check_means_parameters_check_precision_parameters _checkcovariance_prior_parameter)rI   Xs     r   _check_parameters)BayesianGaussianMixture._check_parameters  s:     	&&($$Q'((+--a0r   c                 j    U R                   c  SU R                  -  U l        gU R                   U l        g)z2Check the parameter of the Dirichlet distribution.N      ?)r3   r<   weight_concentration_prior_rI   s    r   rM   1BayesianGaussianMixture._check_weights_parameters  s/    **2/2T5F5F/FD,/3/N/ND,r   c                 P   UR                   u  p#U R                  c  SU l        OU R                  U l        U R                  c  UR	                  SS9U l        g[        U R                  [        R                  [        R                  /SS9U l        [        U R
                  U4S5        g)zzCheck the parameters of the Gaussian distribution.

Parameters
----------
X : array-like of shape (n_samples, n_features)
NrU   r   )axisFdtype	ensure_2dmeans)shaper4   mean_precision_prior_r5   meanmean_prior_r   r   float64float32r   rI   rQ   _r$   s       r   rN   /BayesianGaussianMixture._check_means_parameters  s     $$,),D&)-)B)BD&??" vv1v~D*

BJJ'?5 D ))J='Br   c                     UR                   u  p#U R                  c  X0l        gU R                  US-
  :  a  U R                  U l        g[        SUS-
  U R                  4-  5      e)zCheck the prior parameters of the precision distribution.

Parameters
----------
X : array-like of shape (n_samples, n_features)
NrU   zQThe parameter 'degrees_of_freedom_prior' should be greater than %d, but got %.3f.r   )r_   r6   degrees_of_freedom_prior_
ValueErrorre   s       r   rO   3BayesianGaussianMixture._check_precision_parameters  sl     ((0-7***Z#-==-1-J-JD*;>4#@#@AB r   c           	         UR                   u  p#U R                  c  [        R                  " [        R                  " UR
                  5      5      [        R                  " [        R                  " UR
                  5      5      [        R                  " USSS9[        R                  " USSS9R                  5       S.U R                     U l	        gU R                  S;   a~  [        U R                  [        R                  [        R                  /SS9U l	        [        U R                  X34S	U R                  -  5        [        U R                  U R                  5        gU R                  S
:X  a~  [        U R                  [        R                  [        R                  /SS9U l	        [        U R                  U4S	U R                  -  5        [        U R                  U R                  5        gU R                  U l	        g)zfCheck the `covariance_prior_`.

Parameters
----------
X : array-like of shape (n_samples, n_features)
Nr   r   )rZ   ddofr*   r+   r)   r,   )r*   r+   Fr[   z%s covariance_priorr)   )r_   r7   r   
atleast_2dcovTvarra   r1   covariance_prior_r   rc   rd   r   r   r   re   s       r   rP   8BayesianGaussianMixture._checkcovariance_prior_parameter  s      (bffQSSk2bffQSSk2qqq1VVAAA6;;=	&
 ""&$D" !!%55%0%%bjj"**-EQV&D" &&(%(<(<<
 $D$:$:D<P<PQ!!V+%0%%bjj"**-EQV&D" &&%(<(<<
 ((>(>@T@TU &*%:%:D"r   c                     [        XU R                  U R                  5      u  p4nU R                  U5        U R	                  X45        U R                  X4U5        g)zInitialization of the mixture parameters.

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

resp : array-like of shape (n_samples, n_components)
N)r   r>   r1   _estimate_weights_estimate_means_estimate_precisions)rI   rQ   respnkxksks         r   _initialize#BayesianGaussianMixture._initialize  sQ     3T^^T%9%9

 	r"R$!!""-r   c           
          U R                   S:X  aP  SU-   U R                  [        R                  " [        R                  " USSS2   5      SSS2   S45      -   4U l        gU R                  U-   U l        g)zwEstimate the parameters of the Dirichlet distribution.

Parameters
----------
nk : array-like of shape (n_components,)
r-   rU   Nr   )r2   rV   r   hstackcumsumweight_concentration_)rI   rz   s     r   rv   )BayesianGaussianMixture._estimate_weights  sw     //3FF b44ii2dd8!4RVV!<a @AB*D& *.)I)IB)ND&r   c                     U R                   U-   U l        U R                   U R                  -  USS2[        R                  4   U-  -   U R                  SS2[        R                  4   -  U l        g)zEstimate the parameters of the Gaussian distribution.

Parameters
----------
nk : array-like of shape (n_components,)

xk : array-like of shape (n_components, n_features)
N)r`   mean_precision_rb   r   r!   means_)rI   rz   r{   s      r   rw   'BayesianGaussianMixture._estimate_means)  sb      $99B>&&)9)99Bq"**}<MPR<RR  BJJ/0r   c                     U R                   U R                  U R                  U R                  S.U R                     " XU5        [        U R                  U R                  5      U l        g)a  Estimate the precisions parameters of the precision distribution.

Parameters
----------
nk : array-like of shape (n_components,)

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

sk : array-like
    The shape depends of `covariance_type`:
    'full' : (n_components, n_features, n_features)
    'tied' : (n_features, n_features)
    'diag' : (n_components, n_features)
    'spherical' : (n_components,)
rn   N)_estimate_wishart_full_estimate_wishart_tied_estimate_wishart_diag_estimate_wishart_sphericalr1   r   covariances_precisions_cholesky_)rI   rz   r{   r|   s       r   rx   ,BayesianGaussianMixture._estimate_precisions7  sj    " //////99		

 

	 
 !#	, %@t33%
!r   c                 .   UR                   u  pEU R                  U-   U l        [        R                  " U R
                  XU45      U l        [        U R
                  5       Hp  nX&   U R                  -
  nU R                  X   X6   -  -   X   U R                  -  U R                  U   -  [        R                  " Xw5      -  -   U R                  U'   Mr     U =R                  U R                  SS2[        R                  [        R                  4   -  sl        g)a  Estimate the full Wishart distribution parameters.

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

nk : array-like of shape (n_components,)

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

sk : array-like of shape (n_components, n_features, n_features)
N)r_   ri   degrees_of_freedom_r   emptyr<   r   rangerb   rs   r`   r   outerr!   )rI   rz   r{   r|   rf   r$   kdiffs           r   r   .BayesianGaussianMixture._estimate_wishart_fullR  s     
 $(#A#AB#F HHd&7&7%PQt(()A54+++D&&%"%- %,,-&&q)* ((4&'' a  * 	T55aRZZ6OPPr   c                    UR                   u  pEU R                  UR                  5       U R                  -  -   U l        X R
                  -
  nU R                  X1R                  5       -  U R                  -  -   U R                  U R                  -  [        R                  " XR                  -  UR                  -  U5      -  -   U l        U =R                  U R                  -  sl        g)a  Estimate the tied Wishart distribution parameters.

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

nk : array-like of shape (n_components,)

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

sk : array-like of shape (n_features, n_features)
N)r_   ri   r   r<   r   rb   rs   r`   r   dotr   rq   r   rI   rz   r{   r|   rf   r$   r   s          r   r   .BayesianGaussianMixture._estimate_wishart_tiedv  s      **RVVX8I8I-II 	  $$$""668md///0(( ffb///46694@AA 	 	T555r   c                    UR                   u  pEU R                  U-   U l        X R                  -
  nU R                  USS2[
        R                  4   UU R                  U R                  -  SS2[
        R                  4   [
        R                  " U5      -  -   -  -   U l
        U =R                  U R                  SS2[
        R                  4   -  sl
        g)a  Estimate the diag Wishart distribution parameters.

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

nk : array-like of shape (n_components,)

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

sk : array-like of shape (n_components, n_features)
N)r_   ri   r   rb   rs   r   r!   r`   r   squarer   r   s          r   r   .BayesianGaussianMixture._estimate_wishart_diag  s     
 $(#A#AB#F $$$ 22R2::5F))D,@,@@!RZZ-Piio6
 
 	T55amDDr   c           	      \   UR                   u  pEU R                  U-   U l        X R                  -
  nU R                  UUU R
                  U R                  -  [        R                  " [        R                  " U5      S5      -  -   -  -   U l
        U =R                  U R                  -  sl
        g)a  Estimate the spherical Wishart distribution parameters.

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

nk : array-like of shape (n_components,)

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

sk : array-like of shape (n_components,)
r   N)r_   ri   r   rb   rs   r`   r   r   ra   r   r   r   s          r   r   3BayesianGaussianMixture._estimate_wishart_spherical  s     
 $(#A#AB#F $$$ 22R((""#ggbiioq)**6
 
 	T555r   c                     UR                   u  p4[        U[        R                  " U5      U R                  U R
                  5      u  pVnU R                  U5        U R                  XV5        U R                  XVU5        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)	r_   r   r   expr>   r1   rv   rw   rx   )rI   rQ   log_resp	n_samplesrf   rz   r{   r|   s           r   _m_stepBayesianGaussianMixture._m_step  sg     ww	2rvvh1E1E

 	r"R$!!""-r   c                    U R                   S:X  a  [        U R                  S   U R                  S   -   5      n[        U R                  S   5      n[        U R                  S   5      nUU-
  [        R                  " S[        R
                  " X1-
  5      S S 45      -   $ [        U R                  5      [        [        R                  " U R                  5      5      -
  $ )Nr-   r   r   r   )r2   r   r   r   r   r   r   )rI   digamma_sum	digamma_a	digamma_bs       r   _estimate_log_weights-BayesianGaussianMixture._estimate_log_weights  s    //3FF!**1-0J0J10MMK   : :1 =>I : :1 =>I))Q		)*A B3B GHIJ 4556t112:  r   c                    UR                   u  p#[        XR                  U R                  U R                  5      SU-  [
        R                  " U R                  5      -  -
  nU[
        R                  " S5      -  [
        R                  " [        SU R                  [
        R                  " SU5      S S 2[
        R                  4   -
  -  5      S5      -   nUSXSU R                  -  -
  -  -   $ )Nr   r   r   )r_   r   r   r   r1   r   r   r   r   r   r    r!   r   )rI   rQ   rf   r$   	log_gauss
log_lambdas         r   _estimate_log_prob*BayesianGaussianMixture._estimate_log_prob  s     0{{D55t7K7K
*rvvd&>&>??@	  "&&+-++bii:.Fq"**}.UUW 1
 

 3*D<P<P/P"PQQQr   c                 F   U R                   R                  u  n[        U R                  U R                  U5      SU-  [
        R                  " U R                  5      -  -
  nU R                  S:X  a8  U R                  [
        R                  " [        U R                  XC5      5      -  nO*[
        R                  " [        U R                  XC5      5      nU R                  S:X  a<  [
        R                  " [        U R                  S   U R                  S   5      5      * nO[        U R                  5      n[
        R                  " [
        R                   " U5      U-  5      * U-
  U-
  SU-  [
        R                  " [
        R                  " U R"                  5      5      -  -
  $ )a  Estimate the lower bound of the model.

The lower bound on the likelihood (of the training data with respect to
the model) is used to detect the convergence and has to increase at
each iteration.

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

log_resp : array, shape (n_samples, n_components)
    Logarithm of the posterior probabilities (or responsibilities) of
    the point of each sample in X.

log_prob_norm : float
    Logarithm of the probability of each sample in X.

Returns
-------
lower_bound : float
r   r+   r-   r   r   )rb   r_   r   r   r1   r   r   r   r<   rc   r%   r   r2   r   r   r   r   r   )rI   r   log_prob_normr$   r#   log_wishartlog_norm_weights          r   _compute_lower_bound,BayesianGaussianMixture._compute_lower_bound  st   0 ((.. #<%%t';';Z#
*rvvd&>&>??#@ 6)++bjj!,,.E/ K &&!,,.EK //3FF!vvt11!4d6P6PQR6ST  O 2$2L2LMO VVBFF8$x/00 Jt/C/C(D!EEF	
r   c                     U R                   U R                  U R                  U R                  U R                  U R
                  4$ )N)r   r   r   r   r   r   rW   s    r   _get_parameters'BayesianGaussianMixture._get_parametersH  s@    &&  KK$$%%
 	
r   c           	         Uu  U l         U l        U l        U l        U l        U l        U R                  S:X  a  U R                   S   U R                   S   -   nU R                   S   U-  nU R                   S   U-  [        R                  " S[        R                  " US S 5      45      -  U l
        U =R                  [        R                  " U R                  5      -  sl
        O2U R                   [        R                  " U R                   5      -  U l
        U R                  S:X  aU  [        R                  " U R
                   Vs/ s H#  n[        R                  " XDR                  5      PM%     sn5      U l        g U R                  S:X  a;  [        R                  " U R
                  U R
                  R                  5      U l        g U R
                  S-  U l        g s  snf )Nr-   r   r   r   r*   r+   r   )r   r   r   r   r   r   r2   r   r   cumprodweights_r   r1   arrayr   rq   precisions_)rI   paramsweight_dirichlet_sumtmp	prec_chols        r   _set_parameters'BayesianGaussianMixture._set_parametersR  s    	
& K$% //3FF**1-0J0J10MM ! ,,Q/2FFC**1-&'))Q

3s8 4567 M
 MMRVVDMM22M 66**: DM
 6)!xx &*%>%>%>	 FF9kk2%> D !!V+!vv))4+D+D+F+F D  $88!;Ds   *G)r7   rs   r1   r   r   r6   ri   r   r4   r`   r5   rb   r   r   r   r   r3   rV   r2   r   )"__name__
__module____qualname____firstlineno____doc__r   r8   r
   r	   r   dict__annotations__rH   rR   rM   rN   rO   rP   r}   rv   rw   rx   r   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__)rJ   s   @r   r'   r'   J   s[   Rh$

,
,$&'LMN+-EFG,
 T3Y7'
 "&xc4	'R S\*%)8D#tI+V$WT3Y7
$D . (;#'!!%'(1 (1T
1OC,(';R."O*0
6"QH 6DE<6>.($R$9
v
)< )<r   r'   )r   r   numbersr   numpyr   scipy.specialr   r   r   utilsr   utils._param_validationr	   r
   _baser   r   _gaussian_mixturer   r   r   r   r   r   r   r%   r'    r   r   <module>r      sD    &
    2 2  : , $>q<k q<r   