Esempio n. 1
0
 def test_XXYY_meanfree(self):
     # many passes
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       compute_YY=True,
                                       remove_mean=True)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L], self.Y[i:i + self.L])
     np.testing.assert_allclose(cc.weight_XY(), self.T)
     np.testing.assert_allclose(cc.sum_X(), self.sx)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx0)
     np.testing.assert_allclose(cc.moments_XY(), self.Mxy0)
     np.testing.assert_allclose(cc.moments_YY(), self.Myy0)
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       compute_YY=True,
                                       remove_mean=True)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L],
                self.Y[i:i + self.L],
                column_selection=self.cols_2)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx0[:, self.cols_2])
     np.testing.assert_allclose(cc.moments_XY(), self.Mxy0[:, self.cols_2])
     np.testing.assert_allclose(cc.moments_YY(), self.Myy0[:, self.cols_2])
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       compute_YY=True,
                                       remove_mean=True,
                                       diag_only=True)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L], self.Y[i:i + self.L])
     np.testing.assert_allclose(cc.moments_XX(), np.diag(self.Mxx0))
     np.testing.assert_allclose(cc.moments_XY(), np.diag(self.Mxy0))
     np.testing.assert_allclose(cc.moments_YY(), np.diag(self.Myy0))
Esempio n. 2
0
 def test_XXXY_sym_withmean(self):
     # many passes
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=False,
                                       symmetrize=True)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L], self.Y[i:i + self.L])
     np.testing.assert_allclose(cc.weight_XY(), 2 * self.T)
     np.testing.assert_allclose(cc.sum_X(), self.s_sym)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx_sym)
     np.testing.assert_allclose(cc.moments_XY(), self.Mxy_sym)
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=False,
                                       symmetrize=True)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L],
                self.Y[i:i + self.L],
                column_selection=self.cols_2)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx_sym[:,
                                                              self.cols_2])
     np.testing.assert_allclose(cc.moments_XY(), self.Mxy_sym[:,
                                                              self.cols_2])
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=False,
                                       symmetrize=True,
                                       diag_only=True)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L], self.Y[i:i + self.L])
     np.testing.assert_allclose(cc.moments_XX(), np.diag(self.Mxx_sym))
     np.testing.assert_allclose(cc.moments_XY(), np.diag(self.Mxy_sym))
Esempio n. 3
0
 def test_XXXY_weighted_withmean(self):
     # many passes
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=False)
     for i in range(0, self.T, self.L):
         iX = self.X[i:i + self.L, :]
         iY = self.Y[i:i + self.L, :]
         iwe = self.weights[i:i + self.L]
         cc.add(iX, iY, weights=iwe)
     np.testing.assert_allclose(cc.weight_XY(), self.wesum)
     np.testing.assert_allclose(cc.sum_X(), self.sx_w)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx_w)
     np.testing.assert_allclose(cc.moments_XY(), self.Mxy_w)
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=False)
     for i in range(0, self.T, self.L):
         iX = self.X[i:i + self.L, :]
         iY = self.Y[i:i + self.L, :]
         iwe = self.weights[i:i + self.L]
         cc.add(iX, iY, weights=iwe, column_selection=self.cols_2)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx_w[:, self.cols_2])
     np.testing.assert_allclose(cc.moments_XY(), self.Mxy_w[:, self.cols_2])
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=False,
                                       diag_only=True)
     for i in range(0, self.T, self.L):
         iX = self.X[i:i + self.L, :]
         iY = self.Y[i:i + self.L, :]
         iwe = self.weights[i:i + self.L]
         cc.add(iX, iY, weights=iwe)
     np.testing.assert_allclose(cc.moments_XX(), np.diag(self.Mxx_w))
     np.testing.assert_allclose(cc.moments_XY(), np.diag(self.Mxy_w))
Esempio n. 4
0
 def test_XX_withmean(self):
     # many passes
     cc = running_moments.RunningCovar(remove_mean=False)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L])
     np.testing.assert_allclose(cc.weight_XX(), self.T)
     np.testing.assert_allclose(cc.sum_X(), self.sx)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx)
     cc = running_moments.RunningCovar(remove_mean=False)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L], column_selection=self.cols_2)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx[:, self.cols_2])
     cc = running_moments.RunningCovar(remove_mean=False, diag_only=True)
     for i in range(0, self.T, self.L):
         cc.add(self.X[i:i + self.L])
     np.testing.assert_allclose(cc.moments_XX(), np.diag(self.Mxx))
Esempio n. 5
0
 def test_XXXY_weighted_sym_meanfree(self):
     # many passes
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=True,
                                       symmetrize=True)
     for i in range(0, self.T, self.L):
         iwe = self.weights[i:i + self.L]
         cc.add(self.X[i:i + self.L], self.Y[i:i + self.L], weights=iwe)
     np.testing.assert_allclose(cc.weight_XY(), 2 * self.wesum)
     np.testing.assert_allclose(cc.sum_X(), self.s_sym_w)
     np.testing.assert_allclose(cc.moments_XX(), self.Mxx0_sym_w)
     np.testing.assert_allclose(cc.moments_XY(), self.Mxy0_sym_w)
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=True,
                                       symmetrize=True)
     for i in range(0, self.T, self.L):
         iwe = self.weights[i:i + self.L]
         cc.add(self.X[i:i + self.L],
                self.Y[i:i + self.L],
                weights=iwe,
                column_selection=self.cols_2)
     np.testing.assert_allclose(cc.moments_XX(),
                                self.Mxx0_sym_w[:, self.cols_2])
     np.testing.assert_allclose(cc.moments_XY(),
                                self.Mxy0_sym_w[:, self.cols_2])
     cc = running_moments.RunningCovar(compute_XX=True,
                                       compute_XY=True,
                                       remove_mean=True,
                                       symmetrize=True,
                                       diag_only=True)
     for i in range(0, self.T, self.L):
         iwe = self.weights[i:i + self.L]
         cc.add(self.X[i:i + self.L], self.Y[i:i + self.L], weights=iwe)
     np.testing.assert_allclose(cc.moments_XX(), np.diag(self.Mxx0_sym_w))
     np.testing.assert_allclose(cc.moments_XY(), np.diag(self.Mxy0_sym_w))