def setUp(self): """ Setup a KMRMarkovMatrix and Compute Stationary Values """ self.P = KMR_Markov_matrix_sequential(self.N, self.p, self.epsilon) self.mc = DMarkov(self.P) self.stationary = self.mc.mc_compute_stationary() stat_shape = self.stationary.shape if len(stat_shape) is 1: self.n_stat_dists = 1 else: self.n_stat_dists = stat_shape[1]
class Test_mc_compute_stationary_KMRMarkovMatrix2(): """ Test Suite for mc_compute_stationary using KMR Markov Matrix [suitable for nose] """ #-Starting Values-# N = 27 epsilon = 1e-2 p = 1 / 3 TOL = 1e-2 def setUp(self): """ Setup a KMRMarkovMatrix and Compute Stationary Values """ self.P = KMR_Markov_matrix_sequential(self.N, self.p, self.epsilon) self.mc = DMarkov(self.P) self.stationary = self.mc.mc_compute_stationary() stat_shape = self.stationary.shape if len(stat_shape) is 1: self.n_stat_dists = 1 else: self.n_stat_dists = stat_shape[1] def test_markov_matrix(self): "Check that each row of matrix sums to 1" mc = self.mc assert_allclose(np.sum(mc.P, axis=1), np.ones(mc.n)) def test_sum_one(self): "Check each stationary distribution sums to 1" stationary_distributions = self.stationary assert_allclose(np.sum(stationary_distributions, axis=0), np.ones(self.n_stat_dists)) def test_nonnegative(self): "Check that the stationary distributions are non-negative" stationary_distributions = self.stationary assert (np.all(stationary_distributions > -1e-16)) def test_left_eigen_vec(self): "Check that vP = v for all stationary distributions" mc = self.mc stationary = self.stationary if self.n_stat_dists is 1: assert_allclose(np.dot(stationary, mc.P), stationary, atol=self.TOL) else: for i in range(self.n_stat_dists): curr_v = stationary_distributions[:, i] assert_allclose(np.dot(curr_v, mc.P), curr_v, atol=self.TOL)
class Test_mc_compute_stationary_KMRMarkovMatrix2(): """ Test Suite for mc_compute_stationary using KMR Markov Matrix [suitable for nose] """ #-Starting Values-# N = 27 epsilon = 1e-2 p = 1/3 TOL = 1e-2 def setUp(self): """ Setup a KMRMarkovMatrix and Compute Stationary Values """ self.P = KMR_Markov_matrix_sequential(self.N, self.p, self.epsilon) self.mc = DMarkov(self.P) self.stationary = self.mc.mc_compute_stationary() stat_shape = self.stationary.shape if len(stat_shape) is 1: self.n_stat_dists = 1 else: self.n_stat_dists = stat_shape[1] def test_markov_matrix(self): "Check that each row of matrix sums to 1" mc = self.mc assert_allclose(np.sum(mc.P, axis=1), np.ones(mc.n)) def test_sum_one(self): "Check each stationary distribution sums to 1" stationary_distributions = self.stationary assert_allclose(np.sum(stationary_distributions, axis=0), np.ones(self.n_stat_dists)) def test_nonnegative(self): "Check that the stationary distributions are non-negative" stationary_distributions = self.stationary assert(np.all(stationary_distributions > -1e-16)) def test_left_eigen_vec(self): "Check that vP = v for all stationary distributions" mc = self.mc stationary = self.stationary if self.n_stat_dists is 1: assert_allclose(np.dot(stationary, mc.P), stationary, atol=self.TOL) else: for i in range(self.n_stat_dists): curr_v = stationary_distributions[:, i] assert_allclose(np.dot(curr_v, mc.P), curr_v, atol=self.TOL)