Ë
    ÷Q(hÃ@ ã                   óx  — d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
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mZmZmZ dd
lmZ ddlmZmZmZmZ ddl m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z'm(Z(m)Z) ddl*m+Z+m,Z,m-Z- ddl.m/Z/  ej`                  ejb                  «      jd                  Z3d„ Z4d„ Z5d„ Z6d3d„Z7d„ Z8d„ Z9d4d„Z:d„ Z;	 	 	 	 	 	 	 	 	 	 d5d„Z<	 	 	 	 d6d„Z=	 d7d „Z>	 	 	 	 	 	 	 	 	 d8d"„Z? e#d#d$gd#dgd#dgd%gd&œd¬'«      	 	 	 d9ddd(d!ddd)d*d)dddd+œd,„«       Z@ G d-„ d.eeee«      ZA G d/„ d0eA«      ZB G d1„ d2eA«      ZCy):z"Non-negative matrix factorization.é    N)ÚABC)Úsqrt)ÚIntegralÚReal)Úlinalgé   )Úconfig_context)ÚBaseEstimatorÚClassNamePrefixFeaturesOutMixinÚTransformerMixinÚ_fit_context)ÚConvergenceWarning)Úcheck_arrayÚcheck_random_stateÚgen_batchesÚmetadata_routing)ÚIntervalÚ
StrOptionsÚvalidate_params)Ú"_deprecate_Xt_in_inverse_transform)Úrandomized_svdÚsafe_sparse_dotÚsquared_norm)Úcheck_is_fittedÚcheck_non_negativeÚvalidate_dataé   )Ú_update_cdnmf_fastc                 ó*   — t        t        | «      «      S )zØDot product-based Euclidean norm implementation.

    See: http://fa.bianp.net/blog/2011/computing-the-vector-norm/

    Parameters
    ----------
    x : array-like
        Vector for which to compute the norm.
    )r   r   )Úxs    úX/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/decomposition/_nmf.pyÚnormr"   +   s   € ô ”˜Q“Ó Ð ó    c                 óf   — t        j                  | j                  «       |j                  «       «      S )z�Trace of np.dot(X, Y.T).

    Parameters
    ----------
    X : array-like
        First matrix.
    Y : array-like
        Second matrix.
    )ÚnpÚdotÚravel)ÚXÚYs     r!   Ú	trace_dotr*   8   s!   € ô �6‰6�!—'‘'“)˜QŸW™W›YÓ'Ð'r#   c           	      óˆ  — t        | «      } |d   dk7  r:| j                  d   |d   k7  r%t        d|› d|d   › d| j                  d   › d�«      ‚|d   dk7  r:| j                  d   |d   k7  r%t        d|› d|d   › d| j                  d   › d�«      ‚t        | |«       t	        j
                  | «      dk(  rt        d	|› d
�«      ‚y )Nr   Úautoz+Array with wrong first dimension passed to z. Expected z
, but got ú.r   z,Array with wrong second dimension passed to zArray passed to z is full of zeros.)r   ÚshapeÚ
ValueErrorr   r%   Úmax)ÚAr.   Úwhoms      r!   Ú_check_initr3   E   só   € Ü�A‹€AØˆQ�x�6Ò˜aŸg™g a™j¨E°!©HÒ4ÜØ9¸$¸¸{È5ÐQRÉ8È*ð UØ—w‘w˜q‘z�l !ð%ó
ð 	
ð ˆQ�x�6Ò˜aŸg™g a™j¨E°!©HÒ4ÜØ:¸4¸&ÀÈEÐRSÉHÈ:ð VØ—w‘w˜q‘z�l !ð%ó
ð 	
ô �q˜$ÔÜ	‡v�vˆaƒy�A‚~ÜÐ+¨D¨6Ð1CÐDÓEÐEð r#   Fc           
      ó~  — t        |«      }t        j                  | «      st        j                  | «      } t        j                  |«      }t        j                  |«      }|dk(  rÞt        j                  | «      rˆt        j
                  | j                  | j                  «      }t        t        j                  j                  |j                  ||g«      |«      }t        | |j                  z  |«      }||z   d|z  z
  dz  }n%t        | t        j
                  ||«      z
  «      dz  }|rt        j                  |dz  «      S |S t        j                  | «      r$t        ||| «      j                  }	| j                  }
n6t        j
                  ||«      }|j                  «       }	| j                  «       }
|
t        kD  }|	|   }	|
|   }
t        |	|	t        k  <   |dk(  r†t        j
                  t        j                   |d¬«      t        j                   |d¬«      «      }|
|	z  }t        j
                  |
t        j"                  |«      «      }|||
j!                  «       z
  z  }�n7|dk(  rd|
|	z  }t        j                   |«      t        j$                  | j&                  «      z
  t        j                   t        j"                  |«      «      z
  }nÎt        j                  | «      rVd}t)        | j&                  d   «      D ]8  }|t        j                   t        j
                  ||dd…|f   «      |z  «      z  }Œ: nt        j                   |z  «      }t        j
                  |
|	|dz
  z  «      }|
|z  j!                  «       ||z  z
  }|||dz
  z  z  }|||dz
  z  z  }|r$t+        |d«      }t        j                  d|z  «      S |S )ak  Compute the beta-divergence of X and dot(W, H).

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

    W : float or array-like of shape (n_samples, n_components)

    H : float or array-like of shape (n_components, n_features)

    beta : float or {'frobenius', 'kullback-leibler', 'itakura-saito'}
        Parameter of the beta-divergence.
        If beta == 2, this is half the Frobenius *squared* norm.
        If beta == 1, this is the generalized Kullback-Leibler divergence.
        If beta == 0, this is the Itakura-Saito divergence.
        Else, this is the general beta-divergence.

    square_root : bool, default=False
        If True, return np.sqrt(2 * res)
        For beta == 2, it corresponds to the Frobenius norm.

    Returns
    -------
        res : float
            Beta divergence of X and np.dot(X, H).
    r   ç       @r   r   ©ÚaxisN)Ú_beta_loss_to_floatÚspÚissparser%   Ú
atleast_2dr&   Údatar*   r   Ú	multi_dotÚTr   r   Ú_special_sparse_dotr'   ÚEPSILONÚsumÚlogÚprodr.   Úranger0   )r(   ÚWÚHÚbetaÚsquare_rootÚnorm_XÚnorm_WHÚ
cross_prodÚresÚWH_dataÚX_dataÚWHÚindicesÚsum_WHÚdivÚsum_WH_betaÚiÚsum_X_WHs                     r!   Ú_beta_divergencerV   V   s  € ô6 ˜tÓ$€Dô �;‰;�qŒ>Ü�M‰M˜!ÓˆÜ
�‰�aÓ€AÜ
�‰�aÓ€Að ˆq‚yä�;‰;�qŒ>Ü—V‘V˜AŸF™F A§F¡FÓ+ˆFÜ¤§	¡	× 3Ñ 3°Q·S±S¸!¸Q°KÓ @À!ÓDˆGÜ" A¨¯©¡G¨aÓ0ˆJØ˜GÑ# c¨JÑ&6Ñ6¸#Ñ=‰Cä˜q¤2§6¡6¨!¨Q£<Ñ/Ó0°3Ñ6ˆCáÜ—7‘7˜3 ™7Ó#Ð#àˆJä	‡{�{�1„~ä% a¨¨AÓ.×3Ñ3ˆØ—‘‰ä�V‰V�A�q‹\ˆØ—(‘(“*ˆØ—‘“ˆð ”wÑ€GØ�gÑ€GØ�G‰_€Fô ")€GˆG”gÑÑð ˆq‚yä—‘œŸ™˜q qÔ)¬2¯6©6°!¸!Ô+<Ó=ˆà�wÑˆÜ�f‰f�VœRŸV™V C›[Ó)ˆàˆv˜Ÿ
™
›Ñ$Ñ$Šð 
�ŠØ�wÑˆÜ�f‰f�S‹kœBŸG™G A§G¡GÓ,Ñ,¬r¯v©v´b·f±f¸S³kÓ/BÑB‰ô �;‰;�qŒ>ð ˆKÜ˜1Ÿ7™7 1™:Ó&ò B�ØœrŸv™v¤b§f¡f¨Q°²!°Q°$±Ó&8¸DÑ&@ÓAÑA‘ñBô Ÿ&™&  T¡Ó*ˆKä—6‘6˜& '¨d°Q©hÑ"7Ó8ˆØ�t‰|× Ñ Ó" T¨H¡_Ñ4ˆØˆ{˜d Q™hÑ'Ñ'ˆØˆt�t˜a‘xÑ Ñ ˆáÜ�#�q‹kˆÜ�w‰w�q˜3‘wÓÐàˆ
r#   c                 ó<  — t        j                  |«      rò|j                  «       \  }}|j                  d   }t	        j
                  |«      }| j                  d   }t        |||z  «      }t        d||«      D ]X  }	t        |	|	|z   «      }
t	        j                  | ||
   dd…f   |j                  ||
   dd…f   «      j                  d¬«      ||
<   ŒZ t        j                  |||ff|j                  ¬«      }|j                  «       S t	        j                  | |«      S )z0Computes np.dot(W, H), only where X is non zero.r   r   Nr6   )r.   )r9   r:   Únonzeror.   r%   Úemptyr0   rD   ÚsliceÚmultiplyr>   rA   Ú
coo_matrixÚtocsrr&   )rE   rF   r(   ÚiiÚjjÚn_valsÚdot_valsÚn_componentsÚ
batch_sizeÚstartÚbatchrO   s               r!   r?   r?   Á   sþ   € ä	‡{�{�1„~Ø—‘“‰ˆˆBØ—‘˜!‘ˆÜ—8‘8˜FÓ#ˆØ—w‘w˜q‘zˆä˜ v°Ñ'=Ó>ˆ
Ü˜1˜f jÓ1ò 	ˆEÜ˜% ¨Ñ!3Ó4ˆEÜ Ÿk™k¨!¨B¨u©I²q¨L©/¸1¿3¹3¸rÀ%¹yÊ!¸|Ñ;LÓM×QÑQØð Ró ˆH�UŠOð	ô �]‰]˜H r¨2 hÐ/°q·w±wÔ?ˆØ�x‰x‹zÐä�v‰v�a˜‹|Ðr#   c                 ó<   — ddddœ}t        | t        «      r||    } | S )z"Convert string beta_loss to float.r   r   r   )Ú	frobeniusúkullback-leiblerúitakura-saito)Ú
isinstanceÚstr)Ú	beta_lossÚbeta_loss_maps     r!   r8   r8   Ö   s(   € à"#¸ÈQÑO€MÜ�)œSÔ!Ø! )Ñ,ˆ	ØÐr#   c           
      óà  — t        | d«       | j                  \  }}|�.|dk7  r)|t        ||«      kD  rt        dj	                  |«      «      ‚|€|t        ||«      k  rd}nd}|dk(  rÇt        j                  | j                  «       |z  «      }t        |«      }||j                  ||f¬«      j                  | j                  d¬«      z  }	||j                  ||f¬«      j                  | j                  d¬«      z  }
