list<tree> get_mirrors (tree ln, string id) { if (!is_compound (ln, "link", 4) || ln[0] != "mirror" || !is_compound (ln[2], "id", 1) || !is_atomic (ln[2][0]) || !is_compound (ln[3], "id", 1) || !is_atomic (ln[3][0])) return list<tree> (); if (ln[2][0] == id) return not_done (get_trees (ln[3][0]->label)); if (ln[3][0] == id) return not_done (get_trees (ln[2][0]->label)); return list<tree> (); }
int main(int argc, char * argv[]) { auto trees = get_trees(argc, argv); for (auto & tree : trees) { int postorder_count = 0; for (auto ndi = tree->postorder_begin(); ndi != tree->postorder_end(); ++ndi, ++postorder_count) { std::cout << ndi->get_label() << "\t" << std::setprecision(8) << ndi->get_edge_length() << std::endl; } } }
float RandomForestRegressor::f_predict(const std::vector<float> &feature) { float tot = 0.0; for (int32_t i = 0; i < get_tree_num(); ++i) { float label = get_trees()[i]->predict(feature); tot += label; } std::cout << "nihao" << std::endl; return tot / get_tree_num(); }
int main(int argc, char * argv[]) { auto trees = get_trees(argc, argv); for (auto & tree : trees) { int leaf_count = 0; for (auto ndi = tree->leaf_begin(); ndi != tree->leaf_end(); ++ndi, ++leaf_count) { std::cout << leaf_count + 1 << "\t" << ndi->get_label() << std::endl; if (leaf_count > 40) { std::cerr << "terminating: too many nodes" << std::endl; exit(1); } } } }
vector<Tree*> Tree::descendants() { vector<Tree*> descs; for (auto c : _children) get_trees(c, descs); return descs; }
vector<Tree*> Tree::get_trees() { vector<Tree*> trees; get_trees(this, trees); return trees; }
void Tree::get_trees(Tree* tree, vector<Tree*>& trees) { trees.push_back(tree); if (!tree->isLeaf()) for (auto child : tree->children()) get_trees(child, trees); }
int main(){ scanf("%d%d",&N,&K); printf("%d\n",get_trees()); return 0; }