def full_method(self): # initialize tree tree = Tree() tree.size = 1 tree.depth = self.max_depth tree.root = self.generate_func_node() tree.tree_type = self.gen_config.get("tree_type", None) # build tree via full method self.full_method_build_tree(tree, tree.root, 0) tree.update() return tree
def test_edit_tree_inputs_and_terminals(self): # TEST INPUTS AND TERMINALS term_node_1 = Node(NodeType.CONSTANT, value=2.0) term_node_2 = Node(NodeType.INPUT, name="x") func_node = Node(NodeType.FUNCTION, name="ADD", arity=2, branches=[term_node_1, term_node_2]) print "BEFORE:", func_node tree = Tree() tree.root = func_node tree.depth = 3 editor.edit_tree(tree, tree.root, self.functions) print "AFTER:", func_node print
def test_edit_tree_zero_only(self): # TEST CONTAINS ZERO term_node_1 = Node(NodeType.CONSTANT, value=0.0) term_node_2 = Node(NodeType.CONSTANT, value=1.0) func_node = Node(NodeType.FUNCTION, name="ADD", arity=2, branches=[term_node_1, term_node_2]) print "BEFORE:", func_node tree = Tree() tree.root = func_node tree.depth = 3 editor.edit_tree(tree, tree.root, self.functions) print "AFTER:", func_node print self.assertEquals(func_node.value, 1.0)
def test_edit_tree_inputs_and_terminals(self): # TEST INPUTS AND TERMINALS term_node_1 = Node(NodeType.CONSTANT, value=2.0) term_node_2 = Node(NodeType.INPUT, name="x") func_node = Node( NodeType.FUNCTION, name="ADD", arity=2, branches=[term_node_1, term_node_2] ) print "BEFORE:", func_node tree = Tree() tree.root = func_node tree.depth = 3 editor.edit_tree(tree, tree.root, self.functions) print "AFTER:", func_node print
def test_edit_tree_prune(self): # TEST PRUNE term_node_1 = Node(NodeType.CONSTANT, value=0.0) term_node_2 = Node(NodeType.INPUT, name="x") func_node = Node(NodeType.FUNCTION, name="MUL", arity=2, branches=[term_node_1, term_node_2]) print "BEFORE:", func_node tree = Tree() tree.root = func_node tree.depth = 3 editor.edit_tree(tree, tree.root, self.functions) print "AFTER:", func_node print self.assertEquals(func_node.node_type, NodeType.CONSTANT) self.assertIsNone(func_node.name) self.assertEquals(func_node.value, 0)
def test_edit_tree_terminals_only(self): # TEST TERMINALS ONLY term_node_1 = Node(NodeType.CONSTANT, value=2.0) term_node_2 = Node(NodeType.CONSTANT, value=1.0) func_node = Node( NodeType.FUNCTION, name="ADD", arity=2, branches=[term_node_1, term_node_2] ) print "BEFORE:", func_node tree = Tree() tree.root = func_node tree.depth = 3 editor.edit_tree(tree, tree.root, self.functions) print "AFTER:", func_node print self.assertEquals(func_node.value, 3.0)
def test_edit_tree_prune(self): # TEST PRUNE term_node_1 = Node(NodeType.CONSTANT, value=0.0) term_node_2 = Node(NodeType.INPUT, name="x") func_node = Node( NodeType.FUNCTION, name="MUL", arity=2, branches=[term_node_1, term_node_2] ) print "BEFORE:", func_node tree = Tree() tree.root = func_node tree.depth = 3 editor.edit_tree(tree, tree.root, self.functions) print "AFTER:", func_node print self.assertEquals(func_node.node_type, NodeType.CONSTANT) self.assertIsNone(func_node.name) self.assertEquals(func_node.value, 0)