def test_entropy_rate_not_network(self): """ Raise a ``TypeError`` if the provided network is not actually a network """ with self.assertRaises(TypeError): entropy_rate(5, k=3, timesteps=10, local=False) with self.assertRaises(TypeError): entropy_rate(5, k=3, timesteps=10, local=True)
def test_entropy_rate_not_fixed_size(self): """ Raise a ``ValueError`` if the provided network is not fixed sized, and the ``size`` argument is ``None`` """ with self.assertRaises(ValueError): entropy_rate(ECA(30), k=3, timesteps=10, local=False) entropy_rate(ECA(30), k=3, timesteps=10, size=5, local=False)
def test_local_entropy_rate_s_pombe(self): """ local ``entropy_rate`` averages to the correct values for ``s_pombe`` """ known_er = [ 0.0, 0.016912, 0.072803, 0.072803, 0.058420, 0.024794, 0.032173, 0.032173, 0.089669 ] computed_er = entropy_rate(s_pombe, k=5, timesteps=20, local=True) self.assertEqual((9, 512, 16), computed_er.shape) for got, expected in zip(computed_er, known_er): self.assertAlmostEqual(expected, np.mean(got), places=6)
def test_entropy_rate_s_pombe(self): """ ``entropy_rate`` computes the correct values for ``s_pombe`` """ known_er = [ 0.0, 0.016912, 0.072803, 0.072803, 0.058420, 0.024794, 0.032173, 0.032173, 0.089669 ] computed_er = entropy_rate(s_pombe, k=5, timesteps=20) self.assertEqual(9, len(computed_er)) for got, expected in zip(computed_er, known_er): self.assertAlmostEqual(expected, got, places=6)
def test_architecture_er(self): """ The architecture correctly computes the entropy rate """ k, timesteps = 5, 20 arch = Architecture(s_pombe, k=k, timesteps=timesteps) expected_er = entropy_rate(s_pombe, k=k, timesteps=timesteps) got_er = arch.entropy_rate() self.assertEqual(got_er.shape, expected_er.shape) for got, expected in zip(got_er, expected_er): self.assertAlmostEqual(expected, got, places=6) expected_er = entropy_rate(s_pombe, k=k, timesteps=timesteps, local=True) got_er = arch.entropy_rate(local=True) self.assertEqual(got_er.shape, expected_er.shape) for got, expected in zip(got_er.flatten(), expected_er.flatten()): self.assertAlmostEqual(expected, got, places=6)