def test_counts_factor():
    C = np.random.randint(10, size=(5, 5)).astype(float)
    transmat1, pi2 = _transmat_mle_prinz(C)

    transmat2, pi1 = _transmat_mle_prinz(10 * C)
    np.testing.assert_array_almost_equal(transmat1, transmat2)
    np.testing.assert_array_almost_equal(pi1, pi2)
def test_7():
    C = np.random.randint(10, size=(5, 5)).astype(float)
    transmat1, pi2 = _transmat_mle_prinz(C)

    transmat2, pi1 = _transmat_mle_prinz(10 * C)
    np.testing.assert_array_almost_equal(transmat1, transmat2)
    np.testing.assert_array_almost_equal(pi1, pi2)
Exemple #3
0
 def post(self):
     io = StringIO(self.get_argument('matrix'))
     w = sio.mmread(io)
     msm = MarkovStateModel()
     msm.transmat_, msm.populations_ = _transmat_mle_prinz(w)
     msm.n_states_ = msm.populations_.shape[0]
     if bool(int(self.get_argument('mode'))):
         self.write(make_json_paths(msm, self))  # TP
     else:
         self.write(make_json_graph(msm, self))  # MSM
def _test(C):
    n = C.shape[0]

    T1, pi1 = _transmat_mle_prinz(C, tol=1e-10)
    T2 = reference_mle(scipy.sparse.csr_matrix(C))

    # reference pi
    eigvals, eigvecs = np.linalg.eig(T1.T)
    pi = eigvecs[:, np.argmax(eigvals)]
    pi = pi / np.sum(pi)

    np.testing.assert_array_almost_equal(T1, T2)
    np.testing.assert_array_almost_equal(pi1, pi)

    # make sure that T1 is reversible
    for i in range(n):
        for j in range(n):
            np.testing.assert_almost_equal(T1[i, j] * pi[i], T1[j, i] * pi[j])
def _test(C):
    n = C.shape[0]

    T1, pi1 = _transmat_mle_prinz(C, tol=1e-10)
    T2 = reference_mle(scipy.sparse.csr_matrix(C))

    # reference pi
    eigvals, eigvecs = np.linalg.eig(T1.T)
    pi = eigvecs[:, np.argmax(eigvals)]
    pi = pi / np.sum(pi)

    np.testing.assert_array_almost_equal(T1, T2)
    np.testing.assert_array_almost_equal(pi1, pi)

    # make sure that T1 is reversible
    for i in range(n):
        for j in range(n):
            np.testing.assert_almost_equal(T1[i, j] * pi[i], T1[j, i] * pi[j])
def test_tolerance():
    with np.testing.assert_raises(ValueError):
        _transmat_mle_prinz(np.zeros((3, 3)), tol=1e-10)
    with np.testing.assert_raises(ValueError):
        _transmat_mle_prinz(-1 * np.ones((3, 3)), tol=1e-10)
def test_one_state():
    C = np.array([[1]], dtype=float)
    T, pi = _transmat_mle_prinz(C)
    np.testing.assert_array_equal(T, C)
def test_floats():
    C = np.array([[0, 1], [1, 0]], dtype=float)
    transmat, populations = _transmat_mle_prinz(C)
    assert np.all(np.isfinite(transmat))
    assert np.all(np.isfinite(populations))
    np.testing.assert_array_equal(transmat, C)
def test_5():
    C = np.array([[0, 1], [1, 0]], dtype=float)
    transmat, populations = _transmat_mle_prinz(C)
    assert np.all(np.isfinite(transmat))
    assert np.all(np.isfinite(populations))
    np.testing.assert_array_equal(transmat, C)
def test_4():
    with np.testing.assert_raises(ValueError):
        _transmat_mle_prinz(np.zeros((3, 3)), tol=1e-10)
    with np.testing.assert_raises(ValueError):
        _transmat_mle_prinz(-1 * np.ones((3, 3)), tol=1e-10)
def test_6():
    C = np.array([[1]], dtype=float)
    T, pi = _transmat_mle_prinz(C)
    np.testing.assert_array_equal(T, C)
Exemple #12
0
def _guess_ratemat():
    transmat, pi = _transmat_mle_prinz(countsmat1)
    ratemat = transmat - np.eye(transmat.shape[0])
    return ratemat