Exemplo n.º 1
0
Arquivo: funs.cpp Projeto: cran/mpbart
//--------------------------------------------------
//get sufficient stats for pair of bottom children nl(left) and nr(right) in tree x
void getsuff(std::vector<std::vector<double> >& X, 
			tree& x, tree::tree_cp nl, tree::tree_cp nr, 
			xinfo& xi, dinfo& di, sinfo& sl, sinfo& sr)
{


     double* xx = new double[di.n_cov];
   double y;  //current y
   sl.n=0;sl.sy=0.0;sl.sy2=0.0;
   sr.n=0;sr.sy=0.0;sr.sy2=0.0;

   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];
	  }
      tree::tree_cp bn = x.bn(xx,xi);
      if(bn==nl) {
         y = di.y[i];
         sl.n++;
         sl.sy += y;
         sl.sy2 += y*y;
      }
      if(bn==nr) {
         y = di.y[i];
         sr.n++;
         sr.sy += y;
         sr.sy2 += y*y;
      }
   }
}
Exemplo n.º 2
0
Arquivo: funs.cpp Projeto: cran/mpbart
//--------------------------------------------------
//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;
   }
}
Exemplo n.º 3
0
Arquivo: funs.cpp Projeto: cran/mpbart
//--------------------------------------------------
//get sufficient stats for children (v,c) of node nx in tree x
void getsuff(std::vector<std::vector<double> >& X, 
			tree& x, tree::tree_cp nx, size_t v, size_t c, 
			xinfo& xi, dinfo& di, sinfo& sl, sinfo& sr)
{
      double* xx = new double[di.n_cov];
   double y;  //current y
   sl.n=0;sl.sy=0.0;sl.sy2=0.0;
   sr.n=0;sr.sy=0.0;sr.sy2=0.0;

   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];
	  }
	  
      if(nx==x.bn(xx,xi)) { //does the bottom node = xx's bottom node
         y = di.y[i];
         if(xx[v] < xi[v][c]) {
               sl.n++;
               sl.sy += y;
               sl.sy2 += y*y;
          } else {
               sr.n++;
               sr.sy += y;
               sr.sy2 += y*y;
          }
      }
   }
}
Exemplo n.º 4
0
Arquivo: funs.cpp Projeto: cran/mpbart
void fit(tree& t, std::vector<std::vector<double> >& X, dinfo di, xinfo& xi, std::vector<double>& fv)
{
   double* xx = new double[di.n_cov];
   tree::tree_cp bn;

   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];
	}
      
      bn = t.bn(xx,xi);
      fv[i] = bn->getm();
   }
}