// DFS search on tree. Places results in leaves parameter. void tree(unordered_map<string,Interaction>& leaves,Rcpp::List const& datas, int cls, vector<double> const& theta, vector<bool> const& factor,double epsilon_cont,double epsilon_cat, int depth,int min_inter_sz,int branch,Generator& prng,double radius,bool es){ stack<Interaction, vector<Interaction> > frontier; Rcpp::DataFrame class_data = Rcpp::as<Rcpp::DataFrame>(datas[cls]); // Init root int nb_class = datas.size(); vector<double> root_instance = random_instance(class_data,prng); Interaction root(root_instance,factor,class_data,epsilon_cont,epsilon_cat,0,nb_class,radius); frontier.push(root); while(!frontier.empty()){ Interaction parent = frontier.top(); frontier.pop(); int c_depth = parent.get_depth(); int eff_branch = (c_depth <= 0) ? 1 : branch; int nb_valid = 0; // number of valid children for this parent node for(int i=0;i<eff_branch;++i){ int instance_nb = prng(); Interaction child(parent); child.intersect(instance_nb,class_data); child.set_depth(c_depth + 1); if(child.size() >= min_inter_sz && child.check_sims(datas,theta,es)){ // child is valid if(child.size() == min_inter_sz || child.get_depth() == depth){ // child is leaf insert_interaction(leaves,child); } else{ // child is valid but not leaf frontier.push(child); } nb_valid++; } } if(nb_valid == 0) // If no child is valid, add parent as a leaf insert_interaction(leaves,parent); } }
// DFS search on tree. Places results in leaves parameter. void tree(unordered_map<string,Interaction>& leaves,vector<Dataset> const& all_datasets, int cls, vector<Ht_matrix> const& all_matrices,vector<double> const& theta,int depth,int split_nb, int min_inter_sz,int branch,bool es,Generator& prng){ stack<Interaction, vector<Interaction> > frontier; // Init root int nb_class = all_matrices.size(); unordered_set<int> root_instance = random_instance(all_datasets[cls],prng); Interaction root(root_instance,0,nb_class); frontier.push(root); while(!frontier.empty()){ Interaction parent = frontier.top(); frontier.pop(); int c_depth = parent.get_depth(); int eff_branch = (c_depth <= 0 || c_depth%split_nb != 0) ? 1 : branch; int nb_valid = 0; // number of valid children for this parent node for(int i=0;i<eff_branch;++i){ Interaction child(parent); child.intersect(random_instance(all_datasets[cls],prng)); child.set_depth(c_depth + 1); if(child.size() >= min_inter_sz && child.check_prev(all_matrices,theta,all_datasets,es)){ // child is valid if(child.size() == min_inter_sz || child.get_depth() == depth){ // child is leaf insert_interaction(leaves,child,all_matrices,theta,all_datasets); } else{ // child is valid but not leaf frontier.push(child); } nb_valid++; } } if(nb_valid == 0) // If no child is valid, add parent as leaf insert_interaction(leaves,parent,all_matrices,theta,all_datasets); } }