示例#1
0
 def test_read_logic_missing_equation(self):
     """
     Raise ValueError if an equation is missing
     """
     LOGIC = join(self.LOGIC_PATH, "missing_equation.txt")
     with self.assertRaises(FormatError):
         LogicNetwork.read_logic(LOGIC)
示例#2
0
 def test_logic_simple_read_no_node_headers(self):
     """
     Test simple network read in (no node headers)
     """
     SIMPLE_TRUTH_TABLE = join(self.TABLE_PATH, "no_node_headers.txt")
     with self.assertRaises(FormatError):
         LogicNetwork.read_table(SIMPLE_TRUTH_TABLE)
示例#3
0
 def test_read_table_missing_node(self):
     """
     Raise FormatError if a node is missing from the header
     """
     TRUTH_TABLE = join(self.TABLE_PATH, "missing_node.txt")
     with self.assertRaises(FormatError):
         LogicNetwork.read_table(TRUTH_TABLE)
示例#4
0
 def test_read_table_invalid_condition(self):
     """
     Raise FormatError if a condition has an invalid state
     """
     TRUTH_TABLE = join(self.TABLE_PATH, "invalid_condition.txt")
     with self.assertRaises(FormatError):
         LogicNetwork.read_table(TRUTH_TABLE)
示例#5
0
    def test_neighbors_both(self):

        net = LogicNetwork([((1, 2), set(['11', '10'])), ((0, ), set(['1'])),
                            ((0, 1, 2), set(['010', '011', '101'])),
                            ((3, ), set(['1']))])

        self.assertEqual(net.neighbors(2), set([0, 1, 2]))
示例#6
0
    def test_to_networkx_graph_names(self):
        net = LogicNetwork([((1, 2), {'01', '10'}),
                            ((0, 2), ((0, 1), '10', [1, 1])),
                            ((0, 1), {'11'})], ['A', 'B', 'C'])

        nx_net = net.to_networkx_graph(labels='names')
        self.assertEqual(set(nx_net), set(['A', 'B', 'C']))
示例#7
0
 def test_logic_simple_read_no_header(self):
     """
     Test simple network read in (no header)
     """
     TRUTH_TABLE = join(self.TABLE_PATH, "no_header.txt")
     with self.assertRaises(FormatError):
         LogicNetwork.read_table(TRUTH_TABLE)
示例#8
0
    def test_network_graph_metadata(self):
        net = LogicNetwork([((0, ), {'0'})])
        net.metadata['name'] = 'net_name'

        nx_net = net.network_graph(labels='indices')

        self.assertEqual(nx_net.graph['name'], net.metadata['name'])
示例#9
0
    def test_canalizing(self):
        net = LogicNetwork([((1, 2), {'01', '10'}),
                            ((0, 2), ('01', '10', '11')), ((0, 1), {'11'})])

        edges = net.canalizing_edges()
        self.assertEqual(edges, {(1, 0), (1, 2), (2, 0), (2, 1)})

        nodes = net.canalizing_nodes()
        self.assertEqual(nodes, {1, 2})
示例#10
0
    def test_init(self):
        net = LogicNetwork([((0, ), {'0'})])
        self.assertEqual(1, net.size)
        self.assertEqual([(1, {0})], net._encoded_table)

        net = LogicNetwork([((1, ), {'0', '1'}), ((0, ), {'1'})], ['A', 'B'])
        self.assertEqual(2, net.size)
        self.assertEqual(['A', 'B'], net.names)
        self.assertEqual([(2, {0, 2}), (1, {1})], net._encoded_table)
示例#11
0
    def test_is_canalizing_logic_network(self):
        net = LogicNetwork([((1, 2), {'01', '10'}),
                            ((0, 2), ('01', '10', '11')), ((0, 1), {'11'}),
                            ((3, ), {'0'})])

        self.assertFalse(net.is_canalizing(0, 1))
        self.assertTrue(net.is_canalizing(1, 0))
        self.assertTrue(net.is_canalizing(2, 1))
        self.assertFalse(net.is_canalizing(0, 3))
        self.assertFalse(net.is_canalizing(3, 0))
示例#12
0
    def test_logic_simple_read_no_node_headers(self):
        from os.path import dirname, abspath, realpath, join

        # Determine the path to the "data" directory of the neet.test module
        DATA_PATH = join(dirname(abspath(realpath(__file__))), "data")

        # Test simple network read in (no header)
        SIMPLE_TRUTH_TABLE = join(
            DATA_PATH, "test_simple_no_node_headers-truth_table.txt")
        with self.assertRaises(FormatError):
            LogicNetwork.read_table(SIMPLE_TRUTH_TABLE)