t        j                  |	|	¬	«       t        j                  |
|
¬	«       |
|	fS t        | ||¬
«      \  }}}t        j                  |«      }
t        j                  |«      }	t        j                  |d   «      t        j                  |dd…df   «      z  |
dd…df<   t        j                  |d   «      t        j                  |ddd…f   «      z  |	ddd…f<   t        d|«      D �]  }|dd…|f   ||dd…f   }}t        j                   |d«      t        j                   |d«      }}t        j                  t        j"                  |d«      «      t        j                  t        j"                  |d«      «      }}t%        |«      t%        |«      }}t%        |«      t%        |«      }}||z  ||z  }}||kD  r||z  }||z  }|}n||z  }||z  }|}t        j                  ||   |z  «      }||z  |
dd…|f<   ||z  |	|dd…f<   �Œ d|
|
|k  <   d|	|	|k  <   |dk(  r	 |
|	fS |dk(  r$| j                  «       }||
|
dk(  <   ||	|	dk(  <   |
|	fS |dk(  r‹t        |«      }| j                  «       }t        ||j                  t'        |
|
dk(     «      ¬«      z  dz  «      |
|
dk(  <   t        ||j                  t'        |	|	dk(     «      ¬«      z  dz  «      |	|	dk(  <   |
|	fS t        d|›dd›�«      ‚)aN  Algorithms for NMF initialization.

    Computes an initial guess for the non-negative
    rank k matrix approximation for X: X = WH.

    Parameters
    ----------
    X : array-like of shape (n_samples, n_features)
        The data matrix to be decomposed.

    n_components : int
        The number of components desired in the approximation.

    init :  {'random', 'nndsvd', 'nndsvda', 'nndsvdar'}, default=None
        Method used to initialize the procedure.
        Valid options:

        - None: 'nndsvda' if n_components <= min(n_samples, n_features),
            otherwise 'random'.

        - 'random': non-negative random matrices, scaled with:
            sqrt(X.mean() / n_components)

        - 'nndsvd': Nonnegative Double Singular Value Decomposition (NNDSVD)
            initialization (better for sparseness)

        - 'nndsvda': NNDSVD with zeros filled with the average of X
            (better when sparsity is not desired)

        - 'nndsvdar': NNDSVD with zeros filled with small random values
            (generally faster, less accurate alternative to NNDSVDa
            for when sparsity is not desired)

        - 'custom': use custom matrices W and H

        .. versionchanged:: 1.1
            When `init=None` and n_components is less than n_samples and n_features
            defaults to `nndsvda` instead of `nndsvd`.

    eps : float, default=1e-6
        Truncate all values less then this in output to zero.

    random_state : int, RandomState instance or None, default=None
        Used when ``init`` == 'nndsvdar' or 'random'. Pass an int for
        reproducible results across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    W : array-like of shape (n_samples, n_components)
        Initial guesses for solving X ~= WH.

    H : array-like of shape (n_components, n_features)
        Initial guesses for solving X ~= WH.

    References
    ----------
    C. Boutsidis, E. Gallopoulos: SVD based initialization: A head start for
    nonnegative matrix factorization - Pattern Recognition, 2008
    http://tinyurl.com/nndsvd
    zNMF initializationNÚrandomzLinit = '{}' can only be used when n_components <= min(n_samples, n_features)Únndsvda)ÚsizeF)Úcopy©Úout)Úrandom_stater   r   ÚnndsvdÚnndsvdaréd   zInvalid init parameter: got z instead of one of )Nro   rv   rp   rw   )r   r.   Úminr/   Úformatr%   r   Úmeanr   Ústandard_normalÚastypeÚdtypeÚabsr   Ú
zeros_likerD   ÚmaximumÚminimumr"   Úlen)r(   rb   ÚinitÚepsru   Ú	n_samplesÚ
n_featuresÚavgÚrngrF   rE   ÚUÚSÚVÚjr    ÚyÚx_pÚy_pÚx_nÚy_nÚx_p_nrmÚy_p_nrmÚx_n_nrmÚy_n_nrmÚm_pÚm_nÚuÚvÚsigmaÚlbds                                  r!   Ú_initialize_nmfr�   Þ   s  € ô| �qÐ.Ô/ØŸG™GÑ€Iˆzð 	ÐØ�HÒØœ3˜y¨*Ó5Ò5äð9ß9?¹À»ó
ð 	
ð
 €|Øœ3˜y¨*Ó5Ò5Ø‰DàˆDð ˆxÒÜ�g‰g�a—f‘f“h Ñ-Ó.ˆÜ  Ó.ˆØ�#×%Ñ%¨L¸*Ð+EÐ%ÓF×MÑMØ�G‰G˜%ð Nó 
ñ 
ˆð �#×%Ñ%¨I°|Ð+DÐ%ÓE×LÑLØ�G‰G˜%ð Mó 
ñ 
ˆô 	�‰ˆq�aÕÜ
�‰ˆq�aÕØ�!ˆtˆô ˜Q ¸<ÔH�G€A€qˆ!Ü
�‰�aÓ€AÜ
�‰�aÓ€Aô �g‰g�a˜‘d‹mœbŸf™f Q¢q¨! t¡W›oÑ-€A‚aˆ€d�GÜ�g‰g�a˜‘d‹mœbŸf™f Q qª! t¡W›oÑ-€A€aŠ€d�Gä�1�lÓ#ó ˆØ’�A�‰w˜˜!šQ˜$™ˆ1ˆô —:‘:˜a Ó#¤R§Z¡Z°°1Ó%5ˆSˆÜ—6‘6œ"Ÿ*™* Q¨Ó*Ó+¬R¯V©V´B·J±J¸qÀ!Ó4DÓ-EˆSˆô   ›9¤d¨3£i�ˆÜ ›9¤d¨3£i�ˆà˜WÑ$ g°Ñ&7ˆSˆð �Š9Ø�g‘ˆAØ�g‘ˆAØ‰Eà�g‘ˆAØ�g‘ˆAØˆEä�g‰g�a˜‘d˜U‘lÓ#ˆØ˜‘'ˆŠ!ˆQˆ$‰Ø˜‘'ˆˆ!ŠQˆ$‹ð3ð6 €A€aˆ#�g�JØ€A€aˆ#�g�JàˆxÒØð  ˆaˆ4€Kð 
�Ò	Ø�f‰f‹hˆØˆˆ!ˆq‰&‰	Øˆˆ!ˆq‰&‰	ð ˆaˆ4€Kð 
�Ò	Ü  Ó.ˆØ�f‰f‹hˆÜ˜˜c×1Ñ1´s¸1¸QÀ!¹V¹9³~Ð1ÓFÑFÈÑLÓMˆˆ!ˆq‰&‰	Ü˜˜c×1Ñ1´s¸1¸QÀ!¹V¹9³~Ð1ÓFÑFÈÑLÓMˆˆ!ˆq‰&‰	ð ˆaˆ4€Kõ âÑFðHó
ð 	
r#   c                 óˆ  — |j                   d   }t        j                  |j                  |«      }t	        | |«      }	|dk7  r|j
                  dd|dz   …xx   |z  cc<   |dk7  r|	|z  }	|r|j                  |«      }
nt        j                  |«      }
t        j                  |
t        j                  ¬«      }
t        |||	|
«      S )zåHelper function for _fit_coordinate_descent.

    Update W to minimize the objective function, iterating once over all
    coordinates. By symmetry, to update H, one can call
    _update_coordinate_descent(X.T, Ht, W, ...).

    r   ç        N©r~   )r.   r%   r&   r>   r   ÚflatÚpermutationÚarangeÚasarrayÚintpr   )r(   rE   ÚHtÚl1_regÚl2_regÚshuffleru   rb   ÚHHtÚXHtr¢   s              r!   Ú_update_coordinate_descentr¬   y  s¯   € ð —8‘8˜A‘;€Lä
�&‰&�—‘�rÓ
€CÜ
˜!˜RÓ
 €Cð �‚}à�‰Ñ$�L 1Ñ$Ð$Ó%¨Ñ/Ó%à�‚}Øˆv‰ˆáØ"×.Ñ.¨|Ó<‰ä—i‘i Ó-ˆä—*‘*˜[´·±Ô8€KÜ˜a  c¨;Ó7Ð7r#   ç-Cëâ6?éÈ   Tc                 ó†  — t        |j                  d¬«      }t        | d¬«      } t        |«      }t        d|dz   «      D ]r  }d}|t	        | ||||||«      z  }|	r|t	        | j                  ||||||«      z  }|dk(  r|}dk(  r n.|
rt        d||z  «       ||z  |k  sŒa|
rt        d	|dz   «        n ||j                  fS )
a	  Compute Non-negative Matrix Factorization (NMF) with Coordinate Descent

    The objective function is minimized with an alternating minimization of W
    and H. Each minimization is done with a cyclic (up to a permutation of the
    features) Coordinate Descent.

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

    W : array-like of shape (n_samples, n_components)
        Initial guess for the solution.

    H : array-like of shape (n_components, n_features)
        Initial guess for the solution.

    tol : float, default=1e-4
        Tolerance of the stopping condition.

    max_iter : int, default=200
        Maximum number of iterations before timing out.

    l1_reg_W : float, default=0.
        L1 regularization parameter for W.

    l1_reg_H : float, default=0.
        L1 regularization parameter for H.

    l2_reg_W : float, default=0.
        L2 regularization parameter for W.

    l2_reg_H : float, default=0.
        L2 regularization parameter for H.

    update_H : bool, default=True
        Set to True, both W and H will be estimated from initial guesses.
        Set to False, only W will be estimated.

    verbose : int, default=0
        The verbosity level.

    shuffle : bool, default=False
        If true, randomize the order of coordinates in the CD solver.

    random_state : int, RandomState instance or None, default=None
        Used to randomize the coordinates in the CD solver, when
        ``shuffle`` is set to ``True``. Pass an int for reproducible
        results across multiple function calls.
        See :term:`Glossary <random_state>`.

    Returns
    -------
    W : ndarray of shape (n_samples, n_components)
        Solution to the non-negative least squares problem.

    H : ndarray of shape (n_components, n_features)
        Solution to the non-negative least squares problem.

    n_iter : int
        The number of iterations done by the algorithm.

    References
    ----------
    .. [1] :doi:`"Fast local algorithms for large scale nonnegative matrix and tensor
       factorizations" <10.1587/transfun.E92.A.708>`
       Cichocki, Andrzej, and P. H. A. N. Anh-Huy. IEICE transactions on fundamentals
       of electronics, communications and computer sciences 92.3: 708-721, 2009.
    ÚC)ÚorderÚcsr)Úaccept_sparser   rŸ   r   z
violation:zConverged at iteration)r   r>   r   rD   r¬   Úprint)r(   rE   rF   ÚtolÚmax_iterÚl1_reg_WÚl1_reg_HÚl2_reg_WÚl2_reg_HÚupdate_HÚverboser©   ru   r¦   r‰   Ún_iterÚ	violationÚviolation_inits                     r!   Ú_fit_coordinate_descentrÀ   —  sö   € ôj 
�Q—S‘S Ô	$€BÜ�A UÔ+€Aä
˜\Ó
*€Cä˜˜8 a™<Ó(ò ˆØˆ	ð 	Ô/Øˆq�"�h ¨'°3ó
ñ 	
ˆ	ñ ØÔ3Ø—‘�R˜˜H h°¸óñ ˆIð �QŠ;Ø&ˆNà˜QÒÙáÜ�, 	¨NÑ :Ô;à�~Ñ%¨Ó,ÙÜÐ.°¸±
Ô;Ùð3ð6 ˆb�d‰d�Fˆ?Ðr#   c                 ó.  — |dk(  rg|	€t        | |j                  «      }	|
r|	}n|	j                  «       }|€ t        j                  ||j                  «      }t        j                  ||«      }�nët        ||| «      }t        j                  | «      r|j                  }| j                  }n,|}| }|j                  «       }|dz
  dk  rt        ||t        k  <   |dz
  dk  rt        ||t        k  <   |dk(  rt        j                  |||¬«       n"|dk(  r|dz  }|dz  }||z  }n||dz
  z  }||z  }t        ||j                  «      }|dk(  r1|€t        j                  |d¬	«      }|t        j                  dd…f   }nàt        j                  | «      r¡t        j                  |j                  «      }t        | j                  d   «      D ]f  }t        j                  ||dd…f   |«      }|dz
  dk  rt        ||t        k  <   ||dz
  z  }t        j                  ||j                  «      ||dd…f<   Œh n(|dz
  z  }t        j                  ||j                  «      }|}|dkD  r||z  }|dkD  r|||z  z   }t        ||dk(  <   ||z  }|}|dk7  r||z  }||z  }||||	fS )
