diff --git a/pybrush/deap_api/nsga2.py b/pybrush/deap_api/nsga2.py index 048cde56..378beb62 100644 --- a/pybrush/deap_api/nsga2.py +++ b/pybrush/deap_api/nsga2.py @@ -47,10 +47,10 @@ def calculate_statistics(ind): toolbox.update_current_gen(gen) # Vary the population - print("--"*20) - print("pop before select") - for p in pop: - print(p.program.get_model()) + # print("--"*20) + # print("pop before select") + # for p in pop: + # print(p.program.get_model()) # print(p.fitness.values) # print(p.fitness.weights) # print(p.fitness.wvalues) @@ -60,39 +60,40 @@ def calculate_statistics(ind): parents = toolbox.select(pop) # , len(pop) # select method from brush's cpp side will use the values in self.parameters_ to decide how many individuals it should select - print("--"*20) - print("pop after select") - for p in pop: - print(p.program.get_model()) + # print("--"*20) + # print("pop after select") + # for p in pop: + # print(p.program.get_model()) - print("--"*20) - print("selected parents") - for p in parents: - print(p.program.get_model()) + # print("--"*20) + # print("selected parents") + # for p in parents: + # print(p.program.get_model()) offspring = toolbox.vary_pop(parents) offspring = list(toolbox.map(toolbox.assign_fit, offspring)) - print("--"*20) - print("offspring") - for p in offspring: - print(p.program.get_model()) + # print("--"*20) + # print("offspring") + # for p in offspring: + # print(p.program.get_model()) # Select the next generation population (no sorting before this step, as # survive==offspring will cut it in half) pop = toolbox.survive(pop + offspring) - print("--"*20) - print("pop after survival") - for p in pop: - print(p.program.get_model()) + # print("--"*20) + # print("pop after survival") + # for p in pop: + # print(p.program.get_model()) pop = toolbox.migrate(pop) - print("--"*20) - print("pop after migration") - for p in pop: - print(p.program.get_model()) + # print("--"*20) + # print("pop after migration") + # for p in pop: + # print(p.program.get_model()) + pop.sort(key=lambda x: x.fitness, reverse=True) record = stats.compile(pop) diff --git a/src/program/tree_node.cpp b/src/program/tree_node.cpp index eacacff7..d67f3793 100644 --- a/src/program/tree_node.cpp +++ b/src/program/tree_node.cpp @@ -162,8 +162,8 @@ int TreeNode::get_complexity() const // include the `w` and `*` if the node is weighted (and it is not a constant or mean label) if (data.get_is_weighted() && !(Is(data.node_type) - || Is(data.node_type) - || Is(data.node_type)) + || (Is(data.node_type) + || Is(data.node_type)) ) ) return operator_complexities.at(NodeType::Mul)*( operator_complexities.at(NodeType::Constant) + diff --git a/src/search_space.cpp b/src/search_space.cpp index a6b11e8b..72f15ded 100644 --- a/src/search_space.cpp +++ b/src/search_space.cpp @@ -277,7 +277,7 @@ tree& SearchSpace::PTC2(tree& Tree, // auto Tree = tree(); - fmt::print("building program with max size {}, max depth {}",max_size,max_d); + // fmt::print("building program with max size {}, max depth {}",max_size,max_d); // Queue of nodes that need children vector> queue; @@ -289,7 +289,7 @@ tree& SearchSpace::PTC2(tree& Tree, Node root = spot.node->data; - cout << "root " << root.name << endl; + // cout << "root " << root.name << endl; // auto spot = Tree.set_head(n); // updating size accordingly to root node @@ -305,7 +305,7 @@ tree& SearchSpace::PTC2(tree& Tree, //For each argument position a of n, Enqueue(a; g) for (auto a : root.arg_types) { - cout << "queing a node of type " << DataTypeName[a] << endl; + // cout << "queing a node of type " << DataTypeName[a] << endl; auto child_spot = Tree.append_child(spot); queue.push_back(make_tuple(child_spot, a, d)); } @@ -314,8 +314,8 @@ tree& SearchSpace::PTC2(tree& Tree, Node n; // Now we actually start the PTC2 procedure to create the program tree - cout << "queue size: " << queue.size() << endl; - cout << "entering first while loop...\n"; + // cout << "queue size: " << queue.size() << endl; + // cout << "entering first while loop...\n"; while ( queue.size() + s < max_size && queue.size() > 0) { // including the queue size in the max_size, since each element in queue @@ -327,14 +327,14 @@ tree& SearchSpace::PTC2(tree& Tree, // always insert a non terminal (which by default has weights off). // this way, we can have PTC2 working properly. - cout << "queue size: " << queue.size() << endl; + // cout << "queue size: " << queue.size() << endl; auto [qspot, t, d] = RandomDequeue(queue); - cout << "current depth: " << d << endl; + // cout << "current depth: " << d << endl; if (d >= max_d || s >= max_size) { // choose terminal of matching type - cout << "getting " << DataTypeName[t] << " terminal\n"; + // cout << "getting " << DataTypeName[t] << " terminal\n"; // qspot = sample_terminal(t); // Tree.replace(qspot, sample_terminal(t)); // Tree.append_child(qspot, sample_terminal(t)); @@ -354,9 +354,9 @@ tree& SearchSpace::PTC2(tree& Tree, else { //choose a nonterminal of matching type - cout << "getting op of type " << DataTypeName[t] << endl; + // cout << "getting op of type " << DataTypeName[t] << endl; auto opt = sample_op(t); - cout << "chose " << n.name << endl; + // cout << "chose " << n.name << endl; // TreeIter new_spot = Tree.append_child(qspot, n); // qspot = n; @@ -379,7 +379,7 @@ tree& SearchSpace::PTC2(tree& Tree, // For each arg of n, add to queue for (auto a : n.arg_types) { - cout << "queing a node of type " << DataTypeName[a] << endl; + // cout << "queing a node of type " << DataTypeName[a] << endl; // queue.push_back(make_tuple(new_spot, a, d+1)); auto child_spot = Tree.append_child(newspot); @@ -399,20 +399,20 @@ tree& SearchSpace::PTC2(tree& Tree, && Isnt(n.node_type) ) s += 2; - cout << "current tree size: " << s << endl; + // cout << "current tree size: " << s << endl; } - cout << "entering second while loop...\n"; + // cout << "entering second while loop...\n"; while (queue.size() > 0) { if (queue.size() == 0) break; - cout << "queue size: " << queue.size() << endl; + // cout << "queue size: " << queue.size() << endl; auto [qspot, t, d] = RandomDequeue(queue); - cout << "getting " << DataTypeName[t] << " terminal\n"; + // cout << "getting " << DataTypeName[t] << " terminal\n"; // Tree.append_child(qspot, sample_terminal(t)); // qspot = sample_terminal(t); // auto newspot = Tree.replace(qspot, sample_terminal(t)); @@ -426,9 +426,9 @@ tree& SearchSpace::PTC2(tree& Tree, auto newspot = Tree.replace(qspot, n); } - cout << "final tree:\n" - << Tree.begin().node->get_model() << "\n" - << Tree.begin().node->get_tree_model(true) << endl; + // cout << "final tree:\n" + // << Tree.begin().node->get_model() << "\n" + // << Tree.begin().node->get_tree_model(true) << endl; return Tree; };