示例#13
0
    def test_read_table_condition_len_mismatch(self):
        """
        Raise FormatError if a condition has too many or too few bits in it
        """
        TRUTH_TABLE = join(self.TABLE_PATH, "missing_condition.txt")
        with self.assertRaises(FormatError):
            LogicNetwork.read_table(TRUTH_TABLE)

        TRUTH_TABLE = join(self.TABLE_PATH, "extra_condition.txt")
        with self.assertRaises(FormatError):
            LogicNetwork.read_table(TRUTH_TABLE)
示例#14
0
    def test_average_sensitivity_logic_network(self):
        net = LogicNetwork([((1, 2), {'01', '10'}),
                            ((0, 2), ('01', '10', '11')), ((0, 1), {'11'})])

        s = net.average_sensitivity()
        self.assertAlmostEqual(s, 1.3333333333333333)

        s = net.average_sensitivity(weights=np.ones(8))
        self.assertAlmostEqual(s, 1.3333333333333333)

        s = net.average_sensitivity(states=list(net))
        self.assertAlmostEqual(s, 1.3333333333333333)
示例#15
0
    def test_transitions_logicnetwork(self):
        net = LogicNetwork([((1, ), {'0', '1'}), ((0, ), {'1'})])

        landscape = Landscape(net)
        self.assertEqual(net, landscape.network)
        self.assertEqual(2, landscape.size)
        self.assertEqual([1, 3, 1, 3], list(landscape.transitions))
示例#16
0
 def test_transitions_logicnetwork_encoded(self):
     """
     test `transitions` on `LogicNetwork`s, states encoded
     """
     net = LogicNetwork([((1, ), {'0', '1'}), ((0, ), {'1'})])
     got = transitions(net, encode=True)
     self.assertEqual([1, 3, 1, 3], got)
示例#17
0
 def test_transitions_logicnetwork(self):
     """
     test `transitions` on `LogicNetwork`s
     """
     net = LogicNetwork([((1, ), {'0', '1'}), ((0, ), {'1'})])
     got = transitions(net)
     self.assertEqual([[1, 0], [1, 1], [1, 0], [1, 1]], got)
示例#18
0
    def test_init_long(self):
        table = [((), set()) for _ in range(65)]
        table[0] = ((np.int64(64), ), set('1'))

        mask = long(2)**64

        net = LogicNetwork(table)
        self.assertEqual(net.table, table)
        self.assertEqual(net._encoded_table[0], (mask, set([mask])))
示例#19
0
    def test_transitions_logicnetwork_index(self):
        net = LogicNetwork([((1,), {'0', '1'}), ((0,), {'1'})])

        net.landscape(index=1)
        self.assertEqual([0, 3, 0, 3], list(net.transitions))

        net.landscape(index=0)
        self.assertEqual([1, 1, 3, 3], list(net.transitions))

        net.landscape(index=None)
        self.assertEqual([1, 3, 1, 3], list(net.transitions))
示例#20
0
    def test_transitions_logicnetwork_pin(self):
        net = LogicNetwork([((1,), {'0', '1'}), ((0,), {'1'})])

        net.landscape(pin=[1])
        self.assertEqual([1, 1, 3, 3], list(net.transitions))

        net.landscape(pin=[0])
        self.assertEqual([0, 3, 0, 3], list(net.transitions))

        net.landscape(pin=None)
        self.assertEqual([1, 3, 1, 3], list(net.transitions))
示例#21
0
    def test_transitions_logicnetwork_values(self):
        net = LogicNetwork([((1,), {'0', '1'}), ((0,), {'1'})])

        net.landscape(values={0: 1})
        self.assertEqual([1, 3, 1, 3], list(net.transitions))

        net.landscape(values={1: 0})
        self.assertEqual([1, 1, 1, 1], list(net.transitions))

        net.landscape(values={})
        self.assertEqual([1, 3, 1, 3], list(net.transitions))
示例#22
0
 def test_read_table_skips_empty(self):
     """
     Empty lines are skipped when reading truth tables
     """
     TRUTH_TABLE = join(self.TABLE_PATH, "empty_lines.txt")
     simple = LogicNetwork.read_table(TRUTH_TABLE)
     self.assertEqual(simple.names, ['A', 'B', 'C'])
     self.assertEqual(simple.table,
                      [((1, 2), set(['10', '11'])), ((0, ), set(['1'])),
                       ((1, 2, 0), set(['101', '010', '011']))])
