§
    ¨éUgN  ã                   ó†   — 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  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_is_fittedc                   ó`   — 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        |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   )r   Úcomponents_Úexplained_variance_ÚwhitenÚsqrtÚnpÚnewaxisÚnoise_variance_ÚwhereÚasarrayr   ÚTr
   )ÚselfÚxpÚ_r   Úexp_varÚexp_var_diffÚcovs          úZ/var/www/surfInsights/venv3-11/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Ñ3Ô3ñ
ô 
ˆð
 Œ}˜|Ñ+¨{Ñ:ˆÝ˜˜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   Nr   g      ð?r   )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_precision:   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.fitg   s   € € € r%   c                 óÖ   — t          || j        | j        ¦  «        \  }}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)ÚdtypeÚaccept_sparseÚreset)r   Úx_is_centered)r   r   r   r   Ú_validate_dataÚfloat64Úfloat32Ú
_transform)r   r3   r   r   s       r#   Ú	transformz_BasePCA.transformy   st   € õ$ ˜a Ô!1°4Ô3KÑLÔL‰ˆˆAå˜ÑÔÐà×ÒØ�b”j "¤*Ð-¸^ÐSXð  ñ 
ô 
ˆð �Š˜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   Úfinfor9   Úeps)r   r3   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                 óÞ   — t          |¦  «        \  }}| 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.
        N)r   r   r   r   r   r   r   rE   )r   r3   r   r   Úscaled_componentss        r#   Úinverse_transformz_BasePCA.inverse_transform¨   sw   € õ, ˜aÑ Ô ‰ˆˆAàŒ;ð 	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$   r0   r   r5   rA   r@   rM   ÚpropertyrO   r2   r%   r#   r   r      s«   € € € € € ðð ðð ð ð8+ð +ð +ðZ ðð ð ñ „^ðð">ð >ð >ð6ð ð ð ð(5ð 5ð 5ð@ ð)ð )ñ „Xð)ð )ð )r%   r   )Ú	metaclass)rS   Úabcr   r   Únumpyr   Úscipyr   Úbaser   r   r	   Úutils._array_apir
   r   r   Úutils.validationr   r   r2   r%   r#   ú<module>r\      sÞ   ðØ /Ð /ð (Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à Ð Ð Ð Ø Ð Ð Ð Ð Ð à SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SØ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FÐ FØ .Ð .Ð .Ð .Ð .Ð .ðv)ð v)ð v)ð v)ð v)Ø#Ð%5°}ÐPWðv)ñ v)ô v)ð v)ð v)ð v)r%   