@@ -40,14 +40,26 @@ def _nipals_twoblocks_inner_loop(X, Y, mode="A", max_iter=500, tol=1e-06,
40
40
ite = 1
41
41
X_pinv = Y_pinv = None
42
42
eps = np .finfo (X .dtype ).eps
43
+
44
+ if mode == "B" :
45
+ # Uses condition from scipy<1.3 in pinv2 which was changed in
46
+ # https://github.com/scipy/scipy/pull/10067. In scipy 1.3, the
47
+ # condition was changed to depend on the largest singular value
48
+ X_t = X .dtype .char .lower ()
49
+ Y_t = Y .dtype .char .lower ()
50
+ factor = {'f' : 1E3 , 'd' : 1E6 }
51
+
52
+ cond_X = factor [X_t ] * eps
53
+ cond_Y = factor [Y_t ] * eps
54
+
43
55
# Inner loop of the Wold algo.
44
56
while True :
45
57
# 1.1 Update u: the X weights
46
58
if mode == "B" :
47
59
if X_pinv is None :
48
60
# We use slower pinv2 (same as np.linalg.pinv) for stability
49
61
# reasons
50
- X_pinv = pinv2 (X , check_finite = False )
62
+ X_pinv = pinv2 (X , check_finite = False , cond = cond_X )
51
63
x_weights = np .dot (X_pinv , y_score )
52
64
else : # mode A
53
65
# Mode A regress each X column on y_score
@@ -64,7 +76,8 @@ def _nipals_twoblocks_inner_loop(X, Y, mode="A", max_iter=500, tol=1e-06,
64
76
# 2.1 Update y_weights
65
77
if mode == "B" :
66
78
if Y_pinv is None :
67
- Y_pinv = pinv2 (Y , check_finite = False ) # compute once pinv(Y)
79
+ # compute once pinv(Y)
80
+ Y_pinv = pinv2 (Y , check_finite = False , cond = cond_Y )
68
81
y_weights = np .dot (Y_pinv , x_score )
69
82
else :
70
83
# Mode A regress each Y column on x_score
0 commit comments