예제 #1
0
 def test_transfer_entropy_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):
         transfer_entropy(ECA(30), k=3, timesteps=10, local=False)
     transfer_entropy(ECA(30), k=3, timesteps=10, size=5, local=False)
예제 #2
0
 def test_transfer_entropy_not_network(self):
     """
     Raise a ``TypeError`` if the provided network is not actually a network
     """
     with self.assertRaises(TypeError):
         transfer_entropy(5, k=3, timesteps=10, local=False)
     with self.assertRaises(TypeError):
         transfer_entropy(5, k=3, timesteps=10, local=True)
예제 #3
0
 def test_transfer_entropy_s_pombe(self):
     """
     ``transfer_entropy`` computes the correct values for ``s_pombe``
     """
     known_te = np.asarray(
         [[0., 0., 0., 0., 0., 0., 0., 0., 0.],
          [0., 0., 0., 0., 0.016912, 0., 0., 0., 0.],
          [
              0., 0.051370, 0., 0.012225, 0.019947, 0.051370, 0.006039,
              0.006039, 0.072803
          ],
          [
              0., 0.051370, 0.012225, 0., 0.019947, 0.051370, 0.006039,
              0.006039, 0.072803
          ],
          [
              0., 0.058420, 0.047602, 0.047602, 0., 0.058420, 0.047602,
              0.047602, 0.
          ], [0., 0., 0.024794, 0.024794, 0., 0., 0.024794, 0.024794, 0.],
          [
              0., 0.016690, 0.004526, 0.004526, 0.011916, 0.016690, 0.,
              0.002983, 0.032173
          ],
          [
              0., 0.016690, 0.004526, 0.004526, 0.011916, 0.016690,
              0.002983, 0., 0.032173
          ],
          [
              0., 0.060304, 0.048289, 0.048289, 0.089669, 0.060304,
              0.048927, 0.048927, 0.
          ]])
     computed_te = transfer_entropy(s_pombe, k=5, timesteps=20)
     self.assertEqual(known_te.shape, computed_te.shape)
     for got, expected in zip(computed_te.flatten(), known_te.flatten()):
         self.assertAlmostEqual(expected, got, places=6)
예제 #4
0
    def test_architecture_te(self):
        """
        The architecture correctly computes the transfer entropy
        """
        k, timesteps = 5, 20
        arch = Architecture(s_pombe, k=k, timesteps=timesteps)

        expected_te = transfer_entropy(s_pombe, k=k, timesteps=timesteps)
        got_te = arch.transfer_entropy()
        self.assertEqual(got_te.shape, expected_te.shape)
        for got, expected in zip(got_te.flatten(), expected_te.flatten()):
            self.assertAlmostEqual(expected, got, places=6)

        expected_te = transfer_entropy(s_pombe,
                                       k=k,
                                       timesteps=timesteps,
                                       local=True)
        got_te = arch.transfer_entropy(local=True)
        self.assertEqual(got_te.shape, expected_te.shape)
        for got, expected in zip(got_te.flatten(), expected_te.flatten()):
            self.assertAlmostEqual(expected, got, places=6)
예제 #5
0
 def test_local_transfer_entropy_s_pombe(self):
     """
     local ``transfer_entropy`` averages to the correct values for
     ``s_pombe``
     """
     known_te = np.asarray(
         [[0., 0., 0., 0., 0., 0., 0., 0., 0.],
          [0., 0., 0., 0., 0.016912, 0., 0., 0., 0.],
          [
              0., 0.051370, 0., 0.012225, 0.019947, 0.051370, 0.006039,
              0.006039, 0.072803
          ],
          [
              0., 0.051370, 0.012225, 0., 0.019947, 0.051370, 0.006039,
              0.006039, 0.072803
          ],
          [
              0., 0.058420, 0.047602, 0.047602, 0., 0.058420, 0.047602,
              0.047602, 0.
          ], [0., 0., 0.024794, 0.024794, 0., 0., 0.024794, 0.024794, 0.],
          [
              0., 0.016690, 0.004526, 0.004526, 0.011916, 0.016690, 0.,
              0.002983, 0.032173
          ],
          [
              0., 0.016690, 0.004526, 0.004526, 0.011916, 0.016690,
              0.002983, 0., 0.032173
          ],
          [
              0., 0.060304, 0.048289, 0.048289, 0.089669, 0.060304,
              0.048927, 0.048927, 0.
          ]])
     computed_te = transfer_entropy(s_pombe, k=5, timesteps=20, local=True)
     self.assertEqual((9, 9, 512, 16), computed_te.shape)
     for i in range(9):
         for j in range(9):
             self.assertAlmostEqual(known_te[i, j],
                                    np.mean(computed_te[i, j]),
                                    places=6)