@@ -1194,142 +1194,6 @@ def cohere(x, y, NFFT=256, Fs=2, detrend=detrend_none, window=window_hanning,
11941194 return Cxy , f
11951195
11961196
1197- @cbook .deprecated ('2.2' )
1198- class PCA (object ):
1199- def __init__ (self , a , standardize = True ):
1200- """
1201- compute the SVD of a and store data for PCA. Use project to
1202- project the data onto a reduced set of dimensions
1203-
1204- Parameters
1205- ----------
1206- a : np.ndarray
1207- A numobservations x numdims array
1208- standardize : bool
1209- True if input data are to be standardized. If False, only centering
1210- will be carried out.
1211-
1212- Attributes
1213- ----------
1214- a
1215- A centered unit sigma version of input ``a``.
1216-
1217- numrows, numcols
1218- The dimensions of ``a``.
1219-
1220- mu
1221- A numdims array of means of ``a``. This is the vector that points
1222- to the origin of PCA space.
1223-
1224- sigma
1225- A numdims array of standard deviation of ``a``.
1226-
1227- fracs
1228- The proportion of variance of each of the principal components.
1229-
1230- s
1231- The actual eigenvalues of the decomposition.
1232-
1233- Wt
1234- The weight vector for projecting a numdims point or array into
1235- PCA space.
1236-
1237- Y
1238- A projected into PCA space.
1239-
1240- Notes
1241- -----
1242- The factor loadings are in the ``Wt`` factor, i.e., the factor loadings
1243- for the first principal component are given by ``Wt[0]``. This row is
1244- also the first eigenvector.
1245-
1246- """
1247- n , m = a .shape
1248- if n < m :
1249- raise RuntimeError ('we assume data in a is organized with '
1250- 'numrows>numcols' )
1251-
1252- self .numrows , self .numcols = n , m
1253- self .mu = a .mean (axis = 0 )
1254- self .sigma = a .std (axis = 0 )
1255- self .standardize = standardize
1256-
1257- a = self .center (a )
1258-
1259- self .a = a
1260-
1261- U , s , Vh = np .linalg .svd (a , full_matrices = False )
1262-
1263- # Note: .H indicates the conjugate transposed / Hermitian.
1264-
1265- # The SVD is commonly written as a = U s V.H.
1266- # If U is a unitary matrix, it means that it satisfies U.H = inv(U).
1267-
1268- # The rows of Vh are the eigenvectors of a.H a.
1269- # The columns of U are the eigenvectors of a a.H.
1270- # For row i in Vh and column i in U, the corresponding eigenvalue is
1271- # s[i]**2.
1272-
1273- self .Wt = Vh
1274-
1275- # save the transposed coordinates
1276- Y = np .dot (Vh , a .T ).T
1277- self .Y = Y
1278-
1279- # save the eigenvalues
1280- self .s = s ** 2
1281-
1282- # and now the contribution of the individual components
1283- vars = self .s / len (s )
1284- self .fracs = vars / vars .sum ()
1285-
1286- def project (self , x , minfrac = 0. ):
1287- '''
1288- project x onto the principle axes, dropping any axes where fraction
1289- of variance<minfrac
1290- '''
1291- x = np .asarray (x )
1292- if x .shape [- 1 ] != self .numcols :
1293- raise ValueError ('Expected an array with dims[-1]==%d' %
1294- self .numcols )
1295- Y = np .dot (self .Wt , self .center (x ).T ).T
1296- mask = self .fracs >= minfrac
1297- if x .ndim == 2 :
1298- Yreduced = Y [:, mask ]
1299- else :
1300- Yreduced = Y [mask ]
1301- return Yreduced
1302-
1303- def center (self , x ):
1304- '''
1305- center and optionally standardize the data using the mean and sigma
1306- from training set a
1307- '''
1308- if self .standardize :
1309- return (x - self .mu )/ self .sigma
1310- else :
1311- return (x - self .mu )
1312-
1313- @staticmethod
1314- def _get_colinear ():
1315- c0 = np .array ([
1316- 0.19294738 , 0.6202667 , 0.45962655 , 0.07608613 , 0.135818 ,
1317- 0.83580842 , 0.07218851 , 0.48318321 , 0.84472463 , 0.18348462 ,
1318- 0.81585306 , 0.96923926 , 0.12835919 , 0.35075355 , 0.15807861 ,
1319- 0.837437 , 0.10824303 , 0.1723387 , 0.43926494 , 0.83705486 ])
1320-
1321- c1 = np .array ([
1322- - 1.17705601 , - 0.513883 , - 0.26614584 , 0.88067144 , 1.00474954 ,
1323- - 1.1616545 , 0.0266109 , 0.38227157 , 1.80489433 , 0.21472396 ,
1324- - 1.41920399 , - 2.08158544 , - 0.10559009 , 1.68999268 , 0.34847107 ,
1325- - 0.4685737 , 1.23980423 , - 0.14638744 , - 0.35907697 , 0.22442616 ])
1326-
1327- c2 = c0 + 2 * c1
1328- c3 = - 3 * c0 + 4 * c1
1329- a = np .array ([c3 , c0 , c1 , c2 ]).T
1330- return a
1331-
1332-
13331197@cbook .deprecated ('2.2' , 'numpy.percentile' )
13341198def prctile (x , p = (0.0 , 25.0 , 50.0 , 75.0 , 100.0 )):
13351199 """
0 commit comments