Exemple #1
0
 def test_pca_xrec(self):
     var = setup_data1()
     A = Analyzer(var)
     rec = A.pca_rec()
     xeof = A.pca_eof()
     xpc = A.pca_pc()
     xrec = A.pca_rec(xeof=xeof, xpc=xpc)
     self.assertTrue(npy.allclose(rec, xrec))
Exemple #2
0
 def test_pca_ec(self):
     data = setup_data1(nt=70, nx=150)
     A = Analyzer(data)
     A.pca_eof()
     ec = A.pca_ec()
     pc = A.pca_pc()
     self.assertTrue(npy.allclose(ec, pc))
     ece = A.pca_ec(xeof=A.pca_eof(raw=True), xraw=True)
     self.assertTrue(npy.allclose(ece, pc))
     ecd = A.pca_ec(xdata=data)
     self.assertTrue(npy.allclose(ecd, pc))
     ecrd = A.pca_ec(xdata=A.stacked_data, xraw=True)
     self.assertTrue(npy.allclose(ecrd, pc))
     ecre = A.pca_ec(xeof=A.pca_eof(raw=True), xraw=True)
     self.assertTrue(npy.allclose(ecrd, pc))
Exemple #3
0
    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))
Exemple #4
0
 def test_pca_pc(self):
     A = Analyzer(setup_data1(nt=70, nx=150))
     pc = A.pca_pc()
     self.assertTrue(npy.allclose(pc[:2,:2],  npy.array(
         [[ 2.75532971,   2.96740389],
         [-8.78119373,  -8.49616261]])))