§
     ã h`  ã                   ór   — d Z ddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZmZ  G d„ d	eeee¬
¦  «        ZdS )z)Principal Component Analysis Base Classesé    N)Úlinalgé   )ÚBaseEstimatorÚTransformerMixinÚClassNamePrefixFeaturesOutMixin)Úcheck_is_fitted)ÚABCMetaÚabstractmethodc                   óX   — e Zd ZdZd„ Zd„ Zed	d„¦   «         Z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        r+|t          j        |dd…t          j        f         ¦  «        z  }t          j        || j        z
  d¦  «        }t          j        |j	        |z  |¦  «        }|j
        ddt          |¦  «        dz   …xx         | j        z  cc<   |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ç        é   )Úcomponents_Úexplained_variance_ÚwhitenÚnpÚsqrtÚnewaxisÚmaximumÚnoise_variance_ÚdotÚTÚflatÚlen)Úselfr   Úexp_varÚexp_var_diffÚcovs        úW/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/sklearn/decomposition/_base.pyÚget_covariancez_BasePCA.get_covariance   s©   € ð Ô&ˆØÔ*ˆØŒ;ð 	HØ%­¬°¸¸¸½2¼:¸Ô0FÑ(GÔ(GÑGˆKÝ”z '¨DÔ,@Ñ"@À#ÑFÔFˆÝŒf[”] \Ñ1°;Ñ?Ô?ˆØŒ•C˜‘H”H˜q‘LÐ!Ð!Ô! TÔ%9Ñ9Ð!Ð!Ñ!Øˆ
ó    c                 óJ  — | j         j        d         }| j        dk    rt          j        |¦  «        | j        z  S t          j        | j        dd¬¦  «        r&t          j        |  	                    ¦   «         ¦  «        S | j         }| j
        }| j        r+|t          j        |dd…t          j        f         ¦  «        z  }t          j        || j        z
  d¦  «        }t          j        ||j        ¦  «        | j        z  }|j        ddt%          |¦  «        dz   …xx         d|z  z  cc<   t          j        |j        t          j        t          j        |¦  «        |¦  «        ¦  «        }|| j        dz   z  }|j        ddt%          |¦  «        dz   …xx         d| j        z  z  cc<   |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   r   )ÚatolNg      ð?r   )r   ÚshapeÚn_components_r   Úeyer   Úiscloser   Úinvr!   r   r   r   r   r   r   r   r   r   )r   Ú
n_featuresr   r   r   Ú	precisions         r    Úget_precisionz_BasePCA.get_precision1   s  € ð Ô%Ô+¨AÔ.ˆ
ð Ô Ò"Ð"Ý”6˜*Ñ%Ô%¨Ô(<Ñ<Ð<åŒ:dÔ*¨C°cÐ:Ñ:Ô:ð 	5Ý”:˜d×1Ò1Ñ3Ô3Ñ4Ô4Ð4ð Ô&ˆØÔ*ˆØŒ;ð 	HØ%­¬°¸¸¸½2¼:¸Ô0FÑ(GÔ(GÑGˆKÝ”z '¨DÔ,@Ñ"@À#ÑFÔFˆÝ”F˜;¨¬Ñ6Ô6¸Ô9MÑMˆ	ØŒÐ,Ð,#˜i™.œ.¨1Ñ,Ð,Ð-Ð-Ô-°°|Ñ1CÑCÐ-Ð-Ñ-Ý”F˜;œ=­"¬&µ´¸IÑ1FÔ1FÈÑ*TÔ*TÑUÔUˆ	ØtÔ+¨QÑ.Ð/Ñ/ˆ	ØŒÐ,Ð,#˜i™.œ.¨1Ñ,Ð,Ð-Ð-Ô-°°tÔ7KÑ1KÑKÐ-Ð-Ñ-ØÐ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.fitR   s   € € € r"   c                 ó&  — t          | ¦  «         |                      |t          j        t          j        gd¬¦  «        }| j        
|| j        z
  }t          j        || j        j        ¦  «        }| j	        r|t          j
        | j        ¦  «        z  }|S )az  Apply dimensionality reduction to X.

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

        Parameters
        ----------
        X : array-like 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.
        F)ÚdtypeÚreset)r   Ú_validate_datar   Úfloat64Úfloat32Úmean_r   r   r   r   r   r   )r   r/   ÚX_transformeds      r    Ú	transformz_BasePCA.transformd   s†   € õ$ 	˜ÑÔÐà×Ò ­"¬*µb´jÐ)AÈÐÑOÔOˆØŒ:Ð!ØD”J‘ˆAÝœ˜q $Ô"2Ô"4Ñ5Ô5ˆØŒ;ð 	?ØRœW TÔ%=Ñ>Ô>Ñ>ˆMØÐr"   c                 óô   — | j         rPt          j        |t          j        | j        dd…t          j        f         ¦  «        | j        z  ¦  «        | j        z   S t          j        || j        ¦  «        | 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.
        N)r   r   r   r   r   r   r   r8   )r   r/   s     r    Úinverse_transformz_BasePCA.inverse_transform€   sv   € ð, Œ;ð 		<å”ØÝ”G˜DÔ4°Q°Q°Q½¼
°]ÔCÑDÔDÀtÔGWÑWñô ð ”*ñ	ðõ ”6˜!˜TÔ-Ñ.Ô.°´Ñ;Ð;r"   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)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r,   r
   r1   r:   r<   Úpropertyr>   r.   r"   r    r   r      s—   € € € € € ðð ðð ð ð*ð ð ðB ðð ð ñ „^ðð"ð ð ð8<ð <ð <ðB ð)ð )ñ „Xð)ð )ð )r"   r   )Ú	metaclass)rB   Únumpyr   Úscipyr   Úbaser   r   r   Úutils.validationr   Úabcr	   r
   r   r.   r"   r    ú<module>rJ      sÀ   ðØ /Ð /ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SØ .Ð .Ð .Ð .Ð .Ð .Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'ðQ)ð Q)ð Q)ð Q)ð Q)Ø#Ð%5°}ÐPWðQ)ñ Q)ô Q)ð Q)ð Q)ð Q)r"   