§
    qŠtj’  ã                   óŽ   — d Z ddlmZmZ ddl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mZmZ  G d„ d	e
ee	e¬
¦  «        ZdS )z)Principal Component Analysis Base Classesé    )ÚABCMetaÚabstractmethodN)Úlinalg)ÚBaseEstimatorÚClassNamePrefixFeaturesOutMixinÚTransformerMixin)Ú_add_to_diagonalÚdeviceÚget_namespace)Úcheck_arrayÚcheck_is_fittedÚvalidate_datac                   ó`   — e Zd ZdZd„ Zd„ Zedd„¦   «         Zd„ Zdd„Z	d	„ Z
ed
„ ¦   «         ZdS )Ú_BasePCAzwBase class for PCA methods.

    Warning: This class should not be used directly.
    Use derived classes instead.
    c           
      ó   — t          | j        ¦  «        \  }}| j        }| j        }| j        r,||                     |dd…t
          j        f         ¦  «        z  }|| j        z
  }|                     || j        k    || 	                    dt          |¦  «        |j        ¬¦  «        ¦  «        }|j        |z  |z  }t          || j        |¦  «         |S )as  Compute data covariance with the generative model.

        ``cov = components_.T * S**2 * components_ + sigma2 * eye(n_features)``
        where S**2 contains the explained variances, and sigma2 contains the
        noise variances.

        Returns
        -------
        cov : array of shape=(n_features, n_features)
            Estimated covariance of data.
        Nç        )r
   Údtype)r   Úcomponents_Úexplained_variance_ÚwhitenÚsqrtÚnpÚnewaxisÚnoise_variance_ÚwhereÚasarrayr
   r   ÚTr	   )ÚselfÚxpÚ_r   Úexp_varÚexp_var_diffÚcovs          úY/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/decomposition/_base.pyÚget_covariancez_BasePCA.get_covariance   sÐ   € õ ˜dÔ.Ñ/Ô/‰ˆˆAàÔ&ˆØÔ*ˆØŒ;ð 	HØ%¨¯ª°¸¸¸½2¼:¸Ô0FÑ(GÔ(GÑGˆKØ Ô!5Ñ5ˆØ—x’xØ�dÔ*Ò*ØØ�JŠJ�s¥6¨'¡?¤?¸'¼-ˆJÑHÔHñ
ô 
ˆð
 Œ}˜|Ñ+¨{Ñ:ˆÝ˜˜dÔ2°BÑ7Ô7Ð7Øˆ
ó    c           
      ó  — t          | j        ¦  «        \  }}| j        j        d         }| j        dk    r|                     |¦  «        | j        z  S |r|j        j        }nt          j        }| j        dk    r ||                      ¦   «         ¦  «        S | j        }| j	        }| j
        r,||                     |dd…t          j        f         ¦  «        z  }|| j        z
  }|                     || j        k    ||                     dt!          |¦  «        ¬¦  «        ¦  «        }||j        z  | j        z  }t%          |d|z  |¦  «         |j         ||¦  «        z  |z  }|| j        dz   z  }t%          |d| j        z  |¦  «         |S )a8  Compute data precision matrix with the generative model.

        Equals the inverse of the covariance but computed with
        the matrix inversion lemma for efficiency.

        Returns
        -------
        precision : array, shape=(n_features, n_features)
            Estimated precision of data.
        é   r   r   N)r
   g      ð?é   )r   r   ÚshapeÚn_components_Úeyer   r   Úinvr%   r   r   r   r   r   r   r   r
   r   r	   )	r   r   Úis_array_api_compliantÚ
n_featuresÚ
linalg_invr   r!   r"   Ú	precisions	            r$   Úget_precisionz_BasePCA.get_precision9   sž  € õ &3°4Ô3CÑ%DÔ%DÑ"ˆÐ"àÔ%Ô+¨AÔ.ˆ
ð Ô Ò"Ð"Ø—6’6˜*Ñ%Ô%¨Ô(<Ñ<Ð<à!ð 	$ØœœˆJˆJåœˆJàÔ 3Ò&Ð&Ø�:˜d×1Ò1Ñ3Ô3Ñ4Ô4Ð4ð Ô&ˆØÔ*ˆØŒ;ð 	HØ%¨¯ª°¸¸¸½2¼:¸Ô0FÑ(GÔ(GÑGˆKØ Ô!5Ñ5ˆØ—x’xØ�dÔ*Ò*ØØ�JŠJ�s¥6¨'¡?¤?ˆJÑ3Ô3ñ
ô 
ˆð
   +¤-Ñ/°$Ô2FÑFˆ	Ý˜ C¨,Ñ$6¸Ñ;Ô;Ð;Ø”M J J¨yÑ$9Ô$9Ñ9¸KÑGˆ	Ø�tÔ+¨QÑ.Ð/Ñ/ˆ	Ý˜ C¨$Ô*>Ñ$>ÀÑCÔCÐCØÐr&   Nc                 ó   — dS )a¢  Placeholder for fit. Subclasses should implement this method!

        Fit the model with X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training data, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        Returns
        -------
        self : object
            Returns the instance itself.
        N© )r   ÚXÚys      r$   Úfitz_BasePCA.fitf   s   € € € r&   c                 óÌ   — t          || j        | j        ¦  «        \  }}t          | ¦  «         t	          | ||j        |j        gdd¬¦  «        }|                      ||d¬¦  «        S )a‹  Apply dimensionality reduction to X.

        X is projected on the first principal components previously extracted
        from a training set.

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

        Returns
        -------
        X_new : array-like of shape (n_samples, n_components)
            Projection of X in the first principal components, where `n_samples`
            is the number of samples and `n_components` is the number of the components.
        )ÚcsrÚcscF)r   Úaccept_sparseÚreset)r   Úx_is_centered)r   r   r   r   r   Úfloat64Úfloat32Ú
_transform)r   r5   r   r    s       r$   Ú	transformz_BasePCA.transformx   ss   € õ$ ˜a Ô!1°4Ô3KÑLÔL‰ˆˆAå˜ÑÔÐåØØØ”:˜rœzÐ*Ø(Øð
ñ 
ô 
ˆð �Š˜q R°uˆÑ=Ô=Ð=r&   Fc                 ó  — || j         j        z  }|s+||                     | j        d¦  «        | j         j        z  z  }| j        rG|                     | j        ¦  «        }|                     |j        ¦  «        j	        }||||k     <   ||z  }|S )N)r(   éÿÿÿÿ)
r   r   ÚreshapeÚmean_r   r   r   Úfinfor   Úeps)r   r5   r   r=   ÚX_transformedÚscaleÚ	min_scales          r$   r@   z_BasePCA._transform—   s—   € Ø˜DÔ,Ô.Ñ.ˆØð 	Rð ˜RŸZšZ¨¬
°GÑ<Ô<¸tÔ?OÔ?QÑQÑQˆMØŒ;ð 	#ð
 —G’G˜DÔ4Ñ5Ô5ˆEØŸš ¤Ñ-Ô-Ô1ˆIØ'0ˆE�%˜)Ò#Ñ$Ø˜UÑ"ˆMØÐr&   c                 óP  — t          || j        | j        ¦  «        \  }}t          | ¦  «         t	          |d|j        |j        g¬¦  «        }| j        rC|                     | j        dd…t          j
        f         ¦  «        | j        z  }||z  | j        z   S || j        z  | j        z   S )aé  Transform data back to its original space.

        In other words, return an input `X_original` whose transform would be X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_components)
            New data, where `n_samples` is the number of samples
            and `n_components` is the number of components.

        Returns
        -------
        X_original : array-like of shape (n_samples, n_features)
            Original data, where `n_samples` is the number of samples
            and `n_features` is the number of features.

        Notes
        -----
        If whitening is enabled, inverse_transform will compute the
        exact inverse operation, which includes reversing whitening.
        r5   )Ú
input_namer   N)r   r   r   r   r   r>   r?   r   r   r   r   rE   )r   r5   r   r    Úscaled_componentss        r$   Úinverse_transformz_BasePCA.inverse_transform«   s¬   € õ, ˜a Ô!1°4Ô3KÑLÔL‰ˆˆAå˜ÑÔÐå˜ c°"´*¸b¼jÐ1IÐJÑJÔJˆàŒ;ð 	5à—’˜Ô0°°°µB´J°Ô?Ñ@Ô@À4ÔCSÑSð ð Ð(Ñ(¨4¬:Ñ5Ð5à�tÔ'Ñ'¨$¬*Ñ4Ð4r&   c                 ó&   — | j         j        d         S )z&Number of transformed output features.r   )r   r*   )r   s    r$   Ú_n_features_outz_BasePCA._n_features_outÏ   s   € ð ÔÔ% aÔ(Ð(r&   )N)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r2   r   r7   rA   r@   rN   ÚpropertyrP   r4   r&   r$   r   r      s«   € € € € € ðð ðð ð ð8+ð +ð +ðZ ðð ð ñ „^ðð">ð >ð >ð>ð ð ð ð("5ð "5ð "5ðH ð)ð )ñ „Xð)ð )ð )r&   r   )Ú	metaclass)rT   Úabcr   r   Únumpyr   Úscipyr   Úsklearn.baser   r   r   Úsklearn.utils._array_apir	   r
   r   Úsklearn.utils.validationr   r   r   r   r4   r&   r$   ú<module>r]      s  ðØ /Ð /ð
 (Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð
 MÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LÐ LØ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ Pð~)ð ~)ð ~)ð ~)ð ~)Ø#Ð%5°}ÐPWð~)ñ ~)ô ~)ð ~)ð ~)ð ~)r&   