예제 #1
0
    def test_trajectory_too_short(self):
        """
        ``trajectory`` should raise a value error if ``timeseries`` is less
        than 1
        """
        with self.assertRaises(ValueError):
            trajectory(MockFixedSizedNetwork(), [1, 2, 3], timesteps=0)

        with self.assertRaises(ValueError):
            trajectory(MockFixedSizedNetwork(), [1, 2, 3], timesteps=-1)
예제 #2
0
    def test_trajectory_logicnetwork(self):
        """
        test `trajectory` on `LogicNetwork`s
        """
        net = LogicNetwork([((1, 2), {'01', '10'}),
                            ((0, 2), {'01', '10', '11'}), ((0, 1), {'11'})])
        state = [0, 1, 0]
        got = trajectory(net, state, 3)
        self.assertEqual([[0, 1, 0], [1, 0, 0], [0, 1, 0], [1, 0, 0]], got)
        self.assertEqual([0, 1, 0], state)

        got = list(trajectory(net, state, 3, encode=True))
        self.assertEqual([2, 1, 2, 1], got)
예제 #3
0
    def test_trajectory_wtnetwork_encoded(self):
        """
        test ``trajectory`` on WTNetworks; encoding the states
        """
        net = WTNetwork(weights=[[1, 0], [-1, 0]],
                        thresholds=[0.5, 0.0],
                        theta=WTNetwork.positive_threshold)

        state = [0, 0]
        got = trajectory(net, state, encode=True)
        self.assertEqual([0, 0], state)
        self.assertEqual([0, 2], got)

        got = trajectory(net, state, timesteps=3, encode=True)
        self.assertEqual([0, 0], state)
        self.assertEqual([0, 2, 2, 2], got)
예제 #4
0
    def test_trajectory_wtnetwork(self):
        """
        test ``trajectory`` on WTNetworks
        """
        net = WTNetwork(weights=[[1, 0], [-1, 0]],
                        thresholds=[0.5, 0.0],
                        theta=WTNetwork.positive_threshold)

        state = [0, 0]
        got = trajectory(net, state)
        self.assertEqual([0, 0], state)
        self.assertEqual([[0, 0], [0, 1]], got)

        got = trajectory(net, state, timesteps=3)
        self.assertEqual([0, 0], state)
        self.assertEqual([[0, 0], [0, 1], [0, 1], [0, 1]], got)
예제 #5
0
    def test_trajectory_eca_encoded(self):
        """
        test ``trajectory`` on ECAs; encoding the states
        """
        rule30 = ECA(30)
        with self.assertRaises(ValueError):
            trajectory(rule30, [], encode=True)

        state = [0, 1, 0]
        got = trajectory(rule30, state, encode=True)
        self.assertEqual([0, 1, 0], state)
        self.assertEqual([2, 7], got)

        got = trajectory(rule30, state, timesteps=2, encode=True)
        self.assertEqual([0, 1, 0], state)
        self.assertEqual([2, 7, 0], got)
예제 #6
0
    def test_trajectory_eca(self):
        """
        test ``trajectory`` on ECAs
        """
        rule30 = ECA(30)
        with self.assertRaises(ValueError):
            trajectory(rule30, [])

        xs = [0, 1, 0]
        got = trajectory(rule30, xs)
        self.assertEqual([0, 1, 0], xs)
        self.assertEqual([[0, 1, 0], [1, 1, 1]], got)

        got = trajectory(rule30, xs, timesteps=2)
        self.assertEqual([0, 1, 0], xs)
        self.assertEqual([[0, 1, 0], [1, 1, 1], [0, 0, 0]], got)
예제 #7
0
 def test_timeseries_wtnetworks(self):
     """
     test ``timeseries`` on WTNetwork
     """
     for (net, size) in [(s_pombe, 9), (s_cerevisiae, 11), (c_elegans, 8)]:
         time = 10
         series = timeseries(net, timesteps=time)
         self.assertEqual((size, 2**size, time + 1), series.shape)
         for index, state in enumerate(net.state_space()):
             traj = trajectory(net, state, timesteps=time)
             for t, expect in enumerate(traj):
                 got = series[:, index, t]
                 self.assertTrue(np.array_equal(expect, got))
예제 #8
0
 def test_timeseries_eca(self):
     """
     test ``timeseries`` on ECA
     """
     rule = ECA(30)
     for size in [5, 7, 11]:
         time = 10
         series = timeseries(rule, timesteps=time, size=size)
         self.assertEqual((size, 2**size, time + 1), series.shape)
         for index, state in enumerate(rule.state_space(size)):
             traj = trajectory(rule, state, timesteps=time)
             for t, expect in enumerate(traj):
                 got = series[:, index, t]
                 self.assertTrue(np.array_equal(expect, got))
예제 #9
0
    def test_trajectory_not_network(self):
        """
        ``trajectory`` should raise a type error if ``net`` is not a network
        """
        with self.assertRaises(TypeError):
            trajectory(5, [1, 2, 3])

        with self.assertRaises(TypeError):
            trajectory(MockObject(), [1, 2, 3])

        with self.assertRaises(TypeError):
            trajectory(MockFixedSizedNetwork, [1, 2, 3])