z&Update W in Multiplicative Update NMF.r   Nç      ð?r   r5   r   rs   éÿÿÿÿr6   )r   r>   rr   r%   r&   r?   r9   r:   r<   r@   ÚdividerA   ÚnewaxisrY   r.   rD   )r(   rE   rF   rl   r·   r¹   ÚgammaÚH_sumrª   r«   r»   Ú	numeratorÚdenominatorÚ	WH_safe_XÚWH_safe_X_datarN   rO   ÚWHHtrT   ÚWHiÚdelta_Ws                        r!   Ú_multiplicative_update_wrÏ     s¢  € ð �A‚~àˆ;Ü! ! Q§S¡SÓ)ˆCÙà‰Ið Ÿ™›
ˆIð ˆ;Ü—&‘&˜˜AŸC™C“.ˆCÜ—f‘f˜Q “nŠô
 (¨¨1¨aÓ0ˆ	Ü�;‰;�qŒ>Ø&Ÿ^™^ˆNØ—V‘V‰Fà&ˆNØˆFà—‘Ó!ˆBØ˜3‰ Ò"Ü#*��2œ‘<Ñ ð �s‰?˜QÒÜ7>ˆN˜>¬GÑ3Ñ4à˜Š>Ü�I‰I�f˜n°.ÖAØ˜!Š^ð ˜rÑ!ˆNØ˜qÑ ˆNà˜fÑ$‰Nà˜y¨1™}Ñ,ˆNà˜fÑ$ˆNô $ I¨q¯s©sÓ3ˆ	ð ˜Š>Øˆ}ÜŸ™˜q qÔ)�Ø¤§
¡
ªA Ñ.‰Kô �{‰{˜1Œ~ô —x‘x §¡Ó(�Ü˜qŸw™w q™zÓ*ò 2�AÜŸ&™&  1¢a 4¡¨!Ó,�CØ  1‘} qÒ(Ü-4˜˜C¤'™MÑ*Ø˜I¨™MÑ)�CÜ!#§¡¨¨Q¯S©SÓ!1�D˜šA˜’Jñ2ð �y 1‘}Ñ$�Ü—v‘v˜b !§#¡#“�ØˆKð �!‚|Ø�xÑˆØ�!‚|Ø! H¨q¡LÑ0ˆÜ$+€K�˜qÑ Ñ!à�Ñ€IØ€Gð �‚zØ�EÑˆàˆ�L€Aàˆe�S˜#ÐÐr#   c
                 ób  — |dk(  rDt        |j                  | «      }
t        j                  j	                  |j                  ||g«      }�nñt        ||| «      }t        j                  | «      r|j                  }| j                  }n,|}| }|j                  «       }|dz
  dk  rt        ||t        k  <   |dz
  dk  rt        ||t        k  <   |dk(  rt        j                  |||¬«       n"|dk(  r|dz  }|dz  }||z  }n||dz
  z  }||z  }t        |j                  |«      }
|dk(  r7t        j                  |d¬«      }d||dk(  <   |d	d	…t        j                  f   }nàt        j                  | «      r¡t        j                  |j                  «      }t!        | j                  d   «      D ]f  }t        j"                  ||d	d	…|f   «      }|dz
  dk  rt        ||t        k  <   ||dz
  z  }t        j"                  |j                  |«      |d	d	…|f<   Œh n(|dz
  z  }t        j"                  |j                  |«      }|}|dkD  r||z  }|dkD  r|||z  z   }t        ||dk(  <   |�9|�7|dk7  r|d|z  z  }|
|z  }
||	z  }||	z  }||
z  }||z  }||z  }|dk7  r||z  }|S |
}||z  }|dk7  r||z  }||z  }|S )
z&update H in Multiplicative Update NMF.r   rÂ   r   r5   r   rs   rÃ   r6   N)r   r>   r%   r   r=   r?   r9   r:   r<   rr   r@   rÄ   rA   rÅ   rY   r.   rD   r&   )r(   rE   rF   rl   r¸   rº   rÆ   r1   ÚBÚrhorÈ   rÉ   rÊ   rË   rN   rO   ÚW_sumÚWtWHrT   rÍ   Údelta_Hs                        r!   Ú_multiplicative_update_hrÖ   {  sç  € ð �A‚~Ü# A§C¡C¨Ó+ˆ	Ü—i‘i×)Ñ)¨1¯3©3°°1¨+Ó6Šô (¨¨1¨aÓ0ˆ	Ü�;‰;�qŒ>Ø&Ÿ^™^ˆNØ—V‘V‰Fà&ˆNØˆFà—‘Ó!ˆBØ˜3‰ Ò"Ü#*��2œ‘<Ñ ð �s‰?˜QÒÜ7>ˆN˜>¬GÑ3Ñ4à˜Š>Ü�I‰I�f˜n°.ÖAØ˜!Š^ð ˜rÑ!ˆNØ˜qÑ ˆNà˜fÑ$‰Nà˜y¨1™}Ñ,ˆNà˜fÑ$ˆNô $ A§C¡C¨Ó3ˆ	ð ˜Š>Ü—F‘F˜1 1Ô%ˆEØ #ˆE�%˜1‘*ÑØ¢¤2§:¡: Ñ.‰Kô
 �{‰{˜1Œ~ô —x‘x §¡Ó(�Ü˜qŸw™w q™zÓ*ò 2�AÜŸ&™&  A¢a¨ d¡GÓ,�CØ  1‘} qÒ(Ü-4˜˜C¤'™MÑ*Ø˜I¨™MÑ)�CÜ!#§¡¨¯©¨SÓ!1�Dš˜A˜’Jñ2ð �y 1‘}Ñ$�Ü—v‘v˜aŸc™c 2“�ØˆKð �!‚|Ø�xÑˆØ�!‚|Ø! H¨q¡LÑ0ˆÜ$+€K�˜qÑ Ñ!à€}˜˜à�AŠ:Ø�!�e‘)‰OˆAØ�Q‰ˆ	Ø	ˆS‰ˆØ	ˆS‰ˆØ	ˆY‰ˆØ	ˆ[ÑˆØ�‰Eˆà�AŠ:Ø�%‰KˆAð €Hð ˆØ�;ÑˆØ�AŠ:Ø˜ÑˆGØ	ˆW‰ˆà€Hr#   rg   c                 óH  — t        j                   «       }t        |«      }|dk  r	dd|z
  z  }n|dkD  r	d|dz
  z  }nd}t        | |||d¬«      }|}d\  }}}t        d|dz   «      D �]   }t	        | ||||||||||
¬«      \  }}}}|dk  r3d	||t        j                  t
        j                  «      j                  k  <   |
