def test_harder_hubscore(): # depends on tpt.committors and tpt.conditional_committors assignments = np.random.randint(10, size=(10, 1000)) msm = MarkovStateModel(lag_time=1) msm.fit(assignments) hub_scores = tpt.hub_scores(msm) ref_hub_scores = np.zeros(10) for A in range(10): for B in range(10): committors = tpt.committors(A, B, msm) denom = msm.transmat_[A, :].dot(committors) for C in range(10): if A == B or A == C or B == C: continue cond_committors = tpt.conditional_committors(A, B, C, msm) temp = 0.0 for i in range(10): if i in [A, B]: continue temp += cond_committors[i] * msm.transmat_[A, i] temp /= denom ref_hub_scores[C] += temp ref_hub_scores /= (9 * 8) npt.assert_array_almost_equal(ref_hub_scores, hub_scores)
def test_cond_committors(): # depends on tpt.committors msm = MarkovStateModel(lag_time=1) assignments = np.random.randint(4, size=(10, 1000)) msm.fit(assignments) tprob = msm.transmat_ for_committors = tpt.committors(0, 3, msm) cond_committors = tpt.conditional_committors(0, 3, 2, msm) # The committor for state one can be decomposed into paths that # do and do not visit state 2 along the way. The paths that do not # visit state 1 must look like 1, 1, 1, ..., 1, 1, 3. So we can # compute them with a similar approximation as the forward committor # Since we want the other component of the forward committor, we # subtract that probability from the forward committor ref = for_committors[1] - np.power(tprob[1, 1], np.arange(5000)).sum() * tprob[1, 3] #print (ref / for_committors[1]) ref = [0, ref, for_committors[2], 0] #print(cond_committors, ref) npt.assert_array_almost_equal(ref, cond_committors)
def test_harder_hubscore(): # depends on tpt.committors and tpt.conditional_committors assignments = np.random.randint(10, size=(10, 1000)) msm = MarkovStateModel(lag_time=1) msm.fit(assignments) hub_scores = tpt.hub_scores(msm) ref_hub_scores = np.zeros(10) for A in xrange(10): for B in xrange(10): committors = tpt.committors(A, B, msm) denom = msm.transmat_[A, :].dot(committors) #+ msm.transmat_[A, B] for C in xrange(10): if A == B or A == C or B == C: continue cond_committors = tpt.conditional_committors(A, B, C, msm) temp = 0.0 for i in xrange(10): if i in [A, B]: continue temp += cond_committors[i] * msm.transmat_[A, i] temp /= denom ref_hub_scores[C] += temp ref_hub_scores /= (9 * 8) #print(ref_hub_scores, hub_scores) npt.assert_array_almost_equal(ref_hub_scores, hub_scores)
def test_cond_committors_2(): # depends on tpt.committors bmsm = BayesianMarkovStateModel(lag_time=1) assignments = np.random.randint(4, size=(10, 1000)) bmsm.fit(assignments) for_committors = tpt.committors(0, 3, bmsm) cond_committors = tpt.conditional_committors(0, 3, 2, bmsm) ref = 0 for tprob in bmsm.all_transmats_: ref += (for_committors[1] - np.power(tprob[1, 1], np.arange(5000)).sum() * tprob[1, 3]) ref = [0, ref / 100., for_committors[2], 0] npt.assert_array_almost_equal(ref, cond_committors, decimal=2)