MatrixXd MultivariateFNormalSufficient::compute_PW_cg() const
{
    //compute PW using CG. Preconditionner is Sigma^-1 and initial guess
    //is previous value of PW. Do M steps (theoretically sufficient) and if the
    //residuals are too big do the inversion.
    //
    timer_.start(PW_CG_SUCCESS);
    //static unsigned numtries=0;
    //static unsigned numfail=0;
    cg_->set_A(get_Sigma());
    cg_->set_B(get_W());
    cg_->set_X0(PW_);
    cg_->set_tol(cg_tol_);
    MatrixXd PW(cg_->optimize(precond_, M_));
    if (cg_->info()>0) timer_.stop(PW_CG_SUCCESS);
    double resid = (get_Sigma()*PW-get_W()).norm();
    if (resid > cg_tol_)
    {
        //numfail++;
        PW = compute_PW_direct();
    }
    //numtries++;
    //std::cout << "CG: numtries="<<numtries<<" numfail="<<numfail<<std::endl;
    return PW;
}
MatrixXd MultivariateFNormalSufficient::compute_PW_direct() const
{
    //Eigen::LLT<MatrixXd, Eigen::Upper> ldlt(get_ldlt());
    Eigen::LDLT<MatrixXd, Eigen::Upper> ldlt(get_ldlt());
    MatrixXd tmp(ldlt.solve(get_W()));
    return tmp;
}
 double MultivariateFNormalSufficient::trace_WP() const
 {
     double trace;
     if (N_==1)
     {
         trace=0;
     } else {
         trace = (get_P()*get_W()).trace();
         LOG( "MVN:   trace(WP) = " << trace << std::endl);
     }
     return trace;
 }
MatrixXd MultivariateFNormalSufficient::compute_PWP() const
{
      //compute PWP
      MatrixXd tmp(M_,M_);
      if (N_==1)
      {
          LOG( "MVN:   W = 0 => PWP = 0" << std::endl);
          tmp.setZero();
      } else {
          LOG( "MVN:   computing PWP" << std::endl);
          MatrixXd P(get_P());
          MatrixXd W(get_W());
          tmp=P*W*P;
      }
      return tmp;
}
 double MultivariateFNormalSufficient::trace_WP() const
 {
     timer_.start(TRWP);
     double trace;
     if (N_==1)
     {
         trace=0;
     } else {
         if (use_cg_)
         {
             trace = get_PW().trace();
         } else {
             trace = (get_P()*get_W()).trace();
         }
         IMP_LOG(TERSE, "MVN:   trace(WP) = " << trace << std::endl);
     }
     timer_.stop(TRWP);
     return trace;
 }
MatrixXd MultivariateFNormalSufficient::compute_PWP() const
{
      timer_.start(PWP);
      //compute PWP
      MatrixXd tmp(M_,M_);
      if (N_==1)
      {
          IMP_LOG(TERSE, "MVN:   W = 0 => PWP = 0" << std::endl);
          tmp.setZero();
      } else {
          IMP_LOG(TERSE, "MVN:   computing PWP" << std::endl);
          /*if (use_cg_)
          {
              if (first_PW_)
              {
                  PW = compute_PW_direct();
                  (*const_cast<bool *>(&first_PW_))=false;
              } else {
                  PW = compute_PW_cg();
              }
          } else {
              PW = compute_PW_direct();
          }*/
            //if (use_cg_)
          //{
              //MatrixXd WP(get_PW().transpose());
              //return get_ldlt().solve(WP);
              //return get_P()*WP;
          //} else {
              MatrixXd P(get_P());
              MatrixXd W(get_W());
              tmp=P*W*P;
          //}
      }
      timer_.stop(PWP);
      return tmp;
}
void GaussianProcessInterpolation::compute_Omega() {
  // sigma_val_ is up-to-date because update_flags_covariance was just called
  Omega_ = get_W() + sigma_val_ * IMP_Eigen::MatrixXd(get_S()) / n_obs_;
}
示例#8
0
文件: main.c 项目: rzmz/GoSky
int main(int argc, char *argv[])
{

  int H,i;
  
  int para_R=0;
  int para_x=0;
  int para_y=0;
  int para_inte=0;
  char *fin=0;
  char *fout=0;
  char show_help=0;
  int isLoggingEnabled=0;

//Argumentide otsimine
  for(i=0; i<argc;i++){
	  if((strcmp(argv[i], "-R")==0) && ((i+1)<argc)){
  		  para_R=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-x")==0) && ((i+1)<argc)){
  		  para_x=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-y")==0) && ((i+1)<argc)){
  		  para_y=atoi(argv[i+1]);
  	  	  }
  	  else if((strcmp(argv[i], "-fin")==0) && ((i+1)<argc)){
  		fin=argv[i+1];
  	  	  }
  	  else if((strcmp(argv[i], "-fout")==0) && ((i+1)<argc)){
  		fout=argv[i+1];
  	  	  }
  	  else if((strcmp(argv[i], "-inte")==0) && ((i+1)<argc)){
  		para_inte=atoi(argv[i+1]);
  	  	  	  }
  	  else if((strcmp(argv[i], "-help")==0)){
  		show_help=1;
  	  	  }
  	  else if((strcmp(argv[i], "-log")==0)){
  		isLoggingEnabled=1;
  	  	  }
  	  else{
  		  //printf("Unknown parameter or missing argument: %s", argv[i]);
  	  	  }
  	  }

//Kui mõni argumentidest on olnud help, siis trüki see ja välju.
  if(show_help==1){
	  HELP();
	  return 0;
  	  }


//Kui Logimine on lubatud, siis tekitan logimise failid
  if(isLoggingEnabled){
  	init_error_log("ERROR.txt");
  	init_progress_log("PROGRESS.txt");
	}


/*
  printf("R %i\n", para_R);
  printf("x %i\n", para_x);
  printf("y %i\n", para_y);
  printf("intensity %i\n", para_inte);
  printf("Fin %s\n", fin);
  printf("Fout %s\n", fout);
*/

//Päris programm

  open_img(fin);
  
  //Antud funktsiooni sees toimub parameetrite korrigeerimine 
  DWPA_set_parameters(get_W(), get_H(), para_x, para_y, para_R, para_inte);
  //DWPA_set_parameters(get_W(), get_H(), para_R, 1 );
  H=DWPA_get_img_size();
  create_map(H, H);
  generate_image_from_map(fout);

  char str_msg[1024];
  sprintf(str_msg, "%s -> %s\n", fin, fout);
  write_progress_log(str_msg);

  close_error_log();
  close_progress_log();
  return 0;
}