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)
def test_weights_close_to_zero(self): n = 1000 data = [np.random.random(size=(n, 2)) for _ in range(5)] # create some artificial correlations data[0][:, 0] *= np.random.randint(n) data = np.asarray(data) weights = [np.ones(n, dtype=np.float32) for _ in range(5)] # omit the first trajectory by setting a weight close to zero. weights[0][:] = 1E-44 weights = np.asarray(weights) est = Covariance(lagtime=1, compute_c0t=True) for data_traj, weights_traj in zip(data, weights): est.partial_fit((data_traj[:-3], data_traj[3:]), weights=weights_traj[:-3]) cov = est.fetch_model() # cov = covariance_lagged(data, lag=3, weights=weights, chunksize=10) assert np.all(cov.cov_00 < 1)