Exemple #1
0
 def test_mutual_information_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):
         mutual_information(ECA(30), timesteps=10, local=False)
     mutual_information(ECA(30), timesteps=10, size=5, local=False)
Exemple #2
0
 def test_mutual_information_not_network(self):
     """
     Raise a ``TypeError`` if the provided network is not actually a network
     """
     with self.assertRaises(TypeError):
         mutual_information(5, timesteps=10, local=False)
     with self.assertRaises(TypeError):
         mutual_information(5, timesteps=10, local=True)
Exemple #3
0
    def test_architecture_mi(self):
        """
        The architecture correctly computes the mutual information
        """
        k, timesteps = 5, 20
        arch = Architecture(s_pombe, k=k, timesteps=timesteps)

        expected_mi = mutual_information(s_pombe, timesteps=timesteps)
        got_mi = arch.mutual_information()
        self.assertEqual(got_mi.shape, expected_mi.shape)
        for got, expected in zip(got_mi.flatten(), expected_mi.flatten()):
            self.assertAlmostEqual(expected, got, places=6)

        expected_mi = mutual_information(s_pombe,
                                         timesteps=timesteps,
                                         local=True)
        got_mi = arch.mutual_information(local=True)
        self.assertEqual(got_mi.shape, expected_mi.shape)
        for got, expected in zip(got_mi.flatten(), expected_mi.flatten()):
            self.assertAlmostEqual(expected, got, places=6)
Exemple #4
0
 def test_local_mutual_information_s_pombe(self):
     """
     local ``mutual_information`` averages to the correct values for
     ``s_pombe``
     """
     known_mi = np.asarray(
         [[
             0.162326, 0.013747, 0.004285, 0.004285, 0.013409, 0.015862,
             0.005170, 0.005170, 0.011028
         ],
          [
              0.013747, 0.566610, 0.007457, 0.007457, 0.006391, 0.327908,
              0.006761, 0.006761, 0.004683
          ],
          [
              0.004285, 0.007457, 0.838373, 0.475582, 0.211577, 0.004329,
              0.459025, 0.459025, 0.127557
          ],
          [
              0.004285, 0.007457, 0.475582, 0.838373, 0.211577, 0.004329,
              0.459025, 0.459025, 0.127557
          ],
          [
              0.013409, 0.006391, 0.211577, 0.211577, 0.574591, 0.007031,
              0.175608, 0.175608, 0.012334
          ],
          [
              0.015862, 0.327908, 0.004329, 0.004329, 0.007031, 0.519051,
              0.006211, 0.006211, 0.002607
          ],
          [
              0.005170, 0.006761, 0.459025, 0.459025, 0.175608, 0.006211,
              0.808317, 0.493495, 0.103905
          ],
          [
              0.005170, 0.006761, 0.459025, 0.459025, 0.175608, 0.006211,
              0.493495, 0.808317, 0.103905
          ],
          [
              0.011028, 0.004683, 0.127557, 0.127557, 0.012334, 0.002607,
              0.103905, 0.103905, 0.634238
          ]])
     computed_mi = mutual_information(s_pombe, timesteps=20, local=True)
     self.assertEqual((9, 9, 512, 21), computed_mi.shape)
     for i in range(9):
         for j in range(9):
             self.assertAlmostEqual(known_mi[i, j],
                                    np.mean(computed_mi[i, j]),
                                    places=6)
Exemple #5
0
 def test_mutual_information_s_pombe(self):
     """
     ``mutual_information`` computes the correct values for ``s_pombe``
     """
     known_mi = np.asarray(
         [[
             0.162326, 0.013747, 0.004285, 0.004285, 0.013409, 0.015862,
             0.005170, 0.005170, 0.011028
         ],
          [
              0.013747, 0.566610, 0.007457, 0.007457, 0.006391, 0.327908,
              0.006761, 0.006761, 0.004683
          ],
          [
              0.004285, 0.007457, 0.838373, 0.475582, 0.211577, 0.004329,
              0.459025, 0.459025, 0.127557
          ],
          [
              0.004285, 0.007457, 0.475582, 0.838373, 0.211577, 0.004329,
              0.459025, 0.459025, 0.127557
          ],
          [
              0.013409, 0.006391, 0.211577, 0.211577, 0.574591, 0.007031,
              0.175608, 0.175608, 0.012334
          ],
          [
              0.015862, 0.327908, 0.004329, 0.004329, 0.007031, 0.519051,
              0.006211, 0.006211, 0.002607
          ],
          [
              0.005170, 0.006761, 0.459025, 0.459025, 0.175608, 0.006211,
              0.808317, 0.493495, 0.103905
          ],
          [
              0.005170, 0.006761, 0.459025, 0.459025, 0.175608, 0.006211,
              0.493495, 0.808317, 0.103905
          ],
          [
              0.011028, 0.004683, 0.127557, 0.127557, 0.012334, 0.002607,
              0.103905, 0.103905, 0.634238
          ]])
     computed_mi = mutual_information(s_pombe, timesteps=20)
     self.assertEqual(known_mi.shape, computed_mi.shape)
     for got, expected in zip(computed_mi.flatten(), known_mi.flatten()):
         self.assertAlmostEqual(expected, got, places=6)