def test_eigenvectors_left_stats(bhmm_fixture):
    samples = np.array(
        [m.transition_model.eigenvectors_left() for m in bhmm_fixture.bhmm])
    # mean
    mean = samples.mean(axis=0)
    # test shape and consistency
    assert np.array_equal(mean.shape,
                          (bhmm_fixture.n_states, bhmm_fixture.n_states))
    assert np.sign(mean[0, 0]) == np.sign(mean[0, 1])
    assert np.sign(mean[1, 0]) != np.sign(mean[1, 1])
    # std
    std = samples.std(axis=0)
    # test shape
    assert np.array_equal(std.shape,
                          (bhmm_fixture.n_states, bhmm_fixture.n_states))
    # conf
    L, R = confidence_interval(samples)
    # test shape
    assert np.array_equal(L.shape,
                          (bhmm_fixture.n_states, bhmm_fixture.n_states))
    assert np.array_equal(R.shape,
                          (bhmm_fixture.n_states, bhmm_fixture.n_states))
    # test consistency
    tol = 1e-12
    assert np.all(L - tol <= mean)
    assert np.all(R + tol >= mean)
 def _eigenvectors_right_stats(self, msm, tol=1e-12):
     samples = np.array([s.eigenvectors_right() for s in msm.samples])
     # mean
     mean = samples.mean(axis=0)
     # test shape and consistency
     np.testing.assert_equal(mean.shape, (self.n_states, self.n_states))
     assert np.sign(mean[0, 0]) == np.sign(mean[1, 0])
     assert np.sign(mean[0, 1]) != np.sign(mean[1, 1])
     # std
     std = samples.std(axis=0)
     # test shape
     assert np.array_equal(std.shape, (self.n_states, self.n_states))
     # conf
     L, R = confidence_interval(samples)
     # test shape
     assert np.array_equal(L.shape, (self.n_states, self.n_states))
     assert np.array_equal(R.shape, (self.n_states, self.n_states))
     # test consistency
     assert np.all(L - tol <= mean)
     assert np.all(R + tol >= mean)
 def _eigenvalues_stats(self, msm, tol=1e-12):
     # mean
     samples = np.array([s.eigenvalues() for s in msm.samples])
     mean = samples.mean(axis=0)
     # test shape and consistency
     assert np.array_equal(mean.shape, (self.n_states,))
     assert np.isclose(mean[0], 1)
     assert np.all(mean[1:] < 1.0)
     # std
     std = samples.std(axis=0)
     # test shape
     assert np.array_equal(std.shape, (self.n_states,))
     # conf
     L, R = confidence_interval(samples)
     # test shape
     assert np.array_equal(L.shape, (self.n_states,))
     assert np.array_equal(R.shape, (self.n_states,))
     # test consistency
     assert np.all(L - tol <= mean)
     assert np.all(R + tol >= mean)
 def _transition_matrix_stats(self, msm):
     import deeptime.markov.tools.analysis as msmana
     # mean
     Ps = np.array([s.transition_matrix for s in msm.samples])
     Pmean = Ps.mean(axis=0)
     # test shape and consistency
     assert np.array_equal(Pmean.shape, (self.n_states, self.n_states))
     assert msmana.is_transition_matrix(Pmean)
     # std
     Pstd = Ps.std(axis=0)
     # test shape
     assert np.array_equal(Pstd.shape, (self.n_states, self.n_states))
     # conf
     L, R = confidence_interval(Ps)
     # test shape
     assert np.array_equal(L.shape, (self.n_states, self.n_states))
     assert np.array_equal(R.shape, (self.n_states, self.n_states))
     # test consistency
     assert np.all(L <= Pmean)
     assert np.all(R >= Pmean)
 def _stationary_distribution_stats(self, msm, tol=1e-12):
     samples = np.array([s.stationary_distribution for s in msm.samples])
     # mean
     mean = samples.mean(axis=0)
     # test shape and consistency
     assert np.array_equal(mean.shape, (self.n_states,))
     assert np.isclose(mean.sum(), 1.0)
     assert np.all(mean > 0.0)
     assert np.max(np.abs(mean[0] - mean[1])) < 0.05
     # std
     std = samples.std(axis=0)
     # test shape
     assert np.array_equal(std.shape, (self.n_states,))
     # conf
     L, R = confidence_interval(samples)
     # test shape
     assert np.array_equal(L.shape, (self.n_states,))
     assert np.array_equal(R.shape, (self.n_states,))
     # test consistency
     assert np.all(L - tol <= mean)
     assert np.all(R + tol >= mean)
Beispiel #6
0
 def test_stationary_distribution_stats(self):
     samples = np.array([m.transition_model.stationary_distribution for m in self.bhmm])
     tol = 1e-12
     # mean
     mean = samples.mean(axis=0)
     # test shape and consistency
     assert np.array_equal(mean.shape, (self.n_states,))
     assert np.isclose(mean.sum(), 1.0)
     assert np.all(mean > 0.0)
     assert np.max(np.abs(mean[0] - mean[1])) < 0.05
     # std
     std = samples.std(axis=0)
     # test shape
     assert np.array_equal(std.shape, (self.n_states,))
     # conf
     L, R = confidence_interval(samples)
     # test shape
     assert np.array_equal(L.shape, (self.n_states,))
     assert np.array_equal(R.shape, (self.n_states,))
     # test consistency
     assert np.all(L - tol <= mean)
     assert np.all(R + tol >= mean)
Beispiel #7
0
def test_confidence_interval(conf):
    g = np.random.default_rng(seed=42)
    data = g.normal(size=(300000, ))
    l, r = confidence_interval(data, conf=conf)
    data_inside = data[(data >= l) & (data <= r)]
    np.testing.assert_almost_equal(data_inside.size / data.size, conf)