rPt        | |||||	|¬
«      }d\  }}}|dk  r3d	||t        j                  t
        j                  «      j                  k  <   |dkD  sŒ¯|dz  dk(  sŒ¸t        | |||d¬«      }|r(t        j                   «       }t        d|||z
  |fz  «       ||z
  |z  |k  r n|}�Œ |r4|dk(  sdz  dk7  r't        j                   «       }t        d||z
  fz  «       ||fS )aK	  Compute Non-negative Matrix Factorization with Multiplicative Update.

    The objective function is _beta_divergence(X, WH) and is minimized with an
    alternating minimization of W and H. Each minimization is done with a
    Multiplicative Update.

    Parameters
    ----------
    X : array-like of shape (n_samples, n_features)
        Constant input matrix.

    W : array-like of shape (n_samples, n_components)
        Initial guess for the solution.

    H : array-like of shape (n_components, n_features)
        Initial guess for the solution.

    beta_loss : float or {'frobenius', 'kullback-leibler',             'itakura-saito'}, default='frobenius'
        String must be in {'frobenius', 'kullback-leibler', 'itakura-saito'}.
        Beta divergence to be minimized, measuring the distance between X
        and the dot product WH. Note that values different from 'frobenius'
        (or 2) and 'kullback-leibler' (or 1) lead to significantly slower
        fits. Note that for beta_loss <= 0 (or 'itakura-saito'), the input
        matrix X cannot contain zeros.

    max_iter : int, default=200
        Number of iterations.

    tol : float, default=1e-4
        Tolerance of the stopping condition.

    l1_reg_W : float, default=0.
        L1 regularization parameter for W.

    l1_reg_H : float, default=0.
        L1 regularization parameter for H.

    l2_reg_W : float, default=0.
        L2 regularization parameter for W.

    l2_reg_H : float, default=0.
        L2 regularization parameter for H.

    update_H : bool, default=True
        Set to True, both W and H will be estimated from initial guesses.
        Set to False, only W will be estimated.

    verbose : int, default=0
        The verbosity level.

    Returns
    -------
    W : ndarray of shape (n_samples, n_components)
        Solution to the non-negative least squares problem.

    H : ndarray of shape (n_components, n_features)
        Solution to the non-negative least squares problem.

    n_iter : int
        The number of iterations done by the algorithm.

    References
    ----------
    Lee, D. D., & Seung, H., S. (2001). Algorithms for Non-negative Matrix
    Factorization. Adv. Neural Inform. Process. Syst.. 13.
    Fevotte, C., & Idier, J. (2011). Algorithms for nonnegative matrix
    factorization with the beta-divergence. Neural Computation, 23(9).
    r   rÂ   r5   r   T©rH   ©NNN)rl   r·   r¹   rÆ   rÇ   rª   r«   r»   rŸ   )rl   r¸   rº   rÆ   r   é
   z0Epoch %02d reached after %.3f seconds, error: %fz&Epoch %02d reached after %.3f seconds.)Útimer8   rV   rD   rÏ   r%   ÚfinfoÚfloat64r…   rÖ   r´   )r(   rE   rF   rl   r¶   rµ   r·   r¸   r¹   rº   r»   r¼   Ú
start_timerÆ   Úerror_at_initÚprevious_errorrÇ   rª   r«   r½   ÚerrorÚ	iter_timeÚend_times                          r!   Ú_fit_multiplicative_updaterä   Ü  s   € ôf —‘“€Jä# IÓ.€Ið �1‚}Ø�s˜Y‘Ñ'‰Ø	�QŠØ�y 3‘Ñ'‰àˆô % Q¨¨1¨iÀTÔJ€MØ"€Nà&�O€Eˆ3�Ü˜˜8 a™<Ó(ó 5#ˆô 6ØØØØØØØØØØØô
Ñˆˆ5�#�sð �qŠ=Ø.1ˆAˆa”"—(‘(œ2Ÿ:™:Ó&×*Ñ*Ñ*Ñ+ñ Ü(ØØØØ#Ø!Ø!ØôˆAð /‰OˆE�3˜ð ˜AŠ~Ø25��!”b—h‘hœrŸz™zÓ*×.Ñ.Ñ.Ñ/ð �‹7�v ‘{ aÓ'Ü$ Q¨¨1¨iÀTÔJˆEáÜ ŸI™I›K�	ÜØFØ˜y¨:Ñ5°uÐ=ñ>ôð
  Ñ&¨-Ñ7¸#Ò=ÙØ"ŠNðk5#ñp �C˜1’H ¨¡¨qÒ 0Ü—9‘9“;ˆÜØ4¸ÀÈ:Ñ@UÐ7VÑVô	
ð ˆa�ˆ<Ðr#   z
array-likezsparse matrixÚboolean)r(   rE   rF   r»   ©Úprefer_skip_nested_validationÚcdrŸ   Úsame)r„   r»   Úsolverrl   rµ   r¶   Úalpha_WÚalpha_HÚl1_ratioru   r¼   r©   c                ó&  — t        ||||||	||
||||¬«      }|j                  «        t        | dt        j                  t        j
                  g¬«      } t        d¬«      5  |j                  | |||¬«      \  }}}ddd«       ||fS # 1 sw Y   ŒxY w)a  Compute Non-negative Matrix Factorization (NMF).

    Find two non-negative matrices (W, H) whose product approximates the non-
    negative matrix X. This factorization can be used for example for
    dimensionality reduction, source separation or topic extraction.

    The objective function is:

    .. math::

        L(W, H) &= 0.5 * ||X - WH||_{loss}^2

                &+ alpha\_W * l1\_ratio * n\_features * ||vec(W)||_1

                &+ alpha\_H * l1\_ratio * n\_samples * ||vec(H)||_1

                &+ 0.5 * alpha\_W * (1 - l1\_ratio) * n\_features * ||W||_{Fro}^2

                &+ 0.5 * alpha\_H * (1 - l1\_ratio) * n\_samples * ||H||_{Fro}^2,

    where :math:`||A||_{Fro}^2 = \sum_{i,j} A_{ij}^2` (Frobenius norm) and
    :math:`||vec(A)||_1 = \sum_{i,j} abs(A_{ij})` (Elementwise L1 norm)

    The generic norm :math:`||X - WH||_{loss}^2` may represent
    the Frobenius norm or another supported beta-divergence loss.
    The choice between options is controlled by the `beta_loss` parameter.

    The regularization terms are scaled by `n_features` for `W` and by `n_samples` for
    `H` to keep their impact balanced with respect to one another and to the data fit
    term as independent as possible of the size `n_samples` of the training set.

    The objective function is minimized with an alternating minimization of W
    and H. If H is given and update_H=False, it solves for W only.

    Note that the transformed data is named W and the components matrix is named H. In
    the NMF literature, the naming convention is usually the opposite since the data
    matrix X is transposed.

    Parameters
    ----------
    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Constant matrix.

    W : array-like of shape (n_samples, n_components), default=None
        If `init='custom'`, it is used as initial guess for the solution.
        If `update_H=False`, it is initialised as an array of zeros, unless
        `solver='mu'`, then it is filled with values calculated by
        `np.sqrt(X.mean() / self._n_components)`.
        If `None`, uses the initialisation method specified in `init`.

    H : array-like of shape (n_components, n_features), default=None
        If `init='custom'`, it is used as initial guess for the solution.
        If `update_H=False`, it is used as a constant, to solve for W only.
        If `None`, uses the initialisation method specified in `init`.

    n_components : int or {'auto'} or None, default='auto'
        Number of components. If `None`, all features are kept.
        If `n_components='auto'`, the number of components is automatically inferred
        from `W` or `H` shapes.

        .. versionchanged:: 1.4
            Added `'auto'` value.

        .. versionchanged:: 1.6
            Default value changed from `None` to `'auto'`.

    init : {'random', 'nndsvd', 'nndsvda', 'nndsvdar', 'custom'}, default=None
        Method used to initialize the procedure.

        Valid options:

        - None: 'nndsvda' if n_components < n_features, otherwise 'random'.
        - 'random': non-negative random matrices, scaled with:
          `sqrt(X.mean() / n_components)`
        - 'nndsvd': Nonnegative Double Singular Value Decomposition (NNDSVD)
          initialization (better for sparseness)
        - 'nndsvda': NNDSVD with zeros filled with the average of X
          (better when sparsity is not desired)
        - 'nndsvdar': NNDSVD with zeros filled with small random values
          (generally faster, less accurate alternative to NNDSVDa
          for when sparsity is not desired)
        - 'custom': If `update_H=True`, use custom matrices W and H which must both
          be provided. If `update_H=False`, then only custom matrix H is used.

        .. versionchanged:: 0.23
            The default value of `init` changed from 'random' to None in 0.23.

        .. versionchanged:: 1.1
            When `init=None` and n_components is less than n_samples and n_features
            defaults to `nndsvda` instead of `nndsvd`.

    update_H : bool, default=True
        Set to True, both W and H will be estimated from initial guesses.
        Set to False, only W will be estimated.

    solver : {'cd', 'mu'}, default='cd'
        Numerical solver to use:

        - 'cd' is a Coordinate Descent solver that uses Fast Hierarchical
          Alternating Least Squares (Fast HALS).
        - 'mu' is a Multiplicative Update solver.

        .. versionadded:: 0.17
           Coordinate Descent solver.

        .. versionadded:: 0.19
           Multiplicative Update solver.

    beta_loss : float or {'frobenius', 'kullback-leibler',             'itakura-saito'}, default='frobenius'
        Beta divergence to be minimized, measuring the distance between X
        and the dot product WH. Note that values different from 'frobenius'
        (or 2) and 'kullback-leibler' (or 1) lead to significantly slower
        fits. Note that for beta_loss <= 0 (or 'itakura-saito'), the input
        matrix X cannot contain zeros. Used only in 'mu' solver.

        .. versionadded:: 0.19

    tol : float, default=1e-4
        Tolerance of the stopping condition.

    max_iter : int, default=200
        Maximum number of iterations before timing out.

    alpha_W : float, default=0.0
        Constant that multiplies the regularization terms of `W`. Set it to zero
        (default) to have no regularization on `W`.

        .. versionadded:: 1.0

    alpha_H : float or "same", default="same"
        Constant that multiplies the regularization terms of `H`. Set it to zero to
        have no regularization on `H`. If "same" (default), it takes the same value as
        `alpha_W`.

        .. versionadded:: 1.0

    l1_ratio : float, default=0.0
        The regularization mixing parameter, with 0 <= l1_ratio <= 1.
        For l1_ratio = 0 the penalty is an elementwise L2 penalty
        (aka Frobenius Norm).
        For l1_ratio = 1 it is an elementwise L1 penalty.
        For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.

    random_state : int, RandomState instance or None, default=None
        Used for NMF initialisation (when ``init`` == 'nndsvdar' or
        'random'), and in Coordinate Descent. Pass an int for reproducible
        results across multiple function calls.
        See :term:`Glossary <random_state>`.

    verbose : int, default=0
        The verbosity level.

    shuffle : bool, default=False
        If true, randomize the order of coordinates in the CD solver.

    Returns
    -------
    W : ndarray of shape (n_samples, n_components)
        Solution to the non-negative least squares problem.

    H : ndarray of shape (n_components, n_features)
        Solution to the non-negative least squares problem.

    n_iter : int
        Actual number of iterations.

    References
    ----------
    .. [1] :doi:`"Fast local algorithms for large scale nonnegative matrix and tensor
       factorizations" <10.1587/transfun.E92.A.708>`
       Cichocki, Andrzej, and P. H. A. N. Anh-Huy. IEICE transactions on fundamentals
       of electronics, communications and computer sciences 92.3: 708-721, 2009.

    .. [2] :doi:`"Algorithms for nonnegative matrix factorization with the
       beta-divergence" <10.1162/NECO_a_00168>`
       Fevotte, C., & Idier, J. (2011). Neural Computation, 23(9).

    Examples
    --------
    >>> import numpy as np
    >>> X = np.array([[1,1], [2, 1], [3, 1.2], [4, 1], [5, 0.8], [6, 1]])
    >>> from sklearn.decomposition import non_negative_factorization
    >>> W, H, n_iter = non_negative_factorization(
    ...     X, n_components=2, init='random', random_state=0)
    )rb   r„   rê   rl   rµ   r¶   ru   rë   rì   rí   r¼   r©   ©r²   Úcsc©r³   r~   T©Úassume_finite©rE   rF   r»   N)ÚNMFÚ_validate_paramsr   r%   rÝ   Úfloat32r	   Ú_fit_transform)r(   rE   rF   rb   r„   r»   rê   rl   rµ   r¶   rë   rì   rí   ru   r¼   r©   Úestr½   s                     r!   Únon_negative_factorizationrú   �  sª   € ôl Ø!ØØØØØØ!ØØØØØô€Cð ×ÑÔä�A ^¼B¿J¹JÌÏ
É
Ð;SÔT€Aä	 dÔ	+ñ JØ×)Ñ)¨!¨q°AÀÐ)ÓI‰ˆˆ1ˆf÷Jð ˆa�ˆ<Ð÷Jð Jús   Á BÂBc                   óŽ  ‡ — e Zd ZU dZdej
                  iZ eeddd¬«      d e	dh«      g e	h d£«      dg e	h d	£«      e
g ee
d
dd¬«      g eeddd¬«      gdg ee
d
dd¬«      g ee
d
dd¬«       e	dh«      g ee
d
dd¬«      gdgdœ
Zeed<   	 dddddddddd
dœ	d„Zd„ Zd„ Zd„ Zd d„Zd ddœd„Zed„ «       Zˆ fd„Zˆ xZS )!Ú_BaseNMFz$Base class for NMF and MiniBatchNMF.ÚXtr   NÚleft©Úclosedr,   >   Úcustomrv   ro   rp   rw   >   rg   ri   rh   r   ru   ré   Úbothr¼   ©
rb   r„   rl   rµ   r¶   ru   rë   rì   rí   r¼   Ú_parameter_constraintsrg   r­   r®   rŸ   )	r„   rl   rµ   r¶   ru   rë   rì   rí   r¼   c       	         ó�   — || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        y ©Nr  )Úselfrb   r„   rl   rµ   r¶   ru   rë   rì   rí   r¼   s              r!   Ú__init__z_BaseNMF.__init__Ž  sL   € ð )ˆÔØˆŒ	Ø"ˆŒØˆŒØ ˆŒØ(ˆÔØˆŒØˆŒØ ˆŒØˆ�r#   c                 óš   — | j                   | _        | j                  €|j                  d   | _        t        | j                  «      | _        y )Nr   )rb   Ú_n_componentsr.   r8   rl   Ú
_beta_loss)r  r(   s     r!   Ú_check_paramsz_BaseNMF._check_params§  s>   € à!×.Ñ.ˆÔØ×ÑÐ%Ø!"§¡¨¡ˆDÔô .¨d¯n©nÓ=ˆ�r#   c                 ó  — |j                   \  }}| j                  dk(  r¼|rºt        || j                  |fd«       t        ||| j                  fd«       | j                  dk(  r|j                   d   | _        |j                  |j                  k7  s|j                  |j                  k7  r/t        dj                  |j                  |j                  «      «      ‚||fS |�s7|�t        j                  dt        «       t        || j                  |fd«       | j                  dk(  r|j                   d   | _        |j                  |j                  k7  r$t        dj                  |j                  «      «      ‚| j                  d	k(  rbt        j                  |j                  «       | j                  z  «      }t        j                  || j                  f||j                  ¬
«      }||fS t        j                  || j                  f|j                  ¬
«      }||fS |€|�t        j                  dt        «       | j                  dk(  r|j                   d   | _        t!        || j                  | j                  | j"                  ¬«      \  }}||fS )z"Check W and H, or initialize them.r  zNMF (input H)zNMF (input W)r,   r   zKH and W should have the same dtype as X. Got H.dtype = {} and W.dtype = {}.z8When update_H=False, the provided initial W is not used.z4H should have the same dtype as X. Got H.dtype = {}.Úmur    zcWhen init!='custom', provided W or H are ignored. Set  init='custom' to use them as initialization.r   )r„   ru   )r.   r„   r3   r
  r~   Ú	TypeErrorrz   ÚwarningsÚwarnÚRuntimeWarningrê   r%   r   r{   ÚfullÚzerosr�   ru   )r  r(   rE   rF   r»   r†   r‡   rˆ   s           r!   Ú
_check_w_hz_BaseNMF._check_w_h°  s:  € à !§¡Ñˆ	�:à�9‰9˜Ò ¡XÜ˜˜D×.Ñ.°
Ð;¸_ÔMÜ˜˜I t×'9Ñ'9Ð:¸OÔLØ×!Ñ! VÒ+Ø%&§W¡W¨Q¡Z�Ô"à�w‰w˜!Ÿ'™'Ò! Q§W¡W°·±Ò%7Üð5ß5;±V¸A¿G¹GÀQÇWÁWÓ5Móð ð^ �!ˆtˆòU Øˆ}Ü—‘ØNÜ"ôô
 ˜˜D×.Ñ.°
Ð;¸_ÔMØ×!Ñ! VÒ+Ø%&§W¡W¨Q¡Z�Ô"à�w‰w˜!Ÿ'™'Ò!ÜØJ×QÑQØŸ™óóð ð �{‰{˜dÒ"Ü—g‘g˜aŸf™f›h¨×);Ñ);Ñ;Ó<�Ü—G‘G˜Y¨×(:Ñ(:Ð;¸SÈÏÉÔP�ð* �!ˆtˆô' —H‘H˜i¨×);Ñ);Ð<ÀAÇGÁGÔL�ð& �!ˆtˆð! ˆ}  Ü—‘ðHô #ôð ×!Ñ! VÒ+Ø%&§W¡W¨Q¡Z�Ô"ä"Ø�4×%Ñ%¨D¯I©IÀD×DUÑDUô‰DˆAˆqð �!ˆtˆr#   c                 ó.  — |j                   \  }}| j                  }| j                  dk(  r| j                  n| j                  }||z  | j                  z  }||z  | j                  z  }||z  d| j                  z
  z  }||z  d| j                  z
  z  }	||||	fS )z$Compute scaled regularization terms.ré   rÂ   )r.   rë   rì   rí   )
