ó
    §ñ:iùI  ã                   óÌ   • S r SSKrSSKJrJr  SSKJrJr  SSKJr  SSK	r
SSKJr  SSKJr  SS	KJrJr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SKJr  S r " S S\\\S9rg)zBase class for mixture models.é    N)ÚABCMetaÚabstractmethod)ÚIntegralÚReal)Útime)Ú	logsumexpé   )Úcluster)ÚBaseEstimatorÚDensityMixinÚ_fit_context)Úkmeans_plusplus)ÚConvergenceWarning)Úcheck_random_state)ÚIntervalÚ
StrOptions)Úcheck_is_fittedc                 ó’   • [         R                  " U 5      n U R                  U:w  a!  [        SU< SU< SU R                  < 35      eg)zyValidate the shape of the input parameter 'param'.

Parameters
----------
param : array

param_shape : tuple

name : str
zThe parameter 'z' should have the shape of z
, but got N)ÚnpÚarrayÚshapeÚ
ValueError)ÚparamÚparam_shapeÚnames      ÚX/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/sklearn/mixture/_base.pyÚ_check_shaper      s?   € ô �HŠH�U‹O€EØ‡{�{�kÓ!Ýã“[ %§+£+ð/ó
ð 	
ð "ó    c                   ó¢  • \ rS rSr% Sr\" \SSSS9/\" \SSSS9/\" \SSSS9/\" \SSSS9/\" \SSSS9/\" 1 S	k5      /S
/S/S/\" \SSSS9/S.
r	\
\S'   S r\S 5       rS r\S 5       rS(S jr\" SS9S(S j5       rS r\S 5       r\S 5       r\S 5       rS rS(S jrS rS rS)S jrS  r\S! 5       r\S" 5       rS# r S$ r!S% r"S& r#S'r$g)*ÚBaseMixtureé+   z™Base class for mixture models.

This abstract class specifies an interface for all mixture classes and
provides basic common methods for mixture models.
é   NÚleft)Úclosedg        r   >   ÚkmeansÚrandomÚrandom_from_dataú	k-means++Úrandom_stateÚbooleanÚverbose©
Ún_componentsÚtolÚ	reg_covarÚmax_iterÚn_initÚinit_paramsr)   Ú
warm_startr+   Úverbose_intervalÚ_parameter_constraintsc                 ó|   • Xl         X l        X0l        X@l        XPl        X`l        Xpl        X€l        X�l        X l	        g ©Nr,   )Úselfr-   r.   r/   r0   r1   r2   r)   r3   r+   r4   s              r   Ú__init__ÚBaseMixture.__init__A   s:   € ð )ÔØŒØ"ŒØ ŒØŒØ&ÔØ(ÔØ$ŒØŒØ 0Õr   c                 ó   • g)zwCheck initial parameters of the derived class.

Parameters
----------
X : array-like of shape  (n_samples, n_features)
N© ©r8   ÚXs     r   Ú_check_parametersÚBaseMixture._check_parametersY   ó   € ð 	r   c                 ó¬  • UR                   u  p4U R                  S:X  aw  [        R                  " X0R                  45      n[
        R                  " U R                  SUS9R                  U5      R                  nSU[        R                  " U5      U4'   GO-U R                  S:X  aA  UR                  X0R                  4S9nXUR                  SS9SS2[        R                  4   -  nOÜU R                  S:X  a`  [        R                  " X0R                  45      nUR                  X0R                  S	S
9nSXW[        R                  " U R                  5      4'   OlU R                  S:X  a\  [        R                  " X0R                  45      n[        UU R                  US9u  pGSXW[        R                  " U R                  5      4'   U R                  UW5        g)a  Initialize the model parameters.

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

random_state : RandomState
    A random number generator instance that controls the random seed
    used for the method chosen to initialize the parameters.
r%   r"   )Ú
n_clustersr1   r)   r&   ©Úsize©ÚaxisNr'   F)rE   Úreplacer(   )r)   )r   r2   r   Úzerosr-   r
   ÚKMeansÚfitÚlabels_ÚarangeÚuniformÚsumÚnewaxisÚchoicer   Ú_initialize)r8   r>   r)   Ú	n_samplesÚ_ÚrespÚlabelÚindicess           r   Ú_initialize_parametersÚ"BaseMixture._initialize_parametersc   s˜  € ð —w‘w‰ˆ	à×Ñ˜xÓ'Ü—8’8˜Y×(9Ñ(9Ð:Ó;ˆDä—’Ø#×0Ñ0¸Èñ÷ ‘�Q“ß‘ð ð 12ˆD”—’˜9Ó% uÐ,Ó-Ø×Ñ Ó)Ø×'Ñ'¨i×9JÑ9JÐ-KÐ'ÐLˆDØ—H‘H !�HÐ$¢Q¬¯
©
 ]Ñ3Ñ3‰DØ×ÑÐ!3Ó3Ü—8’8˜Y×(9Ñ(9Ð:Ó;ˆDØ"×)Ñ)Ø× 1Ñ 1¸5ð *ð ˆGð ;<ˆDœ"Ÿ)š) D×$5Ñ$5Ó6Ð6Ò7Ø×Ñ Ó,Ü—8’8˜Y×(9Ñ(9Ð:Ó;ˆDÜ(ØØ×!Ñ!Ø)ñ‰JˆAð
 ;<ˆDœ"Ÿ)š) D×$5Ñ$5Ó6Ð6Ñ7à×Ñ˜˜DÕ!r   c                 ó   • g)z´Initialize the model parameters of the derived class.

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

resp : array-like of shape (n_samples, n_components)
Nr<   )r8   r>   rU   s      r   rR   ÚBaseMixture._initializeŽ   s   € ð 	r   c                 ó(   • U R                  X5        U $ )aX  Estimate model parameters with the EM algorithm.

The method fits the model ``n_init`` times and sets the parameters with
which the model has the largest likelihood or lower bound. Within each
trial, the method iterates between E-step and M-step for ``max_iter``
times until the change of likelihood or lower bound is less than
``tol``, otherwise, a ``ConvergenceWarning`` is raised.
If ``warm_start`` is ``True``, then ``n_init`` is ignored and a single
initialization is performed upon the first call. Upon consecutive
calls, training starts where it left off.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    List of n_features-dimensional data points. Each row
    corresponds to a single data point.

y : Ignored
    Not used, present for API consistency by convention.

Returns
-------
self : object
    The fitted mixture.
)Úfit_predict©r8   r>   Úys      r   rK   ÚBaseMixture.fitš   s   € ð6 	×Ñ˜ÔØˆr   T)Úprefer_skip_nested_validationc                 ó¦  • U R                  U[        R                  [        R                  /SS9nUR                  S   U R
                  :  a(  [        SU R
                   SUR                  S    35      eU R                  U5        U R                  =(       a    [        U S5      (       + nU(       a  U R                  OSn[        R                  * nSU l        [        U R                  5      nUR                  u  px[        U5       GHL  n	U R!                  U	5        U(       a  U R#                  X5        U(       a  [        R                  * OU R$                  n
U R&                  S:X  a  U R)                  5       nSnMu  Sn[        SU R&                  S-   5       Hp  nU
nU R+                  U5      u  nnU R-                  UU5        U R/                  UU5      n
X¯-
  nU R1                  UU5        [3        U5      U R4                  :  d  Mn  S	n  O   U R7                  X­5        X¥:”  d  U[        R                  * :X  d  GM2  U
nU R)                  5       nWnXÐl        GMO     U R                  (       d+  U R&                  S:”  a  [8        R:                  " S
[<        5        U R?                  W5        WU l         XPl        U R+                  U5      u  nnURC                  SS9$ )a>  Estimate model parameters using X and predict the labels for X.

The method fits the model n_init times and sets the parameters with
which the model has the largest likelihood or lower bound. Within each
trial, the method iterates between E-step and M-step for `max_iter`
times until the change of likelihood or lower bound is less than
`tol`, otherwise, a :class:`~sklearn.exceptions.ConvergenceWarning` is
raised. After fitting, it predicts the most probable label for the
input data points.

.. versionadded:: 0.20

Parameters
----------
X : array-like of shape (n_samples, n_features)
    List of n_features-dimensional data points. Each row
    corresponds to a single data point.

y : Ignored
    Not used, present for API consistency by convention.

Returns
-------
labels : array, shape (n_samples,)
    Component labels.
r	   )ÚdtypeÚensure_min_samplesr   z:Expected n_samples >= n_components but got n_components = z, n_samples = Ú
converged_r"   FTzˆBest performing initialization did not converge. Try different init parameters, or increase max_iter, tol, or check for degenerate data.rF   )"Ú_validate_datar   Úfloat64Úfloat32r   r-   r   r?   r3   Úhasattrr1   Úinfre   r   r)   ÚrangeÚ_print_verbose_msg_init_begrX   Úlower_bound_r0   Ú_get_parametersÚ_e_stepÚ_m_stepÚ_compute_lower_boundÚ_print_verbose_msg_iter_endÚabsr.   Ú_print_verbose_msg_init_endÚwarningsÚwarnr   Ú_set_parametersÚn_iter_Úargmax)r8   r>   r_   Údo_initr1   Úmax_lower_boundr)   rS   rT   ÚinitÚlower_boundÚbest_paramsÚbest_n_iterÚ	convergedÚn_iterÚprev_lower_boundÚlog_prob_normÚlog_respÚchanges                      r   r]   ÚBaseMixture.fit_predict¸   sm  € ð8 ×Ñ ¬"¯*©*´b·j±jÐ)AÐVWÐÐXˆØ�7‰7�1‰:˜×)Ñ)Ó)Üð*Ø*.×*;Ñ*;Ð)<ð =Ø Ÿw™w q™z˜lð,óð ð
 	×Ñ˜qÔ!ð —‘×F¬7°4¸Ó+FÔGˆÞ '�—’¨QˆäŸ6™6˜'ˆØˆŒä)¨$×*;Ñ*;Ó<ˆà—w‘w‰ˆ	Ü˜&—MˆDØ×,Ñ,¨TÔ2æØ×+Ñ+¨AÔ<æ%,œ2Ÿ6™6™'°$×2CÑ2CˆKà�}‰} Ó!Ø"×2Ñ2Ó4�Ø’à!�	Ü# A t§}¡}°qÑ'8Ö9�FØ'2Ð$à.2¯l©l¸1«oÑ+�M 8Ø—L‘L  HÔ-Ø"&×";Ñ";¸HÀmÓ"T�Kà(Ñ;�FØ×4Ñ4°V¸VÔDä˜6“{ T§X¡XÕ-Ø$(˜	Ùñ :ð ×0Ñ0°ÔHàÓ0°OÌÏÉÀwÖ4NØ&1�OØ"&×"6Ñ"6Ó"8�KØ"(�KØ&/—OñC "ðL �� 4§=¡=°1Ó#4Ü�MŠMð9ô #ôð 	×Ñ˜[Ô)Ø"ˆŒØ+Ôð
 —l‘l 1“o‰ˆˆ8à�‰ AˆÐ&Ð&r   c                 óX   • U R                  U5      u  p#[        R                  " U5      U4$ )a`  E step.

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

Returns
-------
log_prob_norm : float
    Mean of the logarithms of the probabilities of each sample in X

log_responsibility : array, shape (n_samples, n_components)
    Logarithm of the posterior probabilities (or responsibilities) of
    the point of each sample in X.
)Ú_estimate_log_prob_respr   Úmean)r8   r>   rƒ   r„   s       r   ro   ÚBaseMixture._e_step"  s+   € ð  #'×">Ñ">¸qÓ"AÑˆÜ�wŠw�}Ó% xÐ/Ð/r   c                 ó   • g)zò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.
Nr<   )r8   r>   r„   s      r   rp   ÚBaseMixture._m_step5  s   € ð 	r   c                 ó   • g r7   r<   ©r8   s    r   rn   ÚBaseMixture._get_parametersC  ó   € àr   c                 ó   • g r7   r<   )r8   Úparamss     r   rw   ÚBaseMixture._set_parametersG  r�   r   c                 ój   • [        U 5        U R                  USS9n[        U R                  U5      SS9$ )aK  Compute the log-likelihood of each sample.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    List of n_features-dimensional data points. Each row
    corresponds to a single data point.

Returns
-------
log_prob : array, shape (n_samples,)
    Log-likelihood of each sample in `X` under the current model.
F©Úresetr"   rF   )r   rf   r   Ú_estimate_weighted_log_probr=   s     r   Úscore_samplesÚBaseMixture.score_samplesK  s9   € ô 	˜ÔØ×Ñ ¨ÐÐ/ˆä˜×9Ñ9¸!Ó<À1ÑEÐEr   c                 ó@   • U R                  U5      R                  5       $ )a—  Compute the per-sample average log-likelihood of the given data X.

Parameters
----------
X : array-like of shape (n_samples, n_dimensions)
    List of n_features-dimensional data points. Each row
    corresponds to a single data point.

y : Ignored
    Not used, present for API consistency by convention.

Returns
-------
log_likelihood : float
    Log-likelihood of `X` under the Gaussian mixture model.
)r˜   r‰   r^   s      r   ÚscoreÚBaseMixture.score^  s   € ð" ×!Ñ! !Ó$×)Ñ)Ó+Ð+r   c                 ót   • [        U 5        U R                  USS9nU R                  U5      R                  SS9$ )a4  Predict the labels for the data samples in X using trained model.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    List of n_features-dimensional data points. Each row
    corresponds to a single data point.

Returns
-------
labels : array, shape (n_samples,)
    Component labels.
Fr•   r"   rF   )r   rf   r—   ry   r=   s     r   ÚpredictÚBaseMixture.predictq  s@   € ô 	˜ÔØ×Ñ ¨ÐÐ/ˆØ×/Ñ/°Ó2×9Ñ9¸qÐ9ÐAÐAr   c                 óŠ   • [        U 5        U R                  USS9nU R                  U5      u  p#[        R                  " U5      $ )aV  Evaluate the components' density for each sample.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    List of n_features-dimensional data points. Each row
    corresponds to a single data point.

Returns
-------
resp : array, shape (n_samples, n_components)
    Density of each Gaussian component for each sample in X.
Fr•   )r   rf   rˆ   r   Úexp)r8   r>   rT   r„   s       r   Úpredict_probaÚBaseMixture.predict_probaƒ  sB   € ô 	˜ÔØ×Ñ ¨ÐÐ/ˆØ×2Ñ2°1Ó5‰ˆÜ�vŠv�hÓÐr   c                 ór  • [        U 5        US:  a  [        SU R                  -  5      eU R                  R                  u  p#[        U R                  5      nUR                  XR                  5      nU R                  S:X  ag  [        R                  " [        U R                  U R                  U5       VVVs/ s H!  u  pgnUR                  Xg[        U5      5      PM#     snnn5      n	OèU R                  S:X  ac  [        R                  " [        U R                  U5       VVs/ s H*  u  phUR                  X`R                  [        U5      5      PM,     snn5      n	Ou[        R                  " [        U R                  U R                  U5       VVVs/ s H0  u  pgnUUR!                  Xƒ4S9[        R"                  " U5      -  -   PM2     snnn5      n	[        R$                  " ['        U5       V
Vs/ s H  u  p¨[        R(                  " XŠ[        S9PM      snn
5      nX›4$ s  snnnf s  snnf s  snnnf s  snn
f )a!  Generate random samples from the fitted Gaussian distribution.

Parameters
----------
n_samples : int, default=1
    Number of samples to generate.

Returns
-------
X : array, shape (n_samples, n_features)
    Randomly generated sample.

y : array, shape (nsamples,)
    Component labels.
r"   zNInvalid value for 'n_samples': %d . The sampling requires at least one sample.ÚfullÚtiedrD   )rc   )r   r   r-   Úmeans_r   r   r)   ÚmultinomialÚweights_Úcovariance_typer   ÚvstackÚzipÚcovariances_Úmultivariate_normalÚintÚstandard_normalÚsqrtÚconcatenateÚ	enumerater¥   )r8   rS   rT   Ú
n_featuresÚrngÚn_samples_compr‰   Ú
covarianceÚsampler>   Újr_   s               r   r¸   ÚBaseMixture.sample–  sú  € ô  	˜Ôà�q‹=Üð$Ø'+×'8Ñ'8ñ:óð ð
 Ÿ™×)Ñ)‰ˆÜ  ×!2Ñ!2Ó3ˆØŸ™¨·M±MÓBˆà×Ñ 6Ó)Ü—	’	ô 7:ØŸ™ T×%6Ñ%6¸ô7õò7Ñ2˜¨6ð ×+Ñ+¨D¼cÀ&»kÖJñ7óó‰Að ×!Ñ! VÓ+Ü—	’	ô +.¨d¯k©k¸>Ô*Jôâ*J™˜ð ×+Ñ+¨D×2CÑ2CÄSÈÃ[ÖQÙ*Jòó‰Aô —	’	ô
 7:ØŸ™ T×%6Ñ%6¸ô7õ	ò7Ñ2˜¨6ð Ø×)Ñ)°Ð/CÐ)ÐDÜ—g’g˜jÓ)ñ*ô*ñ7ó	ó	ˆAô �NŠNÜ<EÀnÔ<UÔVÒ<U©y¨qŒR�WŠW�V¤cÔ*Ñ<UÒVó
