@@ -427,9 +427,8 @@ def _fit(self, X, compute_sources=False):
427
427
-------
428
428
X_new : ndarray of shape (n_samples, n_components)
429
429
"""
430
-
431
- X = self ._validate_data (X , copy = self .whiten , dtype = FLOAT_DTYPES ,
432
- ensure_min_samples = 2 ).T
430
+ XT = self ._validate_data (X , copy = self .whiten , dtype = FLOAT_DTYPES ,
431
+ ensure_min_samples = 2 ).T
433
432
fun_args = {} if self .fun_args is None else self .fun_args
434
433
random_state = check_random_state (self .random_state )
435
434
@@ -454,7 +453,7 @@ def g(x, fun_args):
454
453
% self .fun
455
454
)
456
455
457
- n_samples , n_features = X .shape
456
+ n_features , n_samples = XT .shape
458
457
459
458
n_components = self .n_components
460
459
if not self .whiten and n_components is not None :
@@ -471,24 +470,24 @@ def g(x, fun_args):
471
470
)
472
471
473
472
if self .whiten :
474
- # Centering the columns (ie the variables)
475
- X_mean = X .mean (axis = - 1 )
476
- X -= X_mean [:, np .newaxis ]
473
+ # Centering the features of X
474
+ X_mean = XT .mean (axis = - 1 )
475
+ XT -= X_mean [:, np .newaxis ]
477
476
478
477
# Whitening and preprocessing by PCA
479
- u , d , _ = linalg .svd (X , full_matrices = False , check_finite = False )
478
+ u , d , _ = linalg .svd (XT , full_matrices = False , check_finite = False )
480
479
481
480
del _
482
481
K = (u / d ).T [:n_components ] # see (6.33) p.140
483
482
del u , d
484
- X1 = np .dot (K , X )
483
+ X1 = np .dot (K , XT )
485
484
# see (13.6) p.267 Here X1 is white and data
486
485
# in X has been projected onto a subspace by PCA
487
- X1 *= np .sqrt (n_features )
486
+ X1 *= np .sqrt (n_samples )
488
487
else :
489
488
# X must be casted to floats to avoid typing issues with numpy
490
489
# 2.0 and the line below
491
- X1 = as_float_array (X , copy = False ) # copy has been taken care of
490
+ X1 = as_float_array (XT , copy = False ) # copy has been taken care of
492
491
493
492
w_init = self .w_init
494
493
if w_init is None :
@@ -519,9 +518,9 @@ def g(x, fun_args):
519
518
520
519
if compute_sources :
521
520
if self .whiten :
522
- S = np .linalg .multi_dot ([W , K , X ]).T
521
+ S = np .linalg .multi_dot ([W , K , XT ]).T
523
522
else :
524
- S = np .dot (W , X ).T
523
+ S = np .dot (W , XT ).T
525
524
else :
526
525
S = None
527
526
0 commit comments