def compare(self, A, B, nnodes=10, nedges=20, weights=None, x=1): print("") maker = _MakeRandomGraph(nnodes=nnodes, nedges=nedges, node_set=A + B + [x]) graph = maker.run() graph_backup = graph.copy() reducer = GraphReduction(maker.rates, A, B, weights=weights) kmc = KineticMonteCarlo(graph_backup, debug=False) # test compute_committor_probability() PxB = reducer.compute_committor_probability(x) PxB_kmc = kmc.committor_probability(x, A, B, niter=1000) print("committor probability ", x, "->", B, "=", PxB) print("committor probability kmc", x, "->", B, "=", PxB_kmc) self.assertAlmostEqual(PxB, PxB_kmc, delta=.1) reducer.compute_rates() rAB = reducer.get_rate_AB() rBA = reducer.get_rate_BA() rAB_SS = reducer.get_rate_AB_SS() # compute rate via linalg lin = TwoStateRates(maker.rates, A, B, weights=weights) lin.compute_rates() rAB_LA = lin.get_rate_AB() lin.compute_committors() rAB_SS_LA = lin.get_rate_AB_SS() self.assertAlmostEqual(rAB_SS, rAB_SS_LA, 5) PxB_LA = lin.get_committor(x) if x not in A and x not in B: self.assertAlmostEqual(PxB, PxB_LA, 5) rAB_KMC = kmc.mean_rate(A, B, niter=1000, weights=weights) print("NGT rate A->B", rAB) print("KMC rate A->B", rAB_KMC) print("normalized difference", old_div((rAB - rAB_KMC), rAB)) print("normalized difference to linalg", old_div((rAB - rAB_LA), rAB)) self.assertLess(old_div(abs(rAB - rAB_KMC), rAB), .1) self.assertLess(old_div(abs(rAB - rAB_LA), rAB), .00001) rBA_KMC = kmc.mean_rate(B, A, niter=1000, weights=weights) print("NGT rate B->A", rBA) print("KMC rate B->A", rBA_KMC) print("normalized difference", old_div((rBA - rBA_KMC), rBA)) self.assertLess(old_div(abs(rBA - rBA_KMC), rBA), .1) paB = kmc.committor_probability(A[0], [A[0]], B, niter=1000) print("the committor probability a->B", paB) print("graph reduction committor prob", reducer.get_committor_probabilityAB(A[0])) self.assertAlmostEqual(paB, reducer.get_committor_probabilityAB(A[0]), delta=.1)
def _test_rate(self, i, j): reducer = GraphReduction(self.rates, [i], [j], debug=True) reducer.check_graph() reducer.compute_rates() rAB = reducer.get_rate_AB() rBA = reducer.get_rate_BA() reducer.check_graph() self.assertEqual(reducer.graph.number_of_nodes(), 2) self.assertEqual(reducer.graph.number_of_edges(), 4) self.assertAlmostEqual(rAB, self.final_rate, 7) self.assertAlmostEqual(rBA, self.final_rate, 7)
def do_check(self, A, B, nnodes=20, nedges=20): maker = _MakeRandomGraph(nnodes=20, nedges=20, node_set=A + B) graph = maker.run() reducer = GraphReduction(maker.rates, A, B, debug=False) reducer.check_graph() reducer.compute_rates() rAB = reducer.get_rate_AB() rBA = reducer.get_rate_BA() reducer.check_graph() self.assertEqual(reducer.graph.number_of_nodes(), len(A) + len(B)) if len(A) == 1 and len(B) == 1: self.assertLessEqual(reducer.graph.number_of_edges(), 4)
def compare(self, A, B, nnodes=10, nedges=20, weights=None, x=1): print("") maker = _MakeRandomGraph(nnodes=nnodes, nedges=nedges, node_set=A+B+[x]) graph = maker.run() graph_backup = graph.copy() reducer = GraphReduction(maker.rates, A, B, weights=weights) kmc = KineticMonteCarlo(graph_backup, debug=False) # test compute_committor_probability() PxB = reducer.compute_committor_probability(x) PxB_kmc = kmc.committor_probability(x, A, B, niter=1000) print("committor probability ", x, "->", B, "=", PxB) print("committor probability kmc", x, "->", B, "=", PxB_kmc) self.assertAlmostEqual(PxB, PxB_kmc, delta=.1) reducer.compute_rates() rAB = reducer.get_rate_AB() rBA = reducer.get_rate_BA() rAB_SS = reducer.get_rate_AB_SS() # compute rate via linalg lin = TwoStateRates(maker.rates, A, B, weights=weights) lin.compute_rates() rAB_LA = lin.get_rate_AB() lin.compute_committors() rAB_SS_LA = lin.get_rate_AB_SS() self.assertAlmostEqual(rAB_SS, rAB_SS_LA, 5) PxB_LA = lin.get_committor(x) if x not in A and x not in B: self.assertAlmostEqual(PxB, PxB_LA, 5) rAB_KMC = kmc.mean_rate(A, B, niter=1000, weights=weights) print("NGT rate A->B", rAB) print("KMC rate A->B", rAB_KMC) print("normalized difference", (rAB - rAB_KMC)/rAB) print("normalized difference to linalg", (rAB - rAB_LA)/rAB) self.assertLess(abs(rAB - rAB_KMC)/rAB, .1) self.assertLess(abs(rAB - rAB_LA)/rAB, .00001) rBA_KMC = kmc.mean_rate(B, A, niter=1000, weights=weights) print("NGT rate B->A", rBA) print("KMC rate B->A", rBA_KMC) print("normalized difference", (rBA - rBA_KMC)/rBA) self.assertLess(abs(rBA - rBA_KMC)/rBA, .1) paB = kmc.committor_probability(A[0], [A[0]], B, niter=1000) print("the committor probability a->B", paB) print("graph reduction committor prob", reducer.get_committor_probabilityAB(A[0])) self.assertAlmostEqual(paB, reducer.get_committor_probabilityAB(A[0]), delta=.1)
def do_check(self, A, B, nnodes=20, nedges=20): maker = _MakeRandomGraph(nnodes=20, nedges=20, node_set=A+B) graph = maker.run() reducer = GraphReduction(maker.rates, A, B, debug=False) reducer.check_graph() reducer.compute_rates() rAB = reducer.get_rate_AB() rBA = reducer.get_rate_BA() reducer.check_graph() self.assertEqual(reducer.graph.number_of_nodes(), len(A) + len(B)) if len(A) == 1 and len(B) == 1: self.assertLessEqual(reducer.graph.number_of_edges(), 4)
def compare(self, A, B, nnodes=10, nedges=20, weights=None, x=1): print "" maker = _MakeRandomGraph(nnodes=nnodes, nedges=nedges, node_set=A+B+[x]) graph = maker.run() graph_backup = graph.copy() reducer = GraphReduction(maker.rates, A, B, weights=weights) kmc = KineticMonteCarlo(graph_backup, debug=False) # test compute_committor_probability() PxB = reducer.compute_committor_probability(x) PxB_kmc = kmc.committor_probability(x, A, B, niter=1000) print "committor probability ", x, "->", B, "=", PxB print "committor probability kmc", x, "->", B, "=", PxB_kmc self.assertAlmostEqual(PxB, PxB_kmc, delta=.1) reducer.compute_rates() rAB = reducer.get_rate_AB() rBA = reducer.get_rate_BA() rAB_KMC = kmc.mean_rate(A, B, niter=1000, weights=weights) print "NGT rate A->B", rAB print "KMC rate A->B", rAB_KMC print "normalized difference", (rAB - rAB_KMC)/rAB self.assertLess(abs(rAB - rAB_KMC)/rAB, .1) rBA_KMC = kmc.mean_rate(B, A, niter=1000, weights=weights) print "NGT rate B->A", rBA print "KMC rate B->A", rBA_KMC print "normalized difference", (rBA - rBA_KMC)/rBA self.assertLess(abs(rBA - rBA_KMC)/rBA, .1) paB = kmc.committor_probability(A[0], [A[0]], B, niter=1000) print "the committor probability a->B", paB print "graph reduction committor prob", reducer.get_committor_probabilityAB(A[0]) self.assertAlmostEqual(paB, reducer.get_committor_probabilityAB(A[0]), delta=.1)