Beispiel #1
0
 def test_XX_weighted_meanconst(self):
     est = Covariance(lagtime=self.lag, compute_c0t=False, bessels_correction=False)
     cc = est.fit(self.data - self.mean_const, weights=self.data_weights).fetch_model()
     np.testing.assert_allclose(cc.mean_0, self.mx_c_wobj_lag0)
     np.testing.assert_allclose(cc.cov_00, self.Mxx_c_wobj_lag0)
     cc = est.fit(self.data - self.mean_const, weights=self.data_weights, column_selection=self.cols_2).fetch_model()
     np.testing.assert_allclose(cc.cov_00, self.Mxx_c_wobj_lag0[:, self.cols_2])
Beispiel #2
0
def test_weights_incompatible():
    data = np.random.normal(size=(5000, 3))
    est = Covariance(5)
    with np.testing.assert_raises(ValueError):
        est.fit(data, weights=np.arange(10))  # incompatible shape

    with np.testing.assert_raises(ValueError):
        est.fit(data, weights=np.ones((len(data), 2)))  # incompatible shape
Beispiel #3
0
 def test_XX_weightobj_meanfree(self):
     # many passes
     est = Covariance(lagtime=self.lag, compute_c0t=False, remove_data_mean=True, bessels_correction=False)
     cc = est.fit(self.data, weights=self.data_weights, n_splits=10).fetch_model()
     np.testing.assert_allclose(cc.mean_0, self.mx_wobj_lag0)
     np.testing.assert_allclose(cc.cov_00, self.Mxx0_wobj_lag0)
     cc = est.fit(self.data, column_selection=self.cols_2, weights=self.data_weights).fetch_model()
     np.testing.assert_allclose(cc.cov_00, self.Mxx0_wobj_lag0[:, self.cols_2])
Beispiel #4
0
 def test_XX_with_mean(self):
     # many passes
     est = Covariance(lagtime=self.lag, compute_c0t=False, remove_data_mean=False, bessels_correction=False)
     cc = est.fit(self.data).fetch_model()
     np.testing.assert_allclose(cc.mean_0, self.mx_lag0)
     np.testing.assert_allclose(cc.cov_00, self.Mxx_lag0)
     cc = est.fit(self.data, column_selection=self.cols_2).fetch_model()
     np.testing.assert_allclose(cc.cov_00, self.Mxx_lag0[:, self.cols_2])
Beispiel #5
0
 def test_XY_sym_meanconst(self):
     est = Covariance(lagtime=self.lag, compute_c0t=True, reversible=True, bessels_correction=False)
     cc = est.fit(self.Xc_lag0).fetch_model()
     np.testing.assert_allclose(cc.mean_0, self.m_c_sym)
     np.testing.assert_allclose(cc.cov_00, self.Mxx_c_sym)
     np.testing.assert_allclose(cc.cov_0t, self.Mxy_c_sym)
     cc = est.fit(self.Xc_lag0, column_selection=self.cols_2).fetch_model()
     np.testing.assert_allclose(cc.cov_00, self.Mxx_c_sym[:, self.cols_2])
     np.testing.assert_allclose(cc.cov_0t, self.Mxy_c_sym[:, self.cols_2])
Beispiel #6
0
def test_weights():
    weights = np.concatenate([np.ones((1001,)) * 1e-16, np.ones((3999,))])
    np.testing.assert_equal(len(weights), 5000)
    data = np.random.normal(size=(5000, 2))
    cov = Covariance(lagtime=5, compute_c00=True, compute_c0t=True, compute_ctt=False)
    model = cov.fit(data, weights=weights, n_splits=64).fetch_model()
    model2 = cov.fit(data[1002:], weights=weights[1002:], n_splits=55).fetch_model()
    np.testing.assert_array_almost_equal(model.cov_00, model2.cov_00, decimal=2)
    np.testing.assert_array_almost_equal(model.cov_0t, model2.cov_0t, decimal=2)
    np.testing.assert_array_almost_equal(model.mean_0, model2.mean_0, decimal=2)
    np.testing.assert_array_almost_equal(model.mean_t, model2.mean_t, decimal=2)
Beispiel #7
0
 def test_XXXY_weightobj_sym_meanfree(self):
     # many passes
     est = Covariance(lagtime=self.lag, remove_data_mean=True, compute_c0t=True, reversible=True,
                      bessels_correction=False)
     cc = est.fit(self.data, weights=self.data_weights).fetch_model()
     np.testing.assert_allclose(cc.mean_0, self.m_sym_wobj)
     np.testing.assert_allclose(cc.cov_00, self.Mxx0_sym_wobj)
     np.testing.assert_allclose(cc.cov_0t, self.Mxy0_sym_wobj)
     cc = est.fit(self.data, weights=self.data_weights, column_selection=self.cols_2).fetch_model()
     np.testing.assert_allclose(cc.cov_00, self.Mxx0_sym_wobj[:, self.cols_2])
     np.testing.assert_allclose(cc.cov_0t, self.Mxy0_sym_wobj[:, self.cols_2])