r  r(   r†   r‡   rë   rì   r·   r¸   r¹   rº   s
             r!   Ú_compute_regularizationz _BaseNMF._compute_regularizationì  s˜   € à !§¡Ñˆ	�:Ø—,‘,ˆØ"&§,¡,°&Ò"8�$—,’,¸d¿l¹lˆà Ñ'¨$¯-©-Ñ7ˆØ˜wÑ&¨¯©Ñ6ˆØ Ñ'¨3°·±Ñ+>Ñ?ˆØ˜wÑ&¨#°·±Ñ*=Ñ>ˆà˜ 8¨XÐ5Ð5r#   c                 ó,   —  | j                   |fi |¤Ž | S )aS  Learn a NMF model for the data X.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vector, where `n_samples` is the number of samples
            and `n_features` is the number of features.

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

        **params : kwargs
            Parameters (keyword arguments) and values passed to
            the fit_transform instance.

        Returns
        -------
        self : object
            Returns the instance itself.
        )Úfit_transform)r  r(   rŽ   Úparamss       r!   Úfitz_BaseNMF.fitù  s   € ð. 	ˆ×Ñ˜1Ñ' Ò'Øˆr#   )rý   c                óN   — t        ||«      }t        | «       || j                  z  S )a^  Transform data back to its original space.

        .. versionadded:: 0.18

        Parameters
        ----------
        X : {ndarray, sparse matrix} of shape (n_samples, n_components)
            Transformed data matrix.

        Xt : {ndarray, sparse matrix} of shape (n_samples, n_components)
            Transformed data matrix.

            .. deprecated:: 1.5
                `Xt` was deprecated in 1.5 and will be removed in 1.7. Use `X` instead.

        Returns
        -------
        X : ndarray of shape (n_samples, n_features)
            Returns a data matrix of the original shape.
        )r   r   Úcomponents_)r  r(   rý   s      r!   Úinverse_transformz_BaseNMF.inverse_transform  s)   € ô, /¨q°"Ó5ˆä˜ÔØ�4×#Ñ#Ñ#Ð#r#   c                 ó4   — | j                   j                  d   S )z&Number of transformed output features.r   )r  r.   )r  s    r!   Ú_n_features_outz_BaseNMF._n_features_out.  s   € ð ×Ñ×%Ñ% aÑ(Ð(r#   c                 óŽ   •— t         ‰| �  «       }d|j                  _        d|j                  _        ddg|j
                  _        |S )NTrÝ   r÷   )ÚsuperÚ__sklearn_tags__Ú
input_tagsÚpositive_onlyÚsparseÚtransformer_tagsÚpreserves_dtype)r  ÚtagsÚ	__class__s     €r!   r#  z_BaseNMF.__sklearn_tags__3  s@   ø€ Ü‰wÑ'Ó)ˆØ(,ˆ�‰Ô%Ø!%ˆ�‰ÔØ1:¸IÐ0Fˆ×ÑÔ-Øˆr#   ©r,   r  )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚUNUSEDÚ-_BaseNMF__metadata_request__inverse_transformr   r   r   r   r  ÚdictÚ__annotations__r  r  r  r  r  r  Úpropertyr   r#  Ú__classcell__©r*  s   @r!   rü   rü   o  sG  ø… Ù.ð
 .2Ð3C×3JÑ3JÐ,KÐ)ñ �X˜q $¨vÔ6ØÙ˜�xÓ ð
ñ ÒLÓMØð
ñ
 ÒIÓJØð
ñ ˜˜q $¨vÔ6Ð7Ù˜h¨¨4¸Ô?Ð@Ø'Ð(Ù˜T 1 d°6Ô:Ð;Ù˜T 1 d°6Ô:¹JÈÀxÓ<PÐQÙ˜d A q°Ô8Ð9Ø�;ñ)$Ð˜Dó ð2 ðð ØØØØØØØØôò2>ò:òx6óð4$¨dô $ð6 ñ)ó ð)÷ð r#   rü   c                   ó¾   ‡ — e Zd ZU dZi ej
                  ¥ eddh«      gdgdœ¥Zeed<   	 ddddd	d
dddddddœˆ fd„Z	ˆ fd„Z
 ed¬«      dd„«       Zdd„Zd„ Zˆ xZS )rõ   a€  Non-Negative Matrix Factorization (NMF).

    Find two non-negative matrices, i.e. matrices with all non-negative elements, (W, H)
    whose product approximates the non-negative matrix X. This factorization can be used
    for example for dimensionality reduction, source separation or topic extraction.

    The objective function is:

    .. math::

        L(W, H) &= 0.5 * ||X - WH||_{loss}^2

                &+ alpha\_W * l1\_ratio * n\_features * ||vec(W)||_1

                &+ alpha\_H * l1\_ratio * n\_samples * ||vec(H)||_1

                &+ 0.5 * alpha\_W * (1 - l1\_ratio) * n\_features * ||W||_{Fro}^2

                &+ 0.5 * alpha\_H * (1 - l1\_ratio) * n\_samples * ||H||_{Fro}^2,

    where :math:`||A||_{Fro}^2 = \sum_{i,j} A_{ij}^2` (Frobenius norm) and
    :math:`||vec(A)||_1 = \sum_{i,j} abs(A_{ij})` (Elementwise L1 norm).

    The generic norm :math:`||X - WH||_{loss}` may represent
    the Frobenius norm or another supported beta-divergence loss.
    The choice between options is controlled by the `beta_loss` parameter.

    The regularization terms are scaled by `n_features` for `W` and by `n_samples` for
    `H` to keep their impact balanced with respect to one another and to the data fit
    term as independent as possible of the size `n_samples` of the training set.

    The objective function is minimized with an alternating minimization of W
    and H.

    Note that the transformed data is named W and the components matrix is named H. In
    the NMF literature, the naming convention is usually the opposite since the data
    matrix X is transposed.

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

    Parameters
    ----------
    n_components : int or {'auto'} or None, default='auto'
        Number of components. If `None`, all features are kept.
        If `n_components='auto'`, the number of components is automatically inferred
        from W or H shapes.

        .. versionchanged:: 1.4
            Added `'auto'` value.

        .. versionchanged:: 1.6
            Default value changed from `None` to `'auto'`.

    init : {'random', 'nndsvd', 'nndsvda', 'nndsvdar', 'custom'}, default=None
        Method used to initialize the procedure.
        Valid options:

        - `None`: 'nndsvda' if n_components <= min(n_samples, n_features),
          otherwise random.

        - `'random'`: non-negative random matrices, scaled with:
          `sqrt(X.mean() / n_components)`

        - `'nndsvd'`: Nonnegative Double Singular Value Decomposition (NNDSVD)
          initialization (better for sparseness)

        - `'nndsvda'`: NNDSVD with zeros filled with the average of X
          (better when sparsity is not desired)

        - `'nndsvdar'` NNDSVD with zeros filled with small random values
          (generally faster, less accurate alternative to NNDSVDa
          for when sparsity is not desired)

        - `'custom'`: Use custom matrices `W` and `H` which must both be provided.

        .. versionchanged:: 1.1
            When `init=None` and n_components is less than n_samples and n_features
            defaults to `nndsvda` instead of `nndsvd`.

    solver : {'cd', 'mu'}, default='cd'
        Numerical solver to use:

        - 'cd' is a Coordinate Descent solver.
        - 'mu' is a Multiplicative Update solver.

        .. versionadded:: 0.17
           Coordinate Descent solver.

        .. versionadded:: 0.19
           Multiplicative Update solver.

    beta_loss : float or {'frobenius', 'kullback-leibler',             'itakura-saito'}, default='frobenius'
        Beta divergence to be minimized, measuring the distance between X
        and the dot product WH. Note that values different from 'frobenius'
        (or 2) and 'kullback-leibler' (or 1) lead to significantly slower
        fits. Note that for beta_loss <= 0 (or 'itakura-saito'), the input
        matrix X cannot contain zeros. Used only in 'mu' solver.

        .. versionadded:: 0.19

    tol : float, default=1e-4
        Tolerance of the stopping condition.

    max_iter : int, default=200
        Maximum number of iterations before timing out.

    random_state : int, RandomState instance or None, default=None
        Used for initialisation (when ``init`` == 'nndsvdar' or
        'random'), and in Coordinate Descent. Pass an int for reproducible
        results across multiple function calls.
        See :term:`Glossary <random_state>`.

    alpha_W : float, default=0.0
        Constant that multiplies the regularization terms of `W`. Set it to zero
        (default) to have no regularization on `W`.

        .. versionadded:: 1.0

    alpha_H : float or "same", default="same"
        Constant that multiplies the regularization terms of `H`. Set it to zero to
        have no regularization on `H`. If "same" (default), it takes the same value as
        `alpha_W`.

        .. versionadded:: 1.0

    l1_ratio : float, default=0.0
        The regularization mixing parameter, with 0 <= l1_ratio <= 1.
        For l1_ratio = 0 the penalty is an elementwise L2 penalty
        (aka Frobenius Norm).
        For l1_ratio = 1 it is an elementwise L1 penalty.
        For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.

        .. versionadded:: 0.17
           Regularization parameter *l1_ratio* used in the Coordinate Descent
           solver.

    verbose : int, default=0
        Whether to be verbose.

    shuffle : bool, default=False
        If true, randomize the order of coordinates in the CD solver.

        .. versionadded:: 0.17
           *shuffle* parameter used in the Coordinate Descent solver.

    Attributes
    ----------
    components_ : ndarray of shape (n_components, n_features)
        Factorization matrix, sometimes called 'dictionary'.

    n_components_ : int
        The number of components. It is same as the `n_components` parameter
        if it was given. Otherwise, it will be same as the number of
        features.

    reconstruction_err_ : float
        Frobenius norm of the matrix difference, or beta-divergence, between
        the training data ``X`` and the reconstructed data ``WH`` from
        the fitted model.

    n_iter_ : int
        Actual number of iterations.

    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
    --------
    DictionaryLearning : Find a dictionary that sparsely encodes data.
    MiniBatchSparsePCA : Mini-batch Sparse Principal Components Analysis.
    PCA : Principal component analysis.
    SparseCoder : Find a sparse representation of data from a fixed,
        precomputed dictionary.
    SparsePCA : Sparse Principal Components Analysis.
    TruncatedSVD : Dimensionality reduction using truncated SVD.

    References
    ----------
    .. [1] :doi:`"Fast local algorithms for large scale nonnegative matrix and tensor
       factorizations" <10.1587/transfun.E92.A.708>`
       Cichocki, Andrzej, and P. H. A. N. Anh-Huy. IEICE transactions on fundamentals
       of electronics, communications and computer sciences 92.3: 708-721, 2009.

    .. [2] :doi:`"Algorithms for nonnegative matrix factorization with the
       beta-divergence" <10.1162/NECO_a_00168>`
       Fevotte, C., & Idier, J. (2011). Neural Computation, 23(9).

    Examples
    --------
    >>> import numpy as np
    >>> X = np.array([[1, 1], [2, 1], [3, 1.2], [4, 1], [5, 0.8], [6, 1]])
    >>> from sklearn.decomposition import NMF
    >>> model = NMF(n_components=2, init='random', random_state=0)
    >>> W = model.fit_transform(X)
    >>> H = model.components_
    r  rè   rå   )rê   r©   r  Nrg   r­   r®   rŸ   ré   r   F)r„   rê   rl   rµ   r¶   ru   rë   rì   rí   r¼   r©   c                óT   •— t         ‰| �  ||||||||	|
