
    -i                     $   S r SSKJrJr  SSKrSSKJr  SSK	J
r
  SSKJrJr  SSKJrJrJrJr  SSKJrJrJr  SS	KJrJr  SS
KJrJr  SSKJrJrJ r   SSK!J"r#  SSK!J$r$  SSK!J%r&  \RN                  " \(5      RR                  r*S r+ " S S\\\5      r,g)a6  

=============================================================
Online Latent Dirichlet Allocation with variational inference
=============================================================

This implementation is modified from Matthew D. Hoffman's onlineldavb code
Link: https://github.com/blei-lab/onlineldavb
    )IntegralRealN)effective_n_jobs)gammaln	logsumexp   )BaseEstimatorClassNamePrefixFeaturesOutMixinTransformerMixin_fit_context)check_random_stategen_batchesgen_even_slices)Interval
StrOptions)Paralleldelayed)check_is_fittedcheck_non_negativevalidate_data   )_dirichlet_expectation_1d)_dirichlet_expectation_2d)mean_changec           	      b   [         R                  " U 5      nU R                  u  pUR                  S   n
U(       a-  UR                  SSX45      R	                  U R
                  SS9nO [        R                  " X4U R
                  S9n[        R                  " [        U5      5      nU(       a)  [        R                  " UR                  U R
                  S9OSnU(       a$  U R                  nU R                  nU R                  nU R
                  [        R                  :X  a  SOS	n[        U   n[         U   n[        R"                  " U R
                  5      R$                  n['        U5       GH<  nU(       a  WWU   UUS
-       nWUU   UUS
-       nO'[        R(                  " U USS24   5      S   nU UU4   nUUSS24   nUUSS24   R+                  5       nUSS2U4   n['        SU5       H_  nUn[        R,                  " UU5      U-   nU[        R,                  " UU-  UR.                  5      -  nU" UUU5        U" UU5      U:  d  M_    O   UUUSS24'   U(       d  M  [        R,                  " UU5      U-   nUSS2U4==   [        R0                  " UUU-  5      -  ss'   GM?     X4$ )a:  E-step: update document-topic distribution.

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

exp_topic_word_distr : ndarray of shape (n_topics, n_features)
    Exponential value of expectation of log topic word distribution.
    In the literature, this is `exp(E[log(beta)])`.

doc_topic_prior : float
    Prior of document topic distribution `theta`.

max_doc_update_iter : int
    Max number of iterations for updating document topic distribution in
    the E-step.

mean_change_tol : float
    Stopping tolerance for updating document topic distribution in E-step.

cal_sstats : bool
    Parameter that indicate to calculate sufficient statistics or not.
    Set `cal_sstats` to `True` when we need to run M-step.

random_state : RandomState instance or None
    Parameter that indicate how to initialize document topic distribution.
    Set `random_state` to None will initialize document topic distribution
    to a constant number.

Returns
-------
(doc_topic_distr, suff_stats) :
    `doc_topic_distr` is unnormalized topic distribution for each document.
    In the literature, this is `gamma`. we can calculate `E[log(theta)]`
    from it.
    `suff_stats` is expected sufficient statistics for the M-step.
        When `cal_sstats == False`, this will be None.

r         Y@g{Gz?FcopydtypeNfloatdoubler   )spissparseshapegammaastyper    nponesexpr   zerosdataindicesindptrfloat32cy_mean_changecy_dirichlet_expectation_1dfinfoepsrangenonzeror   dotTouter)Xexp_topic_word_distrdoc_topic_priormax_doc_update_itermean_change_tol
cal_sstatsrandom_stateis_sparse_x	n_samples
n_featuresn_topicsdoc_topic_distrexp_doc_topic
suff_statsX_data	X_indicesX_indptrctyper   dirichlet_expectation_1dr3   idx_didscntsdoc_topic_dexp_doc_topic_dexp_topic_word_d_last_dnorm_phis                                 M/var/www/html/venv/lib/python3.13/site-packages/sklearn/decomposition/_lda.py_update_doc_distributionrV   ,   s   b ++a.KGGI#))!,H&,,UD9:OPWWGG% X 
 ''9"7qwwG FF4_EFM @J%++177;t  II	88 ww"**,G(E 'K:5A
((177


Cy!HUOhuqy.ABC(5/HUQY,?@D**Quax[)!,CUCZ=D%eQh/'q1668/37 q-.A F vvo/?@3FH)BFF4(?DTDVDV,WWK$[/?S6;//A / %0q! :vvo/?@3FHq#v"((?D8O"LLC "F ((    c                   v  ^  \ rS rSr% Sr0 S\" \SSSS9/_SS\" \SS	S
S9/_SS\" \SS	S
S9/_S\" SS15      /_S\" \SS	S
S9/_S\" \SSSS9/_S\" \SSSS9/_S\" \SSSS9/_S\" \SSSS9/_S\" \SSSS9/_S\" \SSSS9/_S\" \SSSS9/_S\" \SSSS9/_SS\/_SS/_SS/_r	\
\S'    S<SSSSS SS!S"S#S$S%S&SSSS'.S( jjr\R                  4S) jrS=S* jrS=S+ jrU 4S, jrS- r\" S.S/9S=S0 j5       r\" S.S/9S=S1 j5       rS2 rS.S3.S4 jrS=S.S3.S5 jjrS6 rS=S7 jrS>S8 jrS?S9 jr\S: 5       rS;r U =r!$ )@LatentDirichletAllocation   a4  Latent Dirichlet Allocation with online variational Bayes algorithm.

The implementation is based on [1]_ and [2]_.

.. versionadded:: 0.17

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

Parameters
----------
n_components : int, default=10
    Number of topics.

    .. versionchanged:: 0.19
        ``n_topics`` was renamed to ``n_components``

doc_topic_prior : float, default=None
    Prior of document topic distribution `theta`. If the value is None,
    defaults to `1 / n_components`.
    In [1]_, this is called `alpha`.

topic_word_prior : float, default=None
    Prior of topic word distribution `beta`. If the value is None, defaults
    to `1 / n_components`.
    In [1]_, this is called `eta`.

learning_method : {'batch', 'online'}, default='batch'
    Method used to update `_component`. Only used in :meth:`fit` method.
    In general, if the data size is large, the online update will be much
    faster than the batch update.

    Valid options:

    - 'batch': Batch variational Bayes method. Use all training data in each EM
      update. Old `components_` will be overwritten in each iteration.
    - 'online': Online variational Bayes method. In each EM update, use mini-batch
      of training data to update the ``components_`` variable incrementally. The
      learning rate is controlled by the ``learning_decay`` and the
      ``learning_offset`` parameters.

    .. versionchanged:: 0.20
        The default learning method is now ``"batch"``.

learning_decay : float, default=0.7
    It is a parameter that control learning rate in the online learning
    method. The value should be set between (0.5, 1.0] to guarantee
    asymptotic convergence. When the value is 0.0 and batch_size is
    ``n_samples``, the update method is same as batch learning. In the
    literature, this is called kappa.

learning_offset : float, default=10.0
    A (positive) parameter that downweights early iterations in online
    learning.  It should be greater than 1.0. In the literature, this is
    called tau_0.

max_iter : int, default=10
    The maximum number of passes over the training data (aka epochs).
    It only impacts the behavior in the :meth:`fit` method, and not the
    :meth:`partial_fit` method.

batch_size : int, default=128
    Number of documents to use in each EM iteration. Only used in online
    learning.

evaluate_every : int, default=-1
    How often to evaluate perplexity. Only used in `fit` method.
    set it to 0 or negative number to not evaluate perplexity in
    training at all. Evaluating perplexity can help you check convergence
    in training process, but it will also increase total training time.
    Evaluating perplexity in every iteration might increase training time
    up to two-fold.

total_samples : int, default=1e6
    Total number of documents. Only used in the :meth:`partial_fit` method.

perp_tol : float, default=1e-1
    Perplexity tolerance. Only used when ``evaluate_every`` is greater than 0.

mean_change_tol : float, default=1e-3
    Stopping tolerance for updating document topic distribution in E-step.

max_doc_update_iter : int, default=100
    Max number of iterations for updating document topic distribution in
    the E-step.

n_jobs : int, default=None
    The number of jobs to use in the E-step.
    ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
    ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
    for more details.

verbose : int, default=0
    Verbosity level.

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

Attributes
----------
components_ : ndarray of shape (n_components, n_features)
    Variational parameters for topic word distribution. Since the complete
    conditional for topic word distribution is a Dirichlet,
    ``components_[i, j]`` can be viewed as pseudocount that represents the
    number of times word `j` was assigned to topic `i`.
    It can also be viewed as distribution over the words for each topic
    after normalization:
    ``model.components_ / model.components_.sum(axis=1)[:, np.newaxis]``.

exp_dirichlet_component_ : ndarray of shape (n_components, n_features)
    Exponential value of expectation of log topic word distribution.
    In the literature, this is `exp(E[log(beta)])`.

n_batch_iter_ : int
    Number of iterations of the EM step.

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

n_iter_ : int
    Number of passes over the dataset.

bound_ : float
    Final perplexity score on training set.

doc_topic_prior_ : float
    Prior of document topic distribution `theta`. If the value is None,
    it is `1 / n_components`.

random_state_ : RandomState instance
    RandomState instance that is generated either from a seed, the random
    number generator or by `np.random`.

topic_word_prior_ : float
    Prior of topic word distribution `beta`. If the value is None, it is
    `1 / n_components`.

See Also
--------
sklearn.discriminant_analysis.LinearDiscriminantAnalysis:
    A classifier with a linear decision boundary, generated by fitting
    class conditional densities to the data and using Bayes' rule.

References
----------
.. [1] "Online Learning for Latent Dirichlet Allocation", Matthew D.
       Hoffman, David M. Blei, Francis Bach, 2010
       https://github.com/blei-lab/onlineldavb

.. [2] "Stochastic Variational Inference", Matthew D. Hoffman,
       David M. Blei, Chong Wang, John Paisley, 2013

Examples
--------
>>> from sklearn.decomposition import LatentDirichletAllocation
>>> from sklearn.datasets import make_multilabel_classification
>>> # This produces a feature matrix of token counts, similar to what
>>> # CountVectorizer would produce on text.
>>> X, _ = make_multilabel_classification(random_state=0)
>>> lda = LatentDirichletAllocation(n_components=5,
...     random_state=0)
>>> lda.fit(X)
LatentDirichletAllocation(...)
>>> # get topics for some given samples:
>>> lda.transform(X[-2:])
array([[0.00360392, 0.25499205, 0.0036211 , 0.64236448, 0.09541846],
       [0.15297572, 0.00362644, 0.44412786, 0.39568399, 0.003586  ]])
n_componentsr   Nneither)closedr;   r   bothtopic_word_priorlearning_methodbatchonlinelearning_decaylearning_offset      ?leftmax_iter
batch_sizeevaluate_everytotal_samplesperp_tolr=   r<   n_jobsverboser?   _parameter_constraints
   gffffff?g      $@   g    .Ag?gMbP?d   )r;   r_   r`   rc   rd   rg   rh   ri   rj   rk   r=   r<   rl   rm   r?   c                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        Xl	        Xl
        Xl        Xl        Xl        Xl        UU l        g N)r[   r;   r_   r`   rc   rd   rg   rh   ri   rj   rk   r=   r<   rl   rm   r?   )selfr[   r;   r_   r`   rc   rd   rg   rh   ri   rj   rk   r=   r<   rl   rm   r?   s                    rU   __init__"LatentDirichletAllocation.__init__k  sa    ( ). 0.,. $,* .#6 (rW   c                     [        U R                  5      U l        SU l        SU l        U R
                  c  SU R                  -  U l        OU R
                  U l        U R                  c  SU R                  -  U l	        OU R                  U l	        SnSU-  nU R                  R                  X4U R                  U45      R                  USS9U l        [        R                  " [        U R                  5      5      U l        g)zInitialize latent variables.r   r   Nre   r   Fr   )r   r?   random_state_n_batch_iter_n_iter_r;   r[   doc_topic_prior_r_   topic_word_prior_r&   r'   components_r(   r*   r   exp_dirichlet_component_)ru   rB   r    
init_gammainit_vars        rU   _init_latent_vars+LatentDirichletAllocation._init_latent_vars  s     00A0AB'$'$*;*;$;D!$($8$8D!  (%(4+<+<%<D"%)%:%:D"
#--334#4#4j"A

&U&
# 	
 )+%d&6&67)
%rW   c                   ^ ^^^ U(       a  T R                   OSm[        T R                  5      nUc!  [        U[	        ST R
                  S-
  5      S9nU" UUUU 4S j[        TR                  S   U5       5       5      n[        U6 u  px[        R                  " U5      n	T(       a\  [        R                  " T R                  R                  T R                  R                  S9n
U H  nX-  n
M	     U
T R                  -  n
X4$ Sn
X4$ )aD  E-step in EM update.

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

cal_sstats : bool
    Parameter that indicate whether to calculate sufficient statistics
    or not. Set ``cal_sstats`` to True when we need to run M-step.

random_init : bool
    Parameter that indicate whether to initialize document topic
    distribution randomly in the E-step. Set it to True in training
    steps.

parallel : joblib.Parallel, default=None
    Pre-initialized instance of joblib.Parallel.

Returns
-------
(doc_topic_distr, suff_stats) :
    `doc_topic_distr` is unnormalized topic distribution for each
    document. In the literature, this is called `gamma`.
    `suff_stats` is expected sufficient statistics for the M-step.
    When `cal_sstats == False`, it will be None.

Nr   r   rl   rm   c           
   3      >#    U  HO  n[        [        5      " TUS S 24   TR                  TR                  TR                  TR
                  TT5      v   MQ     g 7frt   )r   rV   r   r|   r<   r=   ).0	idx_slicer9   r>   r?   ru   s     rU   	<genexpr>4LatentDirichletAllocation._e_step.<locals>.<genexpr>  sc      
 A	 ,-)Q,--%%(($$  As   AAr   )ry   r   rl   r   maxrm   r   r%   zipr(   vstackr+   r~   r    r   )ru   r9   r>   random_initparallelrl   results
doc_topicssstats_listrD   rF   sstatsr?   s   ```         @rU   _e_step!LatentDirichletAllocation._e_step  s    > .9t))d "$++.vs1dllQ>N7OPH 
 -QWWQZ@
 
 #&w-
))J/ $"2"2"8"8@P@P@V@VWJ%$
 &$777J  ,, J,,rW   c                    U R                  USSUS9u  pVU(       a  U R                  U-   U l        O[        R                  " U R
                  U R                  -   U R                  * 5      n[        U5      UR                  S   -  nU =R                  SU-
  -  sl        U =R                  UU R                  X-  -   -  -  sl        [        R                  " [        U R                  5      5      U l        U =R                  S-  sl        g)av  EM update for 1 iteration.

update `component_` by batch VB or online VB.

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

total_samples : int
    Total number of documents. It is only used when
    batch_update is `False`.

batch_update : bool
    Parameter that controls updating method.
    `True` for batch learning, `False` for online learning.

parallel : joblib.Parallel, default=None
    Pre-initialized instance of joblib.Parallel

Returns
-------
doc_topic_distr : ndarray of shape (n_samples, n_components)
    Unnormalized document topic distribution.
Tr>   r   r   r   r   N)r   r}   r~   r(   powerrd   rz   rc   r!   r%   r*   r   r   )	ru   r9   rj   batch_updater   rR   rF   weight	doc_ratios	            rU   _em_step"LatentDirichletAllocation._em_step  s    8 $D8 % 

 #55
BD XX$$t'9'99D<O<O;OF m,qwwqz9IF
*&&)??! 
 )+%d&6&67)
% 	arW   c                    > [         TU ]  5       nSUR                  l        SUR                  l        SS/UR
                  l        U$ )NTr/   float64)super__sklearn_tags__
input_tagspositive_onlysparsetransformer_tagspreserves_dtype)ru   tags	__class__s     rU   r   *LatentDirichletAllocation.__sklearn_tags__%  s@    w')(,%!%1:I0F-rW   c                     U(       a   [         R                  [         R                  /OU R                  R                  n[        U UUSUS9n[        X5        U$ )z~check X format

check X format and make sure no negative value in X.

Parameters
----------
X :  array-like or sparse matrix

csr)resetaccept_sparser    )r(   r   r/   r~   r    r   r   )ru   r9   reset_n_featureswhomr    s        rU   _check_non_neg_array.LatentDirichletAllocation._check_non_neg_array,  sN     -=RZZ($BRBRBXBX"
 	1#rW   T)prefer_skip_nested_validationc           	      J   [        U S5      (       + nU R                  XSS9nUR                  u  pEU R                  nU(       a  U R	                  XQR
                  S9  XPR                  R                  S   :w  a&  [        SXPR                  R                  S   4-  5      e[        U R                  5      n[        U[        SU R                  S-
  5      S9 n[        XF5       H%  n	U R                  XS	S	24   U R                  S
US9  M'     S	S	S	5        U $ ! , (       d  f       U $ = f)a  Online VB with Mini-Batch update.

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

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

Returns
-------
self
    Partially fitted estimator.
r~   z%LatentDirichletAllocation.partial_fitr   r   r   r   zUThe provided data has %d dimensions while the model was trained with feature size %d.r   r   NFrj   r   r   )hasattrr   r%   rh   r   r    r~   
ValueErrorr   rl   r   r   rm   r   r   rj   )
ru   r9   y
first_timerA   rB   rh   rl   r   r   s
             rU   partial_fit%LatentDirichletAllocation.partial_fitC  s'   " !}55
%%1X & 
 !"	__
 "":WW"=))//22>//55a89:  "$++.VSDLL14D-EF((?	lO"&"4"4!&%	   @ G  GF s   5D
D"c           
         U R                  USSS9nUR                  u  p4U R                  nU R                  nU R                  nU R
                  nU R                  XAR                  S9  Sn	[        U R                  5      n
[        U
[        SU R                  S-
  5      S9 n[        U5       GH  nUS	:X  a+  [        X85       H  nU R                  XSS24   US
US9  M     OU R                  XSUS9  US:  a}  US-   U-  S:X  aq  U R!                  US
S
US9u  pU R#                  XS
S9nU R                  (       a  [%        SUS-   UU4-  5        U	(       a  ['        U	U-
  5      U R(                  :  a    OAUn	O$U R                  (       a  [%        SUS-   U4-  5        U =R*                  S-  sl        GM     SSS5        U R!                  US
S
WS9u  pU R#                  XS
S9U l        U $ ! , (       d  f       N9= f)a|  Learn model for the data X with variational Bayes method.

When `learning_method` is 'online', use mini-batch update.
Otherwise, use batch update.

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

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

Returns
-------
self
    Fitted estimator.
TzLatentDirichletAllocation.fitr   r   Nr   r   r   rb   Fr   r   sub_samplingz/iteration: %d of max_iter: %d, perplexity: %.4fziteration: %d of max_iter: %d)r   r%   rg   ri   r`   rh   r   r    r   rl   r   r   rm   r4   r   r   r   _perplexity_precomp_distrprintabsrk   r{   bound_)ru   r9   r   rA   rB   rg   ri   r`   rh   
last_boundrl   r   ir   doc_topics_distrrR   bounds                    rU   fitLatentDirichletAllocation.fits  s(   ( %%+J & 
 !"	==,,..__
 	z9
!$++.VSDLL14D-EF(8_"h.%0%G	lO*3).%-	 &  &H MMPX " 
 "A%1q5N*Ba*G*.,,e +7 +'$ !::% ; E ||M 1uh67
 "c*u*<&=&M!&J\\9QUH<MMN!G % GN #ll%UX + 
 44e 5 
 ] GFs   !DG''
G5c                 ,    U R                  USSS9u  p#U$ )a  Transform data X according to fitted model.

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

Returns
-------
doc_topic_distr : ndarray of shape (n_samples, n_components)
    Document topic distribution for X.
F)r>   r   )r   )ru   r9   rD   rR   s       rU   _unnormalized_transform1LatentDirichletAllocation._unnormalized_transform  s!     "\\!5\QrW   	normalizec                    [        U 5        U R                  USSS9nU R                  U5      nU(       a&  X3R                  SS9SS2[        R
                  4   -  nU$ )a  Transform data X according to the fitted model.

.. versionchanged:: 0.18
    `doc_topic_distr` is now normalized.

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

normalize : bool, default=True
    Whether to normalize the document topic distribution.

Returns
-------
doc_topic_distr : ndarray of shape (n_samples, n_components)
    Document topic distribution for X.
Fz#LatentDirichletAllocation.transformr   r   axisN)r   r   r   sumr(   newaxis)ru   r9   r   rD   s       rU   	transform#LatentDirichletAllocation.transform  sg    & 	%%,Q & 
 66q9222:1bjj=IIOrW   c                >    U R                  X5      R                  XS9$ )a*  
Fit to data, then transform it.

Fits transformer to `X` and `y` and returns a transformed version of `X`.

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

y :  array-like of shape (n_samples,) or (n_samples, n_outputs),                 default=None
    Target values (None for unsupervised transformations).

normalize : bool, default=True
    Whether to normalize the document topic distribution in `transform`.

Returns
-------
X_new : ndarray array of shape (n_samples, n_components)
    Transformed array.
r   )r   r   )ru   r9   r   r   s       rU   fit_transform'LatentDirichletAllocation.fit_transform  s     . xx~'''??rW   c                 4   S n[         R                  " U5      nUR                  u  pgU R                  R                  S   nSn	[	        U5      n
[	        U R                  5      nU R
                  nU R                  nU(       a$  UR                  nUR                  nUR                  n[        SU5       H  nU(       a  WWU   UUS-       nWUU   UUS-       nO'[        R                  " UUSS24   5      S   nUUU4   nU
USS2[        R                  4   USS2U4   -   n[        USS9nU	[        R                  " UU5      -  n	M     X" XXR                   5      -  n	U(       a  [#        U R$                  5      U-  nU	U-  n	X" XR                  X5      -  n	U	$ )a  Estimate the variational bound.

Estimate the variational bound over "all documents" using only the
documents passed in as X. Since log-likelihood of each word cannot
be computed directly, we use this bound to estimate it.

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

doc_topic_distr : ndarray of shape (n_samples, n_components)
    Document topic distribution. In the literature, this is called
    gamma.

sub_sampling : bool, default=False
    Compensate for subsampling of documents.
    It is used in calculate bound in online learning.

Returns
-------
score : float

c           
      "   [         R                  " X-
  U-  5      nU[         R                  " [        U5      [        U 5      -
  5      -  nU[         R                  " [        X-  5      [        [         R                  " US5      5      -
  5      -  nU$ )Nr   )r(   r   r   )priordistrdirichlet_distrsizescores        rU   _loglikelihood?LatentDirichletAllocation._approx_bound.<locals>._loglikelihood&  sk    FFEM_<=ERVVGENWU^;<<ERVVGEL1GBFF5!<L4MMNNELrW   r   r   Nr   )r#   r$   r%   r~   r   r|   r}   r,   r-   r.   r4   r(   r5   r   r   r6   r[   r!   rj   )ru   r9   rD   r   r   r@   rA   r[   rB   r   dirichlet_doc_topicdirichlet_component_r;   r_   rG   rH   rI   rL   rM   rN   temprT   r   s                          rU   _approx_bound'LatentDirichletAllocation._approx_bound  s   4	 kk!n"1"7"7	%%++A.
7H89I9IJ//11VVF		IxxH 1i(E(5192EFhuo0CDjj5!8-a0}#E1bjj$89<PQRTWQW<XX  !A.HRVVD(++E ) 	.ACTCT
 	

 d001I=IYE 	..0D
 	
 rW   c                     [        U 5        U R                  USSS9nU R                  U5      nU R                  XSS9nU$ )a/  Calculate approximate log-likelihood as score.

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

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

Returns
-------
score : float
    Use approximate bound as score.
FzLatentDirichletAllocation.scorer   r   )r   r   r   r   )ru   r9   r   rD   r   s        rU   r   LatentDirichletAllocation.score[  sU      	%%,M & 
 66q9""1E"JrW   c                    Uc  U R                  U5      nOEUR                  u  pEXAR                  S   :w  a  [        S5      eXPR                  :w  a  [        S5      eUR                  S   nU R	                  XU5      nU(       a*  UR                  5       [        U R                  5      U-  -  nOUR                  5       nXx-  n	[        R                  " SU	-  5      $ )a  Calculate approximate perplexity for data X with ability to accept
precomputed doc_topic_distr

Perplexity is defined as exp(-1. * log-likelihood per word)

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

doc_topic_distr : ndarray of shape (n_samples, n_components),                 default=None
    Document topic distribution.
    If it is None, it will be generated by applying transform on X.

Returns
-------
score : float
    Perplexity score.
r   z8Number of samples in X and doc_topic_distr do not match.z Number of topics does not match.g      )
r   r%   r   r[   r   r   r!   rj   r(   r*   )
ru   r9   rD   r   rA   r[   current_samplesr   word_cntperword_bounds
             rU   r   3LatentDirichletAllocation._perplexity_precomp_distrt  s    * ""::1=O&5&;&;#IGGAJ& N  000 !CDD''!*""1|Duuw%(:(:";o"MNHuuwH(vvd]*++rW   c                 X    [        U 5        U R                  USSS9nU R                  XS9$ )a  Calculate approximate perplexity for data X.

Perplexity is defined as exp(-1. * log-likelihood per word)

.. versionchanged:: 0.19
   *doc_topic_distr* argument has been deprecated and is ignored
   because user no longer has access to unnormalized distribution

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

sub_sampling : bool
    Do sub-sampling or not.

Returns
-------
score : float
    Perplexity score.
Tz$LatentDirichletAllocation.perplexityr   r   )r   r   r   )ru   r9   r   s      rU   
perplexity$LatentDirichletAllocation.perplexity  s?    , 	%%+Q & 
 --a-KKrW   c                 4    U R                   R                  S   $ )z&Number of transformed output features.r   )r~   r%   )ru   s    rU   _n_features_out)LatentDirichletAllocation._n_features_out  s     %%a((rW   )rh   r   r~   r;   r|   ri   r   rc   r`   rd   r<   rg   r=   rz   r[   r{   rl   rk   r?   ry   r_   r}   rj   rm   )ro   rt   )NF)F)"__name__
__module____qualname____firstlineno____doc__r   r   r   r   rn   dict__annotations__rv   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   propertyr   __static_attributes____classcell__)r   s   @rU   rY   rY      s{   ob$(AtIFG$D(4Af"EF$ 	T8D!Qv#FG$ 	J':;<	$
 	8D!Qv>?$ 	HT3VDE$ 	Xh4?@$ 	x!T)DE$ 	8HdDKL$ 	(4DCD$ 	XdAtF;<$ 	HT1d6BC$ 	1d6 JK$ 	4"$ 	I;$  	(!$D * #) %#)J 35** 
:@-D4l. 5- 6-^ 5P 6Pd" )- 8@D @2M^2*,XL8 ) )rW   rY   )-r   numbersr   r   numpyr(   scipy.sparser   r#   joblibr   scipy.specialr   r   baser	   r
   r   r   utilsr   r   r   utils._param_validationr   r   utils.parallelr   r   utils.validationr   r   r   _online_lda_fastr   r1   r   r   r0   r2   r!   r3   EPSrV   rY    rW   rU   <module>r
     sy    #   # ,  E D : . Q Q 	hhuou)p[)#%5}[)rW   