//-------------------------------------------------- //get sufficients stats for all bottom nodes void allsuff(std::vector<std::vector<double> >& X, tree& x, xinfo& xi, dinfo& di, tree::npv& bnv, std::vector<sinfo>& sv) { tree::tree_cp tbn; //the pointer to the bottom node for the current observations size_t ni; //the index into vector of the current bottom node double* xx = new double[di.n_cov]; double y; //current y bnv.clear(); x.getbots(bnv); typedef tree::npv::size_type bvsz; bvsz nb = bnv.size(); sv.resize(nb); std::map<tree::tree_cp,size_t> bnmap; for(bvsz i=0;i!=bnv.size();i++) bnmap[bnv[i]]=i; for(size_t i=0;i<di.n_samp;i++) { for(size_t j=0;j<di.n_cov; j++){ xx[j] = X[i][j]; } y=di.y[i]; tbn = x.bn(xx,xi); ni = bnmap[tbn]; ++(sv[ni].n); sv[ni].sy += y; sv[ni].sy2 += y*y; } }
//-------------------------------------------------- //compute prob of a birth, goodbots will contain all the good bottom nodes double getpb(tree& t, xinfo& xi, pinfo& pi, tree::npv& goodbots) { double pb; //prob of birth to be returned tree::npv bnv; //all the bottom nodes t.getbots(bnv); for(size_t i=0;i!=bnv.size();i++) if(cansplit(bnv[i],xi)) goodbots.push_back(bnv[i]); if(goodbots.size()==0) { //are there any bottom nodes you can split on? pb=0.0; } else { if(t.treesize()==1) pb=1.0; //is there just one node? else pb=pi.pb; } return pb; }