|¬«
       || _        || _        y ©Nr  )r"  r  rê   r©   )r  rb   r„   rê   rl   rµ   r¶   ru   rë   rì   rí   r¼   r©   r*  s                €r!   r  zNMF.__init__  sE   ø€ ô  	‰ÑØ%ØØØØØ%ØØØØð 	ô 	
ð ˆŒØˆ�r#   c                 ó  •— t         ‰| �  |«       | j                  dk7  r3| j                  dvr%t	        d| j                  ›d| j                  ›�«      ‚| j                  dk(  r)| j
                  dk(  rt        j                  dt        «       | S )Nr  )r   rg   z$Invalid beta_loss parameter: solver z does not handle beta_loss = rv   zÖThe multiplicative update ('mu') solver cannot update zeros present in the initialization, and so leads to poorer results when used jointly with init='nndsvd'. You may try init='nndsvda' or init='nndsvdar' instead.)	r"  r  rê   rl   r/   r„   r  r  ÚUserWarning©r  r(   r*  s     €r!   r  zNMF._check_params0  sŽ   ø€ Ü‰Ñ˜aÔ ð �;‰;˜$Ò 4§>¡>Ð9IÑ#IäØ6°t·{±{°oð FØ#Ÿ~™~Ð0ð2óð ð �;‰;˜$Ò 4§9¡9°Ò#8Ü�M‰MðMô
 ôð ˆr#   Træ   c                 óT  — t        | |dt        j                  t        j                  g¬«      }t	        d¬«      5  | j                  |||¬«      \  }}}ddd«       t        |||| j                  d¬«      | _        |j                  d   | _
        || _        | _        |S # 1 sw Y   ŒLxY w)	a  Learn a NMF model for the data X and returns the transformed data.

        This is more efficient than calling fit followed by transform.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vector, where `n_samples` is the number of samples
            and `n_features` is the number of features.

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

        W : array-like of shape (n_samples, n_components), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            If `None`, uses the initialisation method specified in `init`.

        H : array-like of shape (n_components, n_features), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            If `None`, uses the initialisation method specified in `init`.

        Returns
        -------
        W : ndarray of shape (n_samples, n_components)
            Transformed data.
        rï   rñ   Trò   ©rE   rF   NrØ   r   )r   r%   rÝ   r÷   r	   rø   rV   r  Úreconstruction_err_r.   Ún_components_r  Ún_iter_)r  r(   rŽ   rE   rF   r½   s         r!   r  zNMF.fit_transformG  s¤   € ô8 Ø�! >¼"¿*¹*ÄbÇjÁjÐ9Qô
ˆô ¨$Ô/ñ 	<Ø×.Ñ.¨q°A¸Ð.Ó;‰LˆAˆq�&÷	<ô $4Øˆq�!�T—_‘_°$ô$
ˆÔ ð ŸW™W Q™ZˆÔØˆÔØˆŒàˆ÷	<ð 	<ús   ºBÂB'c                 óü  — | j                  |«       |j                  «       dk(  r| j                  dk  rt        d«      ‚| j	                  ||||«      \  }}| j                  |«      \  }}}}	| j                  dk(  rOt        |||| j                  | j                  ||||	|| j                  | j                  | j                  ¬«      \  }}}
nj| j                  dk(  rCt        |||| j                  | j                  | j                  ||||	|| j                  «      ^}}}
}nt        d| j                  z  «      ‚|
| j                  k(  r6| j                  dkD  r't        j                  d| j                  z  t         «       |||
fS )a4  Learn a NMF model for the data X and returns the transformed data.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Data matrix to be decomposed

        y : Ignored

        W : array-like of shape (n_samples, n_components), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            If `update_H=False`, it is initialised as an array of zeros, unless
            `solver='mu'`, then it is filled with values calculated by
            `np.sqrt(X.mean() / self._n_components)`.
            If `None`, uses the initialisation method specified in `init`.

        H : array-like of shape (n_components, n_features), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            If `update_H=False`, it is used as a constant, to solve for W only.
            If `None`, uses the initialisation method specified in `init`.

        update_H : bool, default=True
            If True, both W and H will be estimated from initial guesses,
            this corresponds to a call to the 'fit_transform' method.
            If False, only W will be estimated, this corresponds to a call
            to the 'transform' method.

        Returns
        -------
        W : ndarray of shape (n_samples, n_components)
            Transformed data.

        H : ndarray of shape (n_components, n_features)
            Factorization matrix, sometimes called 'dictionary'.

        n_iter_ : int
            Actual number of iterations.
        r   ú|When beta_loss <= 0 and X contains zeros, the solver may diverge. Please add small values to X, or use a positive beta_loss.rè   )r»   r¼   r©   ru   r  zInvalid solver parameter '%s'.zLMaximum number of iterations %d reached. Increase it to improve convergence.)r  ry   r  r/   r  r  rê   rÀ   rµ   r¶   r¼   r©   ru   rä   r  r  r   )r  r(   rŽ   rE   rF   r»   r·   r¸   r¹   rº   r½   Ú_s               r!   rø   zNMF._fit_transformt  s{  € ðP 	×Ñ˜1Ôà�5‰5‹7�aŠ<˜DŸO™O¨qÒ0Üð5óð ð �‰˜q ! Q¨Ó1‰ˆˆ1ð 26×1MÑ1MÈaÓ1PÑ.ˆ�(˜H hà�;‰;˜$ÒÜ2ØØØØ—‘Ø—‘ØØØØØ!ØŸ™ØŸ™Ø!×.Ñ.ô‰LˆAˆq‘&ð �[‰[˜DÒ Ü9ØØØØ—‘Ø—‘Ø—‘ØØØØØØ—‘ó ÐˆAˆq�&™1ô Ð=ÀÇÁÑKÓLÐLà�T—]‘]Ò" t§x¡x°!¢|Ü�M‰Mð-Ø/3¯}©}ñ=ä"ôð �!�Vˆ|Ðr#   c                 óþ   — t        | «       t        | |dt        j                  t        j                  gdd¬«      }t        d¬«      5  | j                  || j                  d¬«      ^}}ddd«       |S # 1 sw Y   S xY w)a¦  Transform the data X according to the fitted NMF model.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vector, where `n_samples` is the number of samples
            and `n_features` is the number of features.

        Returns
        -------
        W : ndarray of shape (n_samples, n_components)
            Transformed data.
        rï   FT)r³   r~   ÚresetÚensure_non_negativerò   )rF   r»   N)r   r   r%   rÝ   r÷   r	   rø   r  )r  r(   rE   rD  s       r!   Ú	transformzNMF.transformÖ  s�   € ô 	˜ÔÜØØØ(Ü—:‘:œrŸz™zÐ*ØØ $ô
ˆô ¨$Ô/ñ 	OØ×'Ñ'¨¨T×-=Ñ-=ÈÐ'ÓNˆEˆA�÷	Oð ˆ÷	Oð ˆús   Á!A2Á2A<r+  rÙ   ©NNNT)r,  r-  r.  r/  rü   r  r   r2  r3  r  r  r   r  rø   rH  r5  r6  s   @r!   rõ   rõ   ;  sž   ø… ñLð\$Ø
×
)Ñ
)ð$á˜t T˜lÓ+Ð,Ø�;ò$Ð˜Dó ð ðð ØØØØØØØØØØöô@ñ. °Ô5ò*ó 6ð*óX`öDr#   rõ   c                   ó`  ‡ — e Zd ZU dZi ej
                  ¥ eeddd¬«      dg eeddd¬«      g eeddd¬«      gdg eeddd¬«      g eeddd¬«      dgd	œ¥Ze	e
