Exemplo n.º 1
0
 def test_loose_bound(self):
     leaf = Tree()
     stump = Tree(leaf, leaf)
     tree = Tree(stump, leaf)
     pfub = PartitioningFunctionUpperBound(tree, 10, loose=True)
     pfub(100, 2)
     pfub(100, 3)
def test_vcdim_upper_bound():
    leaf = Tree()
    stump = Tree(leaf, leaf)
    tree = Tree(stump, leaf)

    assert vcdim_upper_bound(leaf, 10) == 1
    assert vcdim_upper_bound(stump, 10) == 6
    assert vcdim_upper_bound(tree, 10) == 16
Exemplo n.º 3
0
 def test_compute_upper_bound_stump(self):
     stump = Tree(Tree(), Tree())
     pfub = PartitioningFunctionUpperBound(stump, 10)
     assert pfub(4,1) == 1
     assert pfub(50,1) == 1
     assert pfub(1,2) == 0
     assert pfub(6,2) == 2**5-1
     assert pfub(7,2) < 2**6-1
Exemplo n.º 4
0
 def test_compute_upper_bound_other_trees(self):
     leaf = Tree()
     stump = Tree(leaf, leaf)
     tree = Tree(stump, leaf)
     pfub = PartitioningFunctionUpperBound(tree, 10)
     m = 16
     assert pfub(m,2) == 2**(m-1)-1
     m = 17
     assert pfub(m,2) < 2**(m-1)-1
Exemplo n.º 5
0
    def test_compute_bound_with_precomputed_tables(self):
        leaf = Tree()
        stump = Tree(leaf, leaf)
        tree = Tree(stump, leaf)
        pfub = PartitioningFunctionUpperBound(tree, 10)
        pfub(16, 2)

        other_tree = Tree(tree, tree)
        pfub = PartitioningFunctionUpperBound(other_tree, 10, pfub.pfub_table)
        assert pfub.pfub_table[tree][2, 16, 10] == 2**(16-1)-1
        pfub(17, 2)
Exemplo n.º 6
0
    def test__eq__(self, trees):
        leaf = Tree()
        assert leaf == Tree()

        tree2 = Tree(Tree(leaf, leaf), leaf)
        tree2_mirror = Tree(leaf, Tree(leaf, leaf))
        assert tree2 == tree2_mirror

        assert trees[1] == trees[2].left_subtree
Exemplo n.º 7
0
def trees():
    trees = [Tree()]
    trees.append(Tree(deepcopy(trees[0]), deepcopy(trees[0])))
    trees.append(Tree(deepcopy(trees[1]), deepcopy(trees[0])))
    trees.append(Tree(deepcopy(trees[1]), deepcopy(trees[1])))
    trees.append(Tree(deepcopy(trees[2]), deepcopy(trees[0])))
    trees.append(Tree(deepcopy(trees[2]), deepcopy(trees[1])))
    trees.append(Tree(deepcopy(trees[3]), deepcopy(trees[0])))
    trees.append(Tree(deepcopy(trees[2]), deepcopy(trees[2])))
    trees.append(Tree(deepcopy(trees[3]), deepcopy(trees[1])))
    trees.append(Tree(deepcopy(trees[3]), deepcopy(trees[2])))
    trees.append(Tree(deepcopy(trees[3]), deepcopy(trees[3])))
    return trees
Exemplo n.º 8
0
 def test_split_leaf(self, trees):
     tree = Tree()
     tree.split_leaf()
     assert tree == trees[1]
Exemplo n.º 9
0
 def test_replace_leaf_by_leaf(self, trees):
     tree = Tree(Tree(), Tree())
     tree.left_subtree.replace_subtree(Tree())
     assert tree == trees[1]
Exemplo n.º 10
0
 def test_replace_stump_by_leaf(self, trees):
     tree = Tree(Tree(), Tree())
     tree.replace_subtree(Tree())
     assert tree.is_leaf()
Exemplo n.º 11
0
 def test_replace_leaf_by_stump(self, trees):
     tree = Tree(Tree(), Tree())
     tree.left_subtree.replace_subtree(deepcopy(tree))
     assert tree == trees[2]
     assert [t.height for t in tree] == [2, 1, 0, 0, 0]
     assert [t.depth for t in tree] == [0, 1, 2, 2, 1]
"""
In this script, we compute the VCdim upper bound for the first 11 non-equivalent binary trees.
"""
from partitioning_machines import Tree, vcdim_upper_bound


leaf = Tree() # tree 1
stump = Tree(leaf, leaf) # tree 2
tree3 = Tree(stump, leaf)
tree4 = Tree(stump, stump)
tree5 = Tree(tree3, leaf)
tree6 = Tree(tree4, leaf)
tree7 = Tree(tree3, stump)
tree8 = Tree(tree3, tree3)
tree9 = Tree(tree4, stump)
tree10 = Tree(tree4, tree3)
tree11 = Tree(tree4, tree4)

trees = [
    leaf,
    stump,
    tree3,
    tree4,
    tree5,
    tree6,
    tree7,
    tree8,
    tree9,
    tree10,
    tree11
]
Exemplo n.º 13
0
def test_growth_function_upper_bound():
    assert growth_function_upper_bound(Tree(Tree(), Tree()), n_features=10, n_classes=3)(1) == 3
    assert growth_function_upper_bound(Tree(Tree(), Tree()), n_features=10, n_classes=3)(2) == 3 + 6
Exemplo n.º 14
0
 def test_compute_upper_bound_leaf(self):
     leaf = Tree()
     pfub = PartitioningFunctionUpperBound(leaf, 10)
     assert pfub(4,1) == 1
     assert pfub(4,2) == 0