ó
    §ñ:iN  ã            	       óx   • S r SSKJrJr  SSKrSSKJr  SSKJ	r	J
r
Jr  SSKJrJrJr  SSKJr   " S	 S
\
\\	\S9rg)z)Principal Component Analysis Base Classesé    )ÚABCMetaÚabstractmethodN)Úlinalgé   )ÚBaseEstimatorÚClassNamePrefixFeaturesOutMixinÚTransformerMixin)Ú_add_to_diagonalÚdeviceÚget_namespace)Úcheck_is_fittedc                   ó^   • \ rS rSrSrS rS r\SS j5       rS r	SS jr
S	 r\S
 5       rSrg)Ú_BasePCAé   zkBase class for PCA methods.

Warning: This class should not be used directly.
Use derived classes instead.
c           
      ó®  • [        U R                  5      u  pU R                  nU R                  nU R                  (       a(  X1R	                  USS2[
        R                  4   5      -  nX@R                  -
  nUR                  X@R                  :„  UUR                  S[        U5      S95      nUR                  U-  U-  n[        X`R                  U5        U$ )a3  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          Ú^/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/sklearn/decomposition/_base.pyÚget_covarianceÚ_BasePCA.get_covariance   sº   € ô ˜d×.Ñ.Ó/‰ˆà×&Ñ&ˆØ×*Ñ*ˆØ�;�;Ø%¯©°º¼2¿:¹:¸Ñ0FÓ(GÑGˆKØ×!5Ñ!5Ñ5ˆØ—x‘xØ×*Ñ*Ñ*ØØ�J‰J�s¤6¨'£?ˆJÐ3ó
ˆð
 �}‰}˜|Ñ+¨{Ñ:ˆÜ˜×2Ñ2°BÔ7Øˆ
ó    c           
      ór  • [        U R                  5      u  pU R                  R                  S   nU R                  S:X  a  UR	                  U5      U R
                  -  $ U(       a  UR                  R                  nO[        R                  nU R
                  S:X  a  U" U R                  5       5      $ U R                  nU R                  nU R                  (       a(  XQR                  USS2[        R                  4   5      -  nX`R
                  -
  nUR                  X`R
                  :„  UUR                  S[!        U5      S95      nXUR"                  -  U R
                  -  n[%        USU-  U5        UR"                  U" U5      -  U-  nX€R
                  S-  * -  n[%        USU R
                  -  U5        U$ )a   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_precisionÚ_BasePCA.get_precision:   sƒ  € ô &3°4×3CÑ3CÓ%DÑ"ˆà×%Ñ%×+Ñ+¨AÑ.ˆ
ð ×Ñ Ó"Ø—6‘6˜*Ó%¨×(<Ñ(<Ñ<Ð<æ!ØŸ™Ÿ™‰JäŸ™ˆJà×Ñ 3Ó&Ù˜d×1Ñ1Ó3Ó4Ð4ð ×&Ñ&ˆØ×*Ñ*ˆØ�;�;Ø%¯©°º¼2¿:¹:¸Ñ0FÓ(GÑGˆKØ×!5Ñ!5Ñ5ˆØ—x‘xØ×*Ñ*Ñ*ØØ�J‰J�s¤6¨'£?ˆJÐ3ó
ˆð
  §-¡-Ñ/°$×2FÑ2FÑFˆ	Ü˜ C¨,Ñ$6¸Ô;Ø—M‘M¡J¨yÓ$9Ñ9¸KÑGˆ	Ø×+Ñ+¨QÑ.Ð/Ñ/ˆ	Ü˜ C¨$×*>Ñ*>Ñ$>ÀÔCØÐr'   Nc                 ó   • g)aJ  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$   ÚfitÚ_BasePCA.fitg   s   � r'   c                 óÊ   • [        XR                  U R                  5      u  p#[        U 5        U R	                  XR
                  UR                  /SSS9nU R                  XSS9$ )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   r6   r   r    s       r$   Ú	transformÚ_BasePCA.transformy   se   € ô$ ˜a×!1Ñ!1°4×3KÑ3KÓL‰ˆä˜Ôà×ÑØ—j‘j "§*¡*Ð-¸^ÐSXð  ð 
ˆð �‰˜q°uˆÐ=Ð=r'   c                 ód  • XR                   R                  -  nU(       d5  XBR                  U R                  S5      U R                   R                  -  -  nU R                  (       aJ  UR                  U R                  5      nUR                  UR                  5      R                  nXeXV:  '   XE-  nU$ )N)r)   éÿÿÿÿ)
r   r   ÚreshapeÚmean_r   r   r   Úfinfor=   Úeps)r   r6   r   r@   ÚX_transformedÚscaleÚ	min_scales          r$   rD   Ú_BasePCA._transform”   s‘   € Ø×,Ñ,×.Ñ.Ñ.ˆÞð ŸZ™Z¨¯
©
°GÓ<¸t×?OÑ?O×?QÑ?QÑQÑQˆMØ�;�;ð
 —G‘G˜D×4Ñ4Ó5ˆEØŸ™ §¡Ó-×1Ñ1ˆIØ'0�%Ñ#Ñ$ØÑ"ˆMØÐr'   c                 ó  • [        U5      u  p#U R                  (       aN  UR                  U R                  SS2[        R
                  4   5      U R                  -  nX-  U R                  -   $ XR                  -  U R                  -   $ )ag  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   rJ   )r   r6   r   r    Úscaled_componentss        r$   Úinverse_transformÚ_BasePCA.inverse_transform¨   sr   € ô, ˜aÓ ‰ˆà�;�;à—‘˜×0Ñ0²´B·J±J°Ñ?Ó@À4×CSÑCSÑSð ð Ñ(¨4¯:©:Ñ5Ð5à×'Ñ'Ñ'¨$¯*©*Ñ4Ð4r'   c                 ó4   • U R                   R                  S   $ )z&Number of transformed output features.r   )r   r*   )r   s    r$   Ú_n_features_outÚ_BasePCA._n_features_outÈ   s   € ð ×Ñ×%Ñ% aÑ(Ð(r'   r5   )N)F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r%   r2   r   r8   rE   rD   rS   ÚpropertyrV   Ú__static_attributes__r5   r'   r$   r   r      sJ   † ñòò8+ðZ óó ðò">ô6ò(5ð@ ñ)ó ó)r'   r   )Ú	metaclass)r\   Úabcr   r   Únumpyr   Úscipyr   Úbaser   r   r	   Úutils._array_apir
   r   r   Úutils.validationr   r   r5   r'   r$   Ú<module>rf      s9   ðÙ /÷ (ã Ý ç SÑ Sß FÑ FÝ .ôv)Ø#Ð%5°}ÐPWóv)r'   