d
<   	 d!ddddddddddddddddœˆ fd„Zˆ fd„Zd„ Zd„ Zd„ Z ed¬«      d"d„«       Zd#d„Zd„ Z ed¬«      d"d „«       Zˆ xZS )$ÚMiniBatchNMFa;   Mini-Batch Non-Negative Matrix Factorization (NMF).

    .. versionadded:: 1.1

    Find two non-negative matrices, i.e. matrices with all non-negative elements,
    (`W`, `H`) whose product approximates the non-negative matrix `X`. This
    factorization can be used for example for dimensionality reduction, source
    separation or topic extraction.

    The objective function is:

    .. math::

        L(W, H) &= 0.5 * ||X - WH||_{loss}^2

                &+ alpha\_W * l1\_ratio * n\_features * ||vec(W)||_1

                &+ alpha\_H * l1\_ratio * n\_samples * ||vec(H)||_1

                &+ 0.5 * alpha\_W * (1 - l1\_ratio) * n\_features * ||W||_{Fro}^2

                &+ 0.5 * alpha\_H * (1 - l1\_ratio) * n\_samples * ||H||_{Fro}^2,

    where :math:`||A||_{Fro}^2 = \sum_{i,j} A_{ij}^2` (Frobenius norm) and
    :math:`||vec(A)||_1 = \sum_{i,j} abs(A_{ij})` (Elementwise L1 norm).

    The generic norm :math:`||X - WH||_{loss}^2` may represent
    the Frobenius norm or another supported beta-divergence loss.
    The choice between options is controlled by the `beta_loss` parameter.

    The objective function is minimized with an alternating minimization of `W`
    and `H`.

    Note that the transformed data is named `W` and the components matrix is
    named `H`. In the NMF literature, the naming convention is usually the opposite
    since the data matrix `X` is transposed.

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

    Parameters
    ----------
    n_components : int or {'auto'} or None, default='auto'
        Number of components. If `None`, all features are kept.
        If `n_components='auto'`, the number of components is automatically inferred
        from W or H shapes.

        .. versionchanged:: 1.4
            Added `'auto'` value.

        .. versionchanged:: 1.6
            Default value changed from `None` to `'auto'`.

    init : {'random', 'nndsvd', 'nndsvda', 'nndsvdar', 'custom'}, default=None
        Method used to initialize the procedure.
        Valid options:

        - `None`: 'nndsvda' if `n_components <= min(n_samples, n_features)`,
          otherwise random.

        - `'random'`: non-negative random matrices, scaled with:
          `sqrt(X.mean() / n_components)`

        - `'nndsvd'`: Nonnegative Double Singular Value Decomposition (NNDSVD)
          initialization (better for sparseness).

        - `'nndsvda'`: NNDSVD with zeros filled with the average of X
          (better when sparsity is not desired).

        - `'nndsvdar'` NNDSVD with zeros filled with small random values
          (generally faster, less accurate alternative to NNDSVDa
          for when sparsity is not desired).

        - `'custom'`: Use custom matrices `W` and `H` which must both be provided.

    batch_size : int, default=1024
        Number of samples in each mini-batch. Large batch sizes
        give better long-term convergence at the cost of a slower start.

    beta_loss : float or {'frobenius', 'kullback-leibler',             'itakura-saito'}, default='frobenius'
        Beta divergence to be minimized, measuring the distance between `X`
        and the dot product `WH`. Note that values different from 'frobenius'
        (or 2) and 'kullback-leibler' (or 1) lead to significantly slower
        fits. Note that for `beta_loss <= 0` (or 'itakura-saito'), the input
        matrix `X` cannot contain zeros.

    tol : float, default=1e-4
        Control early stopping based on the norm of the differences in `H`
        between 2 steps. To disable early stopping based on changes in `H`, set
        `tol` to 0.0.

    max_no_improvement : int, default=10
        Control early stopping based on the consecutive number of mini batches
        that does not yield an improvement on the smoothed cost function.
        To disable convergence detection based on cost function, set
        `max_no_improvement` to None.

    max_iter : int, default=200
        Maximum number of iterations over the complete dataset before
        timing out.

    alpha_W : float, default=0.0
        Constant that multiplies the regularization terms of `W`. Set it to zero
        (default) to have no regularization on `W`.

    alpha_H : float or "same", default="same"
        Constant that multiplies the regularization terms of `H`. Set it to zero to
        have no regularization on `H`. If "same" (default), it takes the same value as
        `alpha_W`.

    l1_ratio : float, default=0.0
        The regularization mixing parameter, with 0 <= l1_ratio <= 1.
        For l1_ratio = 0 the penalty is an elementwise L2 penalty
        (aka Frobenius Norm).
        For l1_ratio = 1 it is an elementwise L1 penalty.
        For 0 < l1_ratio < 1, the penalty is a combination of L1 and L2.

    forget_factor : float, default=0.7
        Amount of rescaling of past information. Its value could be 1 with
        finite datasets. Choosing values < 1 is recommended with online
        learning as more recent batches will weight more than past batches.

    fresh_restarts : bool, default=False
        Whether to completely solve for W at each step. Doing fresh restarts will likely
        lead to a better solution for a same number of iterations but it is much slower.

    fresh_restarts_max_iter : int, default=30
        Maximum number of iterations when solving for W at each step. Only used when
        doing fresh restarts. These iterations may be stopped early based on a small
        change of W controlled by `tol`.

    transform_max_iter : int, default=None
        Maximum number of iterations when solving for W at transform time.
        If None, it defaults to `max_iter`.

    random_state : int, RandomState instance or None, default=None
        Used for initialisation (when ``init`` == 'nndsvdar' or
        'random'), and in Coordinate Descent. Pass an int for reproducible
        results across multiple function calls.
        See :term:`Glossary <random_state>`.

    verbose : bool, default=False
        Whether to be verbose.

    Attributes
    ----------
    components_ : ndarray of shape (n_components, n_features)
        Factorization matrix, sometimes called 'dictionary'.

    n_components_ : int
        The number of components. It is same as the `n_components` parameter
        if it was given. Otherwise, it will be same as the number of
        features.

    reconstruction_err_ : float
        Frobenius norm of the matrix difference, or beta-divergence, between
        the training data `X` and the reconstructed data `WH` from
        the fitted model.

    n_iter_ : int
        Actual number of started iterations over the whole dataset.

    n_steps_ : int
        Number of mini-batches processed.

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

    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.

    See Also
    --------
    NMF : Non-negative matrix factorization.
    MiniBatchDictionaryLearning : Finds a dictionary that can best be used to represent
        data using a sparse code.

    References
    ----------
    .. [1] :doi:`"Fast local algorithms for large scale nonnegative matrix and tensor
       factorizations" <10.1587/transfun.E92.A.708>`
       Cichocki, Andrzej, and P. H. A. N. Anh-Huy. IEICE transactions on fundamentals
       of electronics, communications and computer sciences 92.3: 708-721, 2009.

    .. [2] :doi:`"Algorithms for nonnegative matrix factorization with the
       beta-divergence" <10.1162/NECO_a_00168>`
       Fevotte, C., & Idier, J. (2011). Neural Computation, 23(9).

    .. [3] :doi:`"Online algorithms for nonnegative matrix factorization with the
       Itakura-Saito divergence" <10.1109/ASPAA.2011.6082314>`
       Lefevre, A., Bach, F., Fevotte, C. (2011). WASPA.

    Examples
    --------
    >>> import numpy as np
    >>> X = np.array([[1, 1], [2, 1], [3, 1.2], [4, 1], [5, 0.8], [6, 1]])
    >>> from sklearn.decomposition import MiniBatchNMF
    >>> model = MiniBatchNMF(n_components=2, init='random', random_state=0)
    >>> W = model.fit_transform(X)
    >>> H = model.components_
    r   Nrþ   rÿ   r   r  rå   )Úmax_no_improvementrc   Úforget_factorÚfresh_restartsÚfresh_restarts_max_iterÚtransform_max_iterr  i   rg   r­   rÚ   r®   rŸ   ré   gffffffæ?Fé   )r„   rc   rl   rµ   rL  r¶   rë   rì   rí   rM  rN  rO  rP  ru   r¼   c                óŒ   •— t         ‰| �  ||||||||	|
|¬«
       || _        || _        || _        || _        || _        || _        y r9  )r"  r  rL  rc   rM  rN  rO  rP  )r  rb   r„   rc   rl   rµ   rL  r¶   rë   rì   rí   rM  rN  rO  rP  ru   r¼   r*  s                    €r!   r  zMiniBatchNMF.__init__Ê  sf   ø€ ô( 	‰ÑØ%ØØØØØ%ØØØØð 	ô 	
ð #5ˆÔØ$ˆŒØ*ˆÔØ,ˆÔØ'>ˆÔ$Ø"4ˆÕr#   c                 óÜ  •— t         ‰| �  |«       t        | j                  |j                  d   «      | _        | j                  | j
                  |j                  d   z  z  | _        | j                  dk  rdd| j                  z
  z  | _	        n.| j                  dkD  rd| j                  dz
  z  | _	        nd| _	        | j                  €| j                  | _        | S | j                  | _        | S )Nr   r   rÂ   r5   r   )r"  r  ry   rc   r.   Ú_batch_sizerM  Ú_rhor  Ú_gammarP  r¶   Ú_transform_max_iterr<  s     €r!   r  zMiniBatchNMF._check_paramsò  sß   ø€ Ü‰Ñ˜aÔ ô ˜tŸ™°·±¸±
Ó;ˆÔð ×&Ñ&¨4×+;Ñ+;¸a¿g¹gÀa¹jÑ+HÑIˆŒ	ð �?‰?˜QÒØ  t§¡Ñ!6Ñ7ˆD�KØ�_‰_˜qÒ Ø §¡°3Ñ!6Ñ7ˆD�KàˆDŒKð
 ×&Ñ&Ð.ð �M‰Mð 	Ô ð ˆð ×(Ñ(ð 	Ô ð ˆr#   c           
      ó>  — t        j                  |j                  «       | j                  z  «      }t        j                  |j
                  d   | j                  f||j                  ¬«      }|j                  «       }| j                  |«      \  }}}	}t        |«      D ]}  }t        |||| j                  ||	| j                  «      ^}}t        j                  ||z
  «      t        j                  |«      z  }
| j                  dkD  r|
| j                  k  r |S ||dd Œ |S )zÎMinimize the objective function w.r.t W.

        Update W with H being fixed, until convergence. This is the heart
        of `transform` but it's also used during `fit` when doing fresh restarts.
        r   r    N)r%   r   r{   r
  r  r.   r~   rr   r  rD   rÏ   r  rV  r   r"   rµ   )r  r(   rF   r¶   rˆ   rE   ÚW_bufferr·   rD  r¹   ÚW_diffs              r!   Ú_solve_WzMiniBatchNMF._solve_W  sý   € ô �g‰g�a—f‘f“h ×!3Ñ!3Ñ3Ó4ˆÜ�G‰G�Q—W‘W˜Q‘Z ×!3Ñ!3Ð4°cÀÇÁÔIˆØ—6‘6“8ˆð $(×#?Ñ#?ÀÓ#BÑ ˆ�!�X˜qä�x“ò 		ˆAÜ,Ø�1�a˜Ÿ™¨(°H¸d¿k¹kóˆEˆA�ô —[‘[  X¡Ó.´·±¸Q³Ñ?ˆFØ�x‰x˜!Š| ¨$¯(©(Ò 2Øð ˆð ˆH‘Q‰Kð		ð ˆr#   c                 óx  — |j                   d   }| j                  |«      \  }}}}	| j                  s|€| j                  ||| j                  «      }n't        |||| j                  ||| j                  «      ^}}
| j                  dk  r3d||t        j                  t        j                  «      j                  k  <   t        |||| j                  «      ||j                  «       z  z   ||j                  «       z  z   ||dz  j                  «       z  z   |	|dz  j                  «       z  z   |z  }|rŒt        |||| j                  ||	| j                  | j                  | j                   | j"                  ¬«
      |dd | j                  dk  r3d||t        j                  t        j                  «      j                  k  <   |S )z0Perform the update of W and H for one minibatch.r   Nr   rŸ   r   )rl   r¸   rº   rÆ   r1   rÑ   rÒ   )r.   r  rN  r[  rO  rÏ   r  rV  r%   rÜ   rÝ   r…   rV   rA   rÖ   Ú_components_numeratorÚ_components_denominatorrU  )r  r(   rE   rF   r»   rc   r·   r¸   r¹   rº   rD  Ú
batch_costs               r!   Ú_minibatch_stepzMiniBatchNMF._minibatch_step'  s�  € à—W‘W˜Q‘Zˆ
ð 26×1MÑ1MÈaÓ1PÑ.ˆ�(˜H hð ×Ò ! )Ø—‘˜a  D×$@Ñ$@ÓA‰Aä,Ø�1�a˜Ÿ™¨(°H¸d¿k¹kóˆEˆA�ð
 �?‰?˜QÒØ.1ˆAˆa”"—(‘(œ2Ÿ:™:Ó&×*Ñ*Ñ*Ñ+ô ˜Q  1 d§o¡oÓ6Ø˜Ÿ™›Ñ ñ!à˜Ÿ™›Ñ ñ!ð ˜!˜Q™$Ÿ™›Ñ%ñ&ð ˜!˜Q™$Ÿ™›Ñ%ñ	&ð
 ñˆ
ñ Ü+ØØØØŸ/™/Ø!Ø!Ø—k‘kØ×,Ñ,Ø×.Ñ.Ø—I‘IôˆA‰aˆDð �‰ !Ò#Ø25��!”b—h‘hœrŸz™zÓ*×.Ñ.Ñ.Ñ/àÐr#   c           
      ó\  — |j                   d   }|dz   }|dk(  r!| j                  rt        d|› d|› d|› �«       y| j                  €|| _        n1||dz   z  }	t	        |	d«      }	| j                  d|	z
  z  ||	z  z   | _        | j                  r!t        d|› d|› d|› d| j                  › �«       t        j                  ||z
  «      t        j                  |«      z  }