Beispiel #8
0
 def test_XXXY_sym_withmean(self):
     # many passes
     est = Covariance(lagtime=self.lag, remove_data_mean=False, compute_c0t=True, reversible=True,
                      bessels_correction=False)
     cc = est.fit(self.data).fetch_model()
     np.testing.assert_allclose(cc.mean_0, self.m_sym)
     np.testing.assert_allclose(cc.cov_00, self.Mxx_sym)
     np.testing.assert_allclose(cc.cov_0t, self.Mxy_sym)
     cc = est.fit(self.data, column_selection=self.cols_2).fetch_model()
     np.testing.assert_allclose(cc.cov_00, self.Mxx_sym[:, self.cols_2])
     np.testing.assert_allclose(cc.cov_0t, self.Mxy_sym[:, self.cols_2])
Beispiel #9
0
 def test_XXXY_meanfree(self):
     # many passes
     est = Covariance(lagtime=self.lag, remove_data_mean=True, compute_c0t=True, bessels_correction=False)
     cc = est.fit(self.data).fetch_model()
     np.testing.assert_allclose(cc.mean_0, self.mx)
     np.testing.assert_allclose(cc.mean_t, self.my)
     np.testing.assert_allclose(cc.cov_00, self.Mxx0)
     np.testing.assert_allclose(cc.cov_0t, self.Mxy0)
     cc = est.fit(self.data, column_selection=self.cols_2).fetch_model()
     np.testing.assert_allclose(cc.cov_00, self.Mxx0[:, self.cols_2])
     np.testing.assert_allclose(cc.cov_0t, self.Mxy0[:, self.cols_2])
Beispiel #10
0
 def test_XXXY_weightobj_meanfree(self):
     for n_splits in [1, 2, 3, 4, 5, 6, 7]:
         est = Covariance(lagtime=self.lag, remove_data_mean=True, compute_c0t=True, bessels_correction=False)
         cc = est.fit(self.data, weights=self.data_weights, n_splits=n_splits).fetch_model()
         np.testing.assert_allclose(cc.mean_0, self.mx_wobj)
         np.testing.assert_allclose(cc.mean_t, self.my_wobj)
         np.testing.assert_allclose(cc.cov_00, self.Mxx0_wobj)
         np.testing.assert_allclose(cc.cov_0t, self.Mxy0_wobj)
         cc = est.fit(self.data, weights=self.data_weights, column_selection=self.cols_2,
                      n_splits=n_splits).fetch_model()
         np.testing.assert_allclose(cc.cov_00, self.Mxx0_wobj[:, self.cols_2])
         np.testing.assert_allclose(cc.cov_0t, self.Mxy0_wobj[:, self.cols_2])
Beispiel #11
0
 def test_XXXY_withmean(self):
     # many passes
     est = Covariance(lagtime=self.lag, remove_data_mean=False, compute_c0t=True, bessels_correction=False)
     cc = est.fit(self.data, n_splits=1).fetch_model()
     assert not cc.bessels_correction
     np.testing.assert_allclose(cc.mean_0, self.mx)
     np.testing.assert_allclose(cc.mean_t, self.my)
     np.testing.assert_allclose(cc.cov_00, self.Mxx)
     np.testing.assert_allclose(cc.cov_0t, self.Mxy)
     cc = est.fit(self.data, n_splits=1, column_selection=self.cols_2).fetch_model()
     np.testing.assert_allclose(cc.cov_00, self.Mxx[:, self.cols_2])
     np.testing.assert_allclose(cc.cov_0t, self.Mxy[:, self.cols_2])
Beispiel #12
0
def test_multiple_fetch():
    # checks that the model instance does not change when the estimator was not updated
    data = np.random.normal(size=(5000, 3))
    est = Covariance(5, compute_c00=True, compute_c0t=False, compute_ctt=False)
    m1 = est.fit(data).model
    m2 = est.model
    m3 = est.partial_fit(np.random.normal(size=(50, 3))).model
    np.testing.assert_(m1 is m2)
    np.testing.assert_(m1 is not m3)
    np.testing.assert_(m2 is not m3)
Beispiel #13
0
 def test_re_estimate_weight_types(self):
     # check different types are allowed and re-estimation works
     x = np.random.random((100, 2))
     c = Covariance(lagtime=1, compute_c0t=True)
     c.fit(x, weights=np.ones((len(x),))).fetch_model()
     c.fit(x, weights=np.ones((len(x),))).fetch_model()
     c.fit(x, weights=None).fetch_model()
     c.fit(x, weights=x[:, 0]).fetch_model()