Example #1
0
 def test_transition_matrix(self):
     """Test example transition matrices.
     """
     Tij = testsystems.generate_transition_matrix(nstates=3, reversible=False)
     Tij = testsystems.generate_transition_matrix(nstates=3, reversible=True)
     # TODO: Check Tij is proper row-stochastic matrix?
     return
Example #2
0
 def test_two_state_model(self):
     """Test the creation of a simple two-state HMM model with analytical parameters.
     """
     from bhmm import HMM
     # Create a simple two-state model.
     nstates = 2
     Tij = testsystems.generate_transition_matrix(reversible=True)
     # stationary distribution
     import msmtools.analysis as msmana
     Pi = msmana.stationary_distribution(Tij)
     from bhmm import GaussianOutputModel
     means = [-1, +1]
     sigmas = [1, 1]
     output_model = GaussianOutputModel(nstates, means=means, sigmas=sigmas)
     model = bhmm.HMM(Pi, Tij, output_model)
     # Test model is correct.
     assert_array_almost_equal(model.transition_matrix, Tij)
     assert_array_almost_equal(model.stationary_distribution, Pi)
     assert(np.allclose(model.output_model.means, np.array(means)))
     assert(np.allclose(model.output_model.sigmas, np.array(sigmas)))
Example #3
0
 def test_two_state_model(self):
     """Test the creation of a simple two-state HMM model with analytical parameters.
     """
     from bhmm import HMM
     # Create a simple two-state model.
     nstates = 2
     Tij = testsystems.generate_transition_matrix(reversible=True)
     from bhmm import GaussianOutputModel
     means=[-1,+1]
     sigmas=[1,1]
     output_model = GaussianOutputModel(nstates, means=means, sigmas=sigmas)
     model = bhmm.HMM(Tij, output_model)
     # Compute stationary probability using ARPACK.
     from scipy.sparse.linalg import eigs
     from numpy.linalg import norm
     [eigenvalues, eigenvectors] = eigs(Tij.T, k=1, which='LR')
     eigenvectors = np.real(eigenvectors)
     Pi = eigenvectors[:,0] / eigenvectors[:,0].sum()
     # Test model is correct.
     assert_array_almost_equal(model._Tij, Tij)
     assert_array_almost_equal(model._Pi, Pi)
     assert(np.allclose(model.output_model.means, np.array(means)))
     assert(np.allclose(model.output_model.sigmas, np.array(sigmas)))