| j                  dkD  r-|
| j                  k  r| j                  rt        d|› d|› �«       y	| j                  �| j                  | j                  k  rd| _	        | j                  | _        n| xj                  dz  c_	        | j                  �7| j                  | j                  k\  r| j                  rt        d
|› d|› �«       y	y)z7Helper function to encapsulate the early stopping logicr   r   zMinibatch step ú/z: mean batch cost: Fz, ewa cost: z#Converged (small H change) at step Tz>Converged (lack of improvement in objective function) at step )r.   r¼   r´   Ú	_ewa_costry   r   r"   rµ   Ú_ewa_cost_minÚ_no_improvementrL  )r  r(   r_  rF   ÚH_bufferr†   ÚstepÚn_stepsrc   ÚalphaÚH_diffs              r!   Ú_minibatch_convergencez#MiniBatchNMF._minibatch_convergenceX  s´  € ð —W‘W˜Q‘Zˆ
ð �a‰xˆð �1Š9Ø�|Š|Ü˜¨ v¨Q¨w¨iÐ7JÈ:È,ÐWÔXØð
 �>‰>Ð!Ø'ˆD�Nà )¨a¡-Ñ0ˆEÜ˜˜q“MˆEØ!Ÿ^™^¨q°5©yÑ9¸JÈÑ<NÑNˆDŒNð �<Š<ÜØ! $  q¨¨	Ð1DØ�,˜l¨4¯>©>Ð*:ð<ôô —‘˜Q ™\Ó*¬V¯[©[¸«^Ñ;ˆØ�8‰8�aŠ<˜F d§h¡hÒ.Ø�|Š|ÜÐ;¸D¸6ÀÀ7À)ÐLÔMØð ×ÑÐ%¨¯©¸$×:LÑ:LÒ)LØ#$ˆDÔ Ø!%§¡ˆDÕà× Ò  AÑ%Õ ð ×#Ñ#Ð/Ø×$Ñ$¨×(?Ñ(?Ò?à�|Š|ÜðØ#˜f A g Yð0ôð àr#   Træ   c                 ód  — t        | |dt        j                  t        j                  g¬«      }t	        d¬«      5  | j                  |||¬«      \  }}}}ddd«       t        |||| j                  d¬«      | _        |j                  d   | _
        || _        | _        | _        |S # 1 sw Y   ŒSxY w)	aÃ  Learn a NMF model for the data X and returns the transformed data.

        This is more efficient than calling fit followed by transform.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Data matrix to be decomposed.

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

        W : array-like of shape (n_samples, n_components), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            If `None`, uses the initialisation method specified in `init`.

        H : array-like of shape (n_components, n_features), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            If `None`, uses the initialisation method specified in `init`.

        Returns
        -------
        W : ndarray of shape (n_samples, n_components)
            Transformed data.
        rï   rñ   Trò   r>  NrØ   r   )r   r%   rÝ   r÷   r	   rø   rV   r  r?  r.   r@  r  rA  Ún_steps_)r  r(   rŽ   rE   rF   r½   rh  s          r!   r  zMiniBatchNMF.fit_transform”  s²   € ô6 Ø�! >¼"¿*¹*ÄbÇjÁjÐ9Qô
ˆô ¨$Ô/ñ 	EØ$(×$7Ñ$7¸¸QÀ!Ð$7Ó$DÑ!ˆAˆq�&˜'÷	Eô $4Øˆq�!�T—_‘_°$ô$
ˆÔ ð ŸW™W Q™ZˆÔØˆÔØˆŒØˆŒàˆ÷	Eð 	Eús   ºB&Â&B/c           
      ój  — t        |d«       | j                  |«       |j                  «       dk(  r| j                  dk  rt	        d«      ‚|j
                  d   }| j                  ||||«      \  }}|j                  «       }|j                  «       | _        t        j                  |j
                  |j                  ¬«      | _        d| _        d| _        d| _        t!        || j"                  «      }t%        j&                  |«      }t)        t        j*                  || j"                  z  «      «      }| j,                  |z  }	t/        t1        |	«      |«      D ]B  \  }
}| j3                  ||   ||   ||«      }|r| j5                  ||   |||||
|	«      r n||dd ŒD | j6                  r| j9                  ||| j:                  «      }
dz   }	t)        t        j*                  |	|z  «      «      }|| j,                  k(  r7| j<                  dkD  r(t?        j@                  d| j,                  › d�tB        «       ||||	fS )	a€  Learn a NMF model for the data X and returns the transformed data.

        Parameters
        ----------
        X : {ndarray, sparse matrix} of shape (n_samples, n_features)
            Data matrix to be decomposed.

        W : array-like of shape (n_samples, n_components), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            If `update_H=False`, it is initialised as an array of zeros, unless
            `solver='mu'`, then it is filled with values calculated by
            `np.sqrt(X.mean() / self._n_components)`.
            If `None`, uses the initialisation method specified in `init`.

        H : array-like of shape (n_components, n_features), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            If `update_H=False`, it is used as a constant, to solve for W only.
            If `None`, uses the initialisation method specified in `init`.

        update_H : bool, default=True
            If True, both W and H will be estimated from initial guesses,
            this corresponds to a call to the `fit_transform` method.
            If False, only W will be estimated, this corresponds to a call
            to the `transform` method.

        Returns
        -------
        W : ndarray of shape (n_samples, n_components)
            Transformed data.

        H : ndarray of shape (n_components, n_features)
            Factorization matrix, sometimes called 'dictionary'.

        n_iter : int
            Actual number of started iterations over the whole dataset.

        n_steps : int
            Number of mini-batches processed.
        zMiniBatchNMF (input X)r   rC  r    Nr   zMaximum number of iterations z- reached. Increase it to improve convergence.)"r   r  ry   r  r/   r.   r  rr   r]  r%   Úonesr~   r^  rc  rd  re  r   rT  Ú	itertoolsÚcycleÚintÚceilr¶   ÚziprD   r`  rk  rN  r[  rW  rµ   r  r  r   )r  r(   rE   rF   r»   r†   rf  ÚbatchesÚn_steps_per_iterrh  rT   re   r_  r½   s                 r!   rø   zMiniBatchNMF._fit_transformÁ  s  € ôP 	˜1Ð6Ô7Ø×Ñ˜1Ôà�5‰5‹7�aŠ<˜DŸO™O¨qÒ0Üð5óð ð —G‘G˜A‘Jˆ	ð �‰˜q ! Q¨Ó1‰ˆˆ1Ø—6‘6“8ˆð &'§V¡V£XˆÔ"Ü')§w¡w¨q¯w©w¸a¿g¹gÔ'FˆÔ$ð ˆŒØ!ˆÔØ ˆÔä˜i¨×)9Ñ)9Ó:ˆÜ—/‘/ 'Ó*ˆÜœrŸw™w y°4×3CÑ3CÑ'CÓDÓEÐØ—-‘-Ð"2Ñ2ˆäœE '›N¨GÓ4ò 	‰HˆAˆuØ×-Ñ-¨a°©h¸¸%¹À!ÀXÓNˆJá˜D×7Ñ7Ø�%‘˜* a¨°9¸aÀôñ àˆH‘Q‰Kð	ð ×ÒØ—‘˜a  D×$<Ñ$<Ó=ˆAà�a‘%ˆÜ”R—W‘W˜WÐ'7Ñ7Ó8Ó9ˆà�T—]‘]Ò" t§x¡x°!¢|Ü�M‰Mà3°D·M±M°?ð C:ð :ô #ôð �!�V˜WÐ$Ð$r#   c                 óÆ   — t        | «       t        | |dt        j                  t        j                  gd¬«      }| j                  || j                  | j                  «      }|S )ag  Transform the data X according to the fitted MiniBatchNMF model.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Data matrix to be transformed by the model.

        Returns
        -------
        W : ndarray of shape (n_samples, n_components)
            Transformed data.
        rï   F©r³   r~   rF  )r   r   r%   rÝ   r÷   r[  r  rW  )r  r(   rE   s      r!   rH  zMiniBatchNMF.transform"	  sW   € ô 	˜ÔÜØØØ(Ü—:‘:œrŸz™zÐ*Øô
ˆð �M‰M˜!˜T×-Ñ-¨t×/GÑ/GÓHˆàˆr#   c                 ó  — t        | d«      }t        | |dt        j                  t        j                  g| ¬«      }|sv| j                  |«       | j                  |||d¬«      \  }}|j                  «       | _        t        j                  |j                  |j                  ¬«      | _        d| _        n| j                  }| j                  |d|d¬	«       |j                  d   | _        || _        | xj                  d
z  c_        | S )af  Update the model using the data in `X` as a mini-batch.

        This method is expected to be called several times consecutively
        on different chunks of a dataset so as to implement out-of-core
        or online learning.

        This is especially useful when the whole dataset is too big to fit in
        memory at once (see :ref:`scaling_strategies`).

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Data matrix to be decomposed.

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

        W : array-like of shape (n_samples, n_components), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            Only used for the first call to `partial_fit`.

        H : array-like of shape (n_components, n_features), default=None
            If `init='custom'`, it is used as initial guess for the solution.
            Only used for the first call to `partial_fit`.

        Returns
        -------
        self
            Returns the instance itself.
        r  rï   rx  Trô   r    r   N)r»   r   )Úhasattrr   r%   rÝ   r÷   r  r  rr   r]  ro  r.   r~   r^  rm  r  r`  r@  )r  r(   rŽ   rE   rF   Úhas_componentsrD  s          r!   Úpartial_fitzMiniBatchNMF.partial_fit<	  sä   € ô@ !  }Ó5ˆäØØØ(Ü—:‘:œrŸz™zÐ*Ø$Ð$ô
ˆñ à×Ñ˜qÔ!Ø—?‘? 1¨¨Q¸�?Ó>‰DˆAˆqà)*¯©«ˆDÔ&Ü+-¯7©7°1·7±7À!Ç'Á'Ô+JˆDÔ(ØˆD�Mà× Ñ ˆAà×Ñ˜Q  a°$ÐÔ7àŸW™W Q™ZˆÔØˆÔØ�Š˜Ñ�àˆr#   r+  rÙ   )NNT)r,  r-  r.  r/  rü   r  r   r   r   r2  r3  r  r  r[  r`  rk  r   r  rø   rH  r|  r5  r6  s   @r!   rK  rK  ô  s  ø… ñIðV$Ø
×
)Ñ
)ð$á'¨°!°TÀ&ÔIÈ4ÐPÙ ¨!¨T¸&ÔAÐBÙ" 4¨¨A°fÔ=Ð>Ø$˜+Ù$,¨X°q¸$ÀvÔ$NÐ#OÙ'¨°!°TÀ&ÔIÈ4ÐPò$Ð˜Dó ð ð&5ð ØØØØØØØØØØØ "ØØØö%&5ôPò4ò6/òb:ñx °Ô5ò*ó 6ð*óX_%òBñ4 °Ô5ò:ó 6ô:r#   rK  )F)Ng�íµ ÷Æ°>N)
r­   r®   r   r   r   r   Tr   FNrI  rÙ   )	rg   r®   r­   r   r   r   r   Tr   )NNr,   )Dr/  rp  rÛ   r  Úabcr   Úmathr   Únumbersr   r   Únumpyr%   Úscipy.sparser&  r9   Úscipyr   Ú_configr	   Úbaser
   r   r   r   Ú
exceptionsr   Úutilsr   r   r   r   Úutils._param_validationr   r   r   Úutils.deprecationr   Úutils.extmathr   r   r   Úutils.validationr   r   r   Ú_cdnmf_fastr   rÜ   r÷   r…   r@   r"   r*   r3   rV   r?   r8   r�   r¬   rÀ   rÏ   rÖ   rä   rú   rü   rõ   rK  © r#   r!   ú<module>r�     sÇ  ðÙ (ó
 Û Û Ý Ý ß "ã Ý Ý å $÷ó õ ,ß RÓ R÷ñ õ
 Cß IÑ I÷ñ õ
 ,à
ˆ"�(‰(�2—:‘:Ó
×
"Ñ
"€ò
!ò
(òFó"hòVò*óXòv8ðD 	ØØØØØØØØØóuð@ ØØØóiðZ HLó^ðJ ØØØØØØØØóbñJ à˜OÐ,Ø˜DÐ!Ø˜DÐ!Ø�Kñ	ð #(ôð Ø
Øð	bð 
ØØØØØØØØØØØó#bóðbôJIÐ.Ð0@À-ÐQTô IôXvˆ(ô vôrC
�8õ C
r#   