示例#23
0
    def test_update_exceptions(self):
        net = LogicNetwork([((1, 2), {'01', '10'}),
                            ((0, 2), {(0, 1), '10', (1, 1)}),
                            ((0, 1), {'11'})])
        with self.assertRaises(ValueError):
            net.update([0, 0])

        with self.assertRaises(ValueError):
            net.update([0, 0, 1], values={0: 2})

        with self.assertRaises(ValueError):
            net.update([0, 0, 1], pin=[0], values={0: 1})
示例#24
0
    def _randomize(self, topo=None):
        if topo is None:
            topo = self.topogen.random()

        table = []
        for node in np.sort(topo.nodes):
            predecessors = tuple(topo.predecessors(node))
            table.append(
                (predecessors, self._random_function(len(predecessors))))
        return LogicNetwork(table)
示例#25
0
    def test_node_dependency(self):
        net = LogicNetwork([((1, 2), {'11', '10'}), ((0, ), {'1'}),
                            ((0, 1, 2), {'010', '011', '101', '100'})])

        self.assertTrue(net.is_dependent(0, 1))
        self.assertFalse(net.is_dependent(0, 2))

        self.assertTrue(net.is_dependent(1, 0))
        self.assertFalse(net.is_dependent(1, 2))

        self.assertFalse(net.is_dependent(2, 2))
        self.assertTrue(net.is_dependent(2, 0))
        self.assertTrue(net.is_dependent(2, 1))
示例#26
0
    def test_logic_simple_read_empty(self):
        """
        Test simple network read in (empty table)
        """
        TRUTH_TABLE = join(self.TABLE_PATH, "empty_table.txt")
        simple = LogicNetwork.read_table(TRUTH_TABLE)

        self.assertEqual(simple.names, ['A', 'B', 'C', 'D'])
        self.assertEqual(simple.table,
                         [((0, ), set(['1'])), ((1, ), set(['1'])),
                          ((2, ), set(['1'])), ((3, ), set(['1']))])
示例#27
0
def make_network(net, trans):
    """
    Given a network and desired state transitions, construct a `LogicNetwork`
    which implements those transitions.
    """
    table = [(list(range(net.size)), set()) for _ in range(net.size)]
    for a, b in zip(net, map(net.decode, trans)):
        state = ''.join(map(str, a))
        for u, row in zip(b, table):
            if u == 1:
                row[1].add(state)
    return LogicNetwork(table, reduced=True)
示例#28
0
    def test_logic_simple_read_custom_comment(self):
        """
        Test simple network read in with custom comments
        """
        TRUTH_TABLE = join(self.TABLE_PATH, "custom_comment.txt")
        simple = LogicNetwork.read_table(TRUTH_TABLE)

        self.assertEqual(simple.names, ['A', 'B', 'C', 'D'])
        self.assertEqual(simple.table,
                         [((1, 2), set(['11', '10'])), ((0, ), set(['1'])),
                          ((1, 2, 0), set(['010', '011', '101'])),
                          ((3, ), set(['1']))])
示例#29
0
    def test_logic_simple_read(self):
        """
        Read a network from a truth table file
        """
        TRUTH_TABLE = join(self.TABLE_PATH, "simple_table.txt")
        simple = LogicNetwork.read_table(TRUTH_TABLE)

        self.assertEqual(simple.names, ['A', 'B', 'C', 'D'])
        self.assertEqual(simple.table,
                         [((1, 2), set(['11', '10'])), ((0, ), set(['1'])),
                          ((1, 2, 0), set(['010', '011', '101'])),
                          ((3, ), set(['1']))])
示例#30
0
    def test_is_irreducible_satisfies(self):
        """
        IsIrreducible.satisfies correctly identifies networks that are
        irreducible.
        """
        constraint = IsIrreducible()
        self.assertTrue(constraint.satisfies(myeloid))

        reducible = LogicNetwork([((0,), {'0', '1'})])
        self.assertFalse(constraint.satisfies(reducible))

        reducible = LogicNetwork([((0, 1), {'01', '11'}),
                                  ((0, 1), {'00', '01', '11'})])
        self.assertFalse(constraint.satisfies(reducible))

        reducible = LogicNetwork([((1,), {'0'}),
                                  ((0, 1), {'01', '11'})])
        self.assertFalse(constraint.satisfies(reducible))

        irreducible = LogicNetwork([((0,), {'0'})])
        self.assertTrue(constraint.satisfies(irreducible))

        irreducible = LogicNetwork([((0, 1), {'01'}),
                                    ((0, 1), {'00', '01', '11'})])
        self.assertTrue(constraint.satisfies(irreducible))

        irreducible = LogicNetwork([((1,), {'0'}),
                                    ((0, 1), {'01', '11', '10'})])
        self.assertTrue(constraint.satisfies(irreducible))