ˆð ˆvˆùô=ùóùôùó Ws   Â7(HÄ"1H&
Æ7H,Ç/%H3
c                 óF   • U R                  U5      U R                  5       -   $ )z×Estimate the weighted log-probabilities, log P(X | Z) + log weights.

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

Returns
-------
weighted_log_prob : array, shape (n_samples, n_component)
)Ú_estimate_log_probÚ_estimate_log_weightsr=   s     r   r—   Ú'BaseMixture._estimate_weighted_log_probÔ  s#   € ð ×&Ñ& qÓ)¨D×,FÑ,FÓ,HÑHÐHr   c                 ó   • g)zEstimate log-weights in EM algorithm, E[ log pi ] in VB algorithm.

Returns
-------
log_weight : array, shape (n_components, )
Nr<   rŽ   s    r   r½   Ú!BaseMixture._estimate_log_weightsá  rA   r   c                 ó   • g)zùEstimate the log-probabilities log P(X | Z).

Compute the log-probabilities per each component for each sample.

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

Returns
-------
log_prob : array, shape (n_samples, n_component)
Nr<   r=   s     r   r¼   ÚBaseMixture._estimate_log_probë  s   € ð 	r   c                 óÒ   • U R                  U5      n[        USS9n[        R                  " SS9   X#SS2[        R                  4   -
  nSSS5        X44$ ! , (       d  f       UW4$ = f)aØ  Estimate log probabilities and responsibilities for each sample.

Compute the log probabilities, weighted log probabilities per
component and responsibilities for each sample in X with respect to
the current state of the model.

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

Returns
-------
log_prob_norm : array, shape (n_samples,)
    log p(X)

log_responsibilities : array, shape (n_samples, n_components)
    logarithm of the responsibilities
r"   rF   Úignore)ÚunderN)r—   r   r   ÚerrstaterP   )r8   r>   Úweighted_log_probrƒ   r„   s        r   rˆ   Ú#BaseMixture._estimate_log_prob_respû  si   € ð& !×<Ñ<¸QÓ?ÐÜ!Ð"3¸!Ñ<ˆÜ�[Š[˜xÓ(à(º¼B¿J¹J¸Ñ+GÑGˆH÷ )ð Ð&Ð&÷ )Ô(ð ˜hÐ&Ð&ús   °AÁ
A&c                 óÀ   • U R                   S:X  a  [        SU-  5        gU R                   S:¼  a/  [        SU-  5        [        5       U l        U R                  U l        gg)ú(Print verbose message on initialization.r"   zInitialization %dr	   N)r+   Úprintr   Ú_init_prev_timeÚ_iter_prev_time)r8   r1   s     r   rl   Ú'BaseMixture._print_verbose_msg_init_beg  sS   € à�<‰<˜1ÓÜÐ%¨Ñ.Õ/Ø�\‰\˜QÓÜÐ%¨Ñ.Ô/Ü#'£6ˆDÔ Ø#'×#7Ñ#7ˆDÕ ð r   c                 óä   • XR                   -  S:X  a^  U R                  S:X  a  [        SU-  5        gU R                  S:¼  a.  [        5       n[        SXU R                  -
  U4-  5        X0l        ggg)rÊ   r   r"   z  Iteration %dr	   z0  Iteration %d	 time lapse %.5fs	 ll change %.5fN)r4   r+   rË   r   rÍ   )r8   r�   Údiff_llÚcur_times       r   rr   Ú'BaseMixture._print_verbose_msg_iter_end  sv   € à×)Ñ)Ñ)¨QÓ.Ø�|‰|˜qÓ ÜÐ&¨Ñ/Õ0Ø—‘ Ó"Ü›6�ÜØHØ¨$×*>Ñ*>Ñ>ÀÐHñIôð (0Õ$ð #ð /r   c           	      óØ   • U(       a  SOSnU R                   S:X  a  [        SU S35        g
U R                   S:¼  a/  [        5       U R                  -
  n[        SU SUS S	US S35        g
g
)z.Print verbose message on the end of iteration.r€   zdid not converger"   zInitialization Ú.r	   z. time lapse z.5fzs	 lower bound N)r+   rË   r   rÌ   )r8   ÚlbÚinit_has_convergedÚconverged_msgÚts        r   rt   Ú'BaseMixture._print_verbose_msg_init_end+  sw   € æ'9™Ð?QˆØ�<‰<˜1ÓÜ�O M ?°!Ð4Õ5Ø�\‰\˜QÓÜ“˜×-Ñ-Ñ-ˆAÜØ! - °¸aÀ¸Wð EØ�s�8˜1ðõð r   )rÌ   rÍ   re   r2   rm   r0   r-   r1   rx   r)   r/   r.   r+   r4   r3   r7   )r"   )%Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   r5   ÚdictÚ__annotations__r9   r   r?   rX   rR   rK   r   r]   ro   rp   rn   rw   r˜   r›   rž   r¢   r¸   r—   r½   r¼   rˆ   rl   rr   rt   Ú__static_attributes__r<   r   r   r    r    +   s‘  ‡ ññ " (¨A¨t¸FÑCÐDÙ˜˜s D°Ñ8Ð9Ù˜t S¨$°vÑ>Ð?Ù˜h¨¨4¸Ñ?Ð@Ù˜H a¨°fÑ=Ð>áÒLÓMð
ð (Ð(Ø �kØ�;Ù% h°°4ÀÑGÐHñ$Ð˜Dó ò1ð0 ñó ðò)"ðV ñ	ó ð	ôñ< °Ñ5óg'ó 6ðg'òR0ð& ñó ðð ñó ðð ñó ðòFô&,ò&Bò$ ô&<ò|Ið ñó ðð ñó ðò'ò48ò0õ
r   r    )Ú	metaclass)rÞ   ru   Úabcr   r   Únumbersr   r   r   Únumpyr   Úscipy.specialr   Ú r
   Úbaser   r   r   r   Ú
exceptionsr   Úutilsr   Úutils._param_validationr   r   Úutils.validationr   r   r    r<   r   r   Ú<module>rí      sK   ðÙ $ó ß 'ß "Ý ã Ý #å ß <Ñ <Ý %Ý +Ý &ß :Ý .ò
ô&J�, ¸ó Jr   