4string TreeNode::get_model(
bool pretty)
const
6 if (data.get_arg_count()==0)
7 return data.get_name();
9 vector<string> child_outputs;
10 auto sib = first_child;
11 for(
int i = 0; i < data.get_arg_count(); ++i)
13 child_outputs.push_back(sib->get_model(pretty));
14 sib = sib->next_sibling;
16 return data.get_model(child_outputs);
20string TreeNode::get_tree_model(
bool pretty,
string offset)
const
22 if (data.get_arg_count()==0)
23 return data.get_name();
25 string new_offset =
" ";
26 string child_outputs =
"\n";
28 auto sib = first_child;
29 for(
int i = 0; i < data.get_arg_count(); ++i)
31 child_outputs +=
offset +
"|- ";
32 string s = sib->get_tree_model(pretty, offset+new_offset);
33 sib = sib->next_sibling;
38 child_outputs +=
"\n";
42 if (data.get_feature_type() == DataType::ArrayB)
43 return fmt::format(
"If({})", data.get_feature()) + child_outputs;
45 return fmt::format(
"If({}>{:.2f})", data.get_feature(), data.W) +
49 if (data.arg_types.at(0) == DataType::ArrayB)
52 return "If" + child_outputs;
55 return fmt::format(
"If(>{:.2f})", data.W) + child_outputs;
58 return data.get_name() + child_outputs;
67 for (
const auto &el : t)
78 vector<tree<Node>> stack;
79 for (
int i = j.size(); i --> 0; )
81 auto node = j.at(i).get<
Node>();
83 auto root = subtree.insert(subtree.begin(), node);
84 for (
auto at : node.arg_types)
86 auto spot = subtree.append_child(root);
87 auto arg = stack.back();
88 subtree.move_ontop(spot, arg.begin());
91 stack.push_back(subtree);
100 {NodeType::Asin , 6},
101 {NodeType::Atan , 6},
103 {NodeType::Cosh , 6},
105 {NodeType::Sinh , 6},
107 {NodeType::Tanh , 6},
108 {NodeType::Ceil , 5},
109 {NodeType::Floor , 5},
112 {NodeType::Logabs , 10},
113 {NodeType::Log1p , 9},
114 {NodeType::Sqrt , 5},
115 {NodeType::Sqrtabs , 5},
116 {NodeType::Square , 4},
117 {NodeType::Logistic, 4},
118 {NodeType::OffsetSum, 3},
121 {NodeType::Before, 4},
122 {NodeType::After , 4},
123 {NodeType::During, 4},
128 {NodeType::Mean , 4},
129 {NodeType::Median , 4},
131 {NodeType::Prod , 4},
134 {NodeType::Softmax, 5},
144 {NodeType::SplitBest, 4},
145 {NodeType::SplitOn , 4},
153 {NodeType::MeanLabel, 1},
154 {NodeType::Constant , 2},
155 {NodeType::Terminal , 3},
156 {NodeType::ArgMax , 5},
157 {NodeType::Count , 4},
160 {NodeType::CustomUnaryOp , 5},
161 {NodeType::CustomBinaryOp, 5},
162 {NodeType::CustomSplit , 5}
165int TreeNode::get_linear_complexity()
const
169 auto child = first_child;
170 for(
int i = 0; i < data.get_arg_count(); ++i)
172 tree_complexity += child->get_linear_complexity();
173 child = child->next_sibling;
177 if (data.get_is_weighted()
188 return tree_complexity;
191int TreeNode::get_complexity()
const
194 int children_complexity_sum = 0;
196 auto child = first_child;
197 for(
int i = 0; i < data.get_arg_count(); ++i)
199 children_complexity_sum += child->get_complexity();
200 child = child->next_sibling;
204 children_complexity_sum = max(children_complexity_sum, 1);
207 if (data.get_is_weighted()
215 node_complexity*(children_complexity_sum)
219 return node_complexity*(children_complexity_sum);
222int TreeNode::get_size(
bool include_weight)
const
236 if ( (include_weight && data.get_is_weighted()==
true)
242 auto child = first_child;
243 for(
int i = 0; i < data.get_arg_count(); ++i)
245 acc += child->get_size(include_weight);
246 child = child->next_sibling;
void ReplaceStringInPlace(std::string &subject, const std::string &search, const std::string &replace)
string find and replace in place
auto Isnt(DataType dt) -> bool
void from_json(const json &j, Fitness &f)
auto Is(NodeType nt) -> bool
void to_json(json &j, const Fitness &f)
class holding the data for a node in a tree.
unordered_map< NodeType, int > operator_complexities