def test_pca_ev(self): A = Analyzer(setup_data1(nt=70, nx=150)) ev = A.pca_ev() self.assertTrue(npy.allclose(ev, npy.array( [ 24.98560392, 18.04025736, 3.59796042, 1.44110266, 0.88847967, 0.45467402, 0.24646941, 0.22392288, 0.16899249, 0.14435935] )))
def test_pca(self): # spanlib A = Analyzer(setup_data1(nt=70, nx=50)) sp_eof = A.pca_eof(raw=True) sp_pc = A.pca_pc(raw=True) sp_ev = A.pca_ev(raw=True) # numpy np_eof, np_pc, np_ev = pca_numpy(A.stacked_data.T, A.npca) # checks self.assertTrue(npy.allclose(sp_ev, np_ev)) signs = npy.sign(sp_eof[0])*npy.sign(np_eof[0]) np_eof *= npy.resize(signs, np_eof.shape) np_pc *= npy.resize(signs, np_pc.shape) self.assertTrue(npy.allclose(sp_eof, np_eof)) self.assertTrue(npy.allclose(sp_pc, np_pc)) self.assertTrue(npy.allclose(sp_ev, np_ev))