def testFindTreeGeneric(self): pgm = OrderedDict() # Children: # (root) 0: 1, 2 # 1: 3, 4, 5 # 2: 7 # 3: 6 # 4: 9, 10 # 5: # 6: # 7: 8 # 8: # 9: # 10: add_edges(pgm, [(0, 1), (0, 2), (1, 3), (1, 4), (1, 5), (3, 6), (4, 9), (4, 10), (1, 5), (2, 7), (7, 8)]) depths = { 0: 0, 1: 1, 2: 1, 3: 2, 4: 2, 5: 2, 6: 3, 7: 2, 8: 3, 9: 3, 10: 3 } elimination_order = graph_util.find_tree(pgm) self.assertTrue(check_elimination_ordering(elimination_order, depths))
def testFindTreeLoop(self): pgm = OrderedDict() add_edges(pgm, [(0, 1), (0, 2), (1, 3), (1, 4), (1, 5), (3, 6), (4, 9), (4, 10), (1, 5), (2, 7), (7, 8)]) add_edges(pgm, [(8, 0)]) elimination_order = graph_util.find_tree(pgm) self.assertFalse(elimination_order)
def testFindTreeWheel(self): T = 3 pgm = OrderedDict() add_edges(pgm, [(0, t) for t in range(1, T)]) depths = dict([(0, 0)] + [(t, 1) for t in range(1, T)]) elimination_order = graph_util.find_tree(pgm) self.assertTrue(check_elimination_ordering(elimination_order, depths))
def testFindTreeChainFromEnd(self): # Starting at the end of a chain. pgm = OrderedDict([(0, set([1]))] + [(t, set([t - 1, t + 1])) for t in range(1, T - 1)] + [(T - 1, set([T - 2]))]) depths = dict(zip(range(T), range(T))) elimination_order = graph_util.find_tree(pgm) self.assertTrue(check_elimination_ordering(elimination_order, depths))
def testFindTreeChainFromMiddle(self): mid = T // 2 pgm = OrderedDict([(t, set([t - 1, t + 1])) for t in range(mid, T - 1)] + [(0, set([1])), (T - 1, set([T - 2]))] + [(t, set([t - 1, t + 1])) for t in range(1, mid)]) depths = {t: abs(mid - t) for t in range(T)} elimination_order = graph_util.find_tree(pgm) self.assertTrue(check_elimination_ordering(elimination_order, depths))