Пример #1
0
    def test_pdag_to_dag(self):
        pdag1 = DirectedGraph([('A', 'B'), ('C', 'B'), ('C', 'D'), ('D', 'C'),
                               ('D', 'A'), ('A', 'D')])
        dag1 = ConstraintBasedEstimator.pdag_to_dag(pdag1)
        self.assertTrue(('A', 'B') in dag1.edges()
                        and ('C', 'B') in dag1.edges()
                        and len(dag1.edges()) == 4)

        pdag2 = DirectedGraph([('B', 'C'), ('D', 'A'), ('A', 'D'), ('A', 'C')])
        dag2 = ConstraintBasedEstimator.pdag_to_dag(pdag2)
        self.assertTrue(
            set(dag2.edges()) == set([('B', 'C'), ('A', 'D'), ('A', 'C')])
            or set(dag2.edges()) == set([('B', 'C'), ('D', 'A'), ('A', 'C')]))

        pdag3 = DirectedGraph([('B', 'C'), ('D', 'C'), ('C', 'D'), ('A', 'C')])
        dag3 = ConstraintBasedEstimator.pdag_to_dag(pdag3)
        self.assertSetEqual(set([('B', 'C'), ('C', 'D'), ('A', 'C')]),
                            set(dag3.edges()))
Пример #2
0
 def setUp(self):
     self.graph = DirectedGraph()
Пример #3
0
 def test_class_init_with_data_string(self):
     self.graph = DirectedGraph([('a', 'b'), ('b', 'c')])
     self.assertListEqual(sorted(self.graph.nodes()), ['a', 'b', 'c'])
     self.assertListEqual(hf.recursive_sorted(self.graph.edges()),
                          [['a', 'b'], ['b', 'c']])
Пример #4
0
 def test_update_node_parents_bm_constructor(self):
     self.graph = DirectedGraph([('a', 'b'), ('b', 'c')])
     self.assertListEqual(self.graph.predecessors('a'), [])
     self.assertListEqual(self.graph.predecessors('b'), ['a'])
     self.assertListEqual(self.graph.predecessors('c'), ['b'])
Пример #5
0
 def setUp(self):
     self.graph = DirectedGraph()
     self.graph.add_edges_from([('diff', 'grade'), ('intel', 'grade')])