def test_toy_model(): """test DTRAM with toy model""" C_K_ij = np.array( [[[2358, 29, 0], [29, 0, 32], [0, 32, 197518]], [[16818, 16763, 0], [16763, 0, 16510], [0, 16510, 16635]]], dtype=np.intc) b_K_i = np.array([[0.0, 0.0, 0.0], [4.0, 0.0, 8.0]], dtype=np.float64) dtram = DTRAM(C_K_ij, b_K_i) assert_raises(NotConvergedWarning, dtram.sc_iteration, maxiter=1, ftol=1.0E-80, verbose=False) dtram.sc_iteration(maxiter=200000, ftol=1.0E-15, verbose=True) pi = np.array([1.82026887e-02, 3.30458960e-04, 9.81466852e-01], dtype=np.float64) T = np.array([[9.90504397e-01, 9.49560284e-03, 0.0], [5.23046803e-01, 0.0, 4.76953197e-01], [0.0, 1.60589690e-04, 9.99839410e-01]], dtype=np.float64) print(pi) print(dtram.pi_i) assert_true(np.max(np.abs(dtram.pi_i - pi)) < 1.0E-8) assert_true( np.max(np.abs(dtram.estimate_transition_matrix(0) - T)) < 1.0E-8)
def test_toy_model(): """test DTRAM with toy model""" C_K_ij = np.array([ [[2358, 29, 0], [29, 0, 32], [0, 32, 197518]], [[16818, 16763, 0], [16763, 0, 16510], [0, 16510, 16635]]], dtype=np.intc) b_K_i = np.array([[0.0, 0.0, 0.0], [4.0, 0.0, 8.0]], dtype=np.float64) dtram = DTRAM(C_K_ij, b_K_i) assert_raises(NotConvergedWarning, dtram.sc_iteration, maxiter=1, ftol=1.0E-80, verbose=False) dtram.sc_iteration(maxiter=200000, ftol=1.0E-15, verbose=True) pi = np.array([1.82026887e-02, 3.30458960e-04, 9.81466852e-01], dtype=np.float64) T = np.array([ [9.90504397e-01, 9.49560284e-03, 0.0], [5.23046803e-01, 0.0, 4.76953197e-01], [0.0, 1.60589690e-04, 9.99839410e-01]], dtype=np.float64) print pi print dtram.pi_i assert_true(np.max(np.abs(dtram.pi_i - pi)) < 1.0E-8) assert_true(np.max(np.abs(dtram.estimate_transition_matrix(0) - T)) < 1.0E-8)
exit( 1 ) print "#\n### SYSTEM INFORMATION\n#" print "# %25s %24d" % ( "[markov states]", tramdata.n_markov_states ) print "# %25s %24d" % ( "[thermodynamic states]", tramdata.n_therm_states ) ############################################################################ # # run the self-consistent-iteration # ############################################################################ print "#\n#################################### RUN DTRAM #####################################\n#" try: print "# Run self-consistent-iteration" dtram_obj.sc_iteration( maxiter=args.maxiter, ftol=args.ftol, verbose=args.verbose ) print "# ... converged!" except NotConvergedWarning, e: print "#\n### WARNING\n#\n# dTRAM is not converged - use these results carefuly!" print "#\n### RECOMMENDATION\n#\n# Run dtram.py again and increase --maxiter" ############################################################################ # # print out the results # ############################################################################ print "#\n##################################### RESULTS ######################################" print "#\n### UNBIASED STATIONARY VECTOR\n#" print "# %25s %25s" % ( "[markov state]", "[stationary probability]" )
print "#\n### ABORTING\n\n" exit(1) print "#\n### SYSTEM INFORMATION\n#" print "# %25s %24d" % ("[markov states]", tramdata.n_markov_states) print "# %25s %24d" % ("[thermodynamic states]", tramdata.n_therm_states) ############################################################################ # # run the self-consistent-iteration # ############################################################################ print "#\n#################################### RUN DTRAM #####################################\n#" try: print "# Run self-consistent-iteration" dtram_obj.sc_iteration(maxiter=args.maxiter, ftol=args.ftol, verbose=args.verbose) print "# ... converged!" except NotConvergedWarning, e: print "#\n### WARNING\n#\n# dTRAM is not converged - use these results carefuly!" print "#\n### RECOMMENDATION\n#\n# Run dtram.py again and increase --maxiter" ############################################################################ # # print out the results # ############################################################################ print "#\n##################################### RESULTS ######################################" print "#\n### UNBIASED STATIONARY VECTOR\n#" print "# %25s %25s" % ("[markov state]", "[stationary probability]") for i in xrange(dtram_obj.pi_i.shape[0]):