示例#1
0
int main(int nargs, char *args[])
{
    bayesopt::Parameters par;
    if(nargs > 1) {
        if(!bayesopt::utils::ParamLoader::load(args[1], par)) {
            std::cout << "ERROR: provided file \"" << args[1] << "\" does not exist" << std::endl;
            return -1;
        }
    }
    else {
        par = initialize_parameters_to_default();
        par.n_iterations = 100;
        par.n_init_samples = 2;
        par.n_iter_relearn = 1;
        par.random_seed = 10;
        //set_surrogate(&par,"sStudentTProcessNIG");

        par.l_type = L_MCMC;
        par.sc_type = SC_MAP;
        par.verbose_level = 1;
        //bayesopt::utils::ParamLoader::save("bo_branin_display.txt", par);
    }

    boost::scoped_ptr<BraninNormalized> branin(new BraninNormalized(par));
    GLOBAL_MATPLOT.init(branin.get(),2);

    vectord sv(2);
    sv(0) = 0.1239;
    sv(1) = 0.8183;
    GLOBAL_MATPLOT.setSolution(sv);

    sv(0) = 0.5428;
    sv(1) = 0.1517;
    GLOBAL_MATPLOT.setSolution(sv);

    sv(0) = 0.9617;
    sv(1) = 0.1650;
    GLOBAL_MATPLOT.setSolution(sv);

    glutInit(&nargs, args);
    glutCreateWindow(50,50,800,650);
    glutDisplayFunc( display );
    glutReshapeFunc( reshape );
    glutIdleFunc( idle );
    glutMotionFunc( motion );
    glutMouseFunc( mouse );
    glutPassiveMotionFunc(passive);
    glutKeyboardFunc( keyboard );
    glutMainLoop();

    return 0;
}
示例#2
0
int main(int nargs, char *args[])
{
  bopt_params par = initialize_parameters_to_default();
  par.n_iterations = 190;
  par.random_seed = 0;
  par.verbose_level = 1;
  par.noise = 1e-10;
  
  BraninNormalized branin(par);
  vectord result(2);

  branin.optimize(result);
  std::cout << "Result: " << result << "->" 
	    << branin.evaluateSample(result) << std::endl;
  branin.printOptimal();

  return 0;
}
示例#3
0
int main(int nargs, char *args[])
{
  bayesopt::Parameters par;
  if(nargs > 1){
    if(!bayesopt::utils::ParamLoader::load(args[1], par)){
        std::cout << "ERROR: provided file \"" << args[1] << "\" does not exist" << std::endl;
        return -1;
    }
  }
  else{
    par = initialize_parameters_to_default();
    par.n_iterations = 190;
    par.random_seed = 0;
    par.verbose_level = 1;
    par.noise = 1e-10;
    //bayesopt::utils::ParamLoader::save("system_opt.txt", par);
  }

    
  SystemCallsBranin branin(par);
  vectord result(2);

  branin.optimize(result);
  std::cout << "Result: " << result << "->" 
	    << branin.evaluateSample(result) << std::endl;
  branin.printOptimal();
  
  // Remove results.txt file
  std::string filename("results.txt");
  if( remove( filename.c_str() ) == 0 ){
    std::cout << "File \"" << filename << "\" successfully removed" << std::endl;
  }
  else{
    std::cout << "Error: cannot remove \"" << filename << "\" file" << std::endl; 
  }
  
  return 0;
}
示例#4
0
int main(int nargs, char *args[])
{
  bopt_params par = initialize_parameters_to_default();
  par.verbose_level = 0;
  par.noise = 1e-10;
  par.force_jump = 30;

  std::ofstream log;
  std::clock_t start_t;


  /* Branin */
  log.open("branin.log");
  par.n_init_samples = 5;
  par.n_iterations = 195;

  for (size_t ii = 0; ii < 10; ++ii)
    {
      par.random_seed = ii;
      BraninNormalized branin(par);
      vectord result(2);

      start_t = clock();
      branin.initializeOptimization();
      
      for (size_t jj = 0; jj < par.n_iterations; ++jj)
  	{      
  	  branin.stepOptimization();
  	  if (jj == 50)
  	    {
  	      result = branin.getFinalResult();	      
  	      log << branin.evaluateSample(result) << ", ";
  	    }
  	}
      result = branin.getFinalResult();	      
      log << branin.evaluateSample(result) << ", ";
      
      log << static_cast<double>(clock() - start_t) / static_cast<double>(CLOCKS_PER_SEC)
  	  << std::endl;
      }

  log.close();


  /* Camel */
  log.open("camel.log");
  par.n_init_samples = 5;
  par.n_iterations = 95;

  for (size_t ii = 0; ii < 10; ++ii)
    {
      par.random_seed = ii;
      ExampleCamelback camel(par);
      vectord result(2);

      vectord lb(2); lb(0) = -2; lb(1) = -1;
      vectord ub(2); ub(0) =  2; ub(1) = 1;

      camel.setBoundingBox(lb,ub);

      start_t = clock();
      camel.initializeOptimization();
      
      for (size_t jj = 0; jj < par.n_iterations; ++jj)
  	{      
  	  camel.stepOptimization();
  	  if (jj == 50)
  	    {
  	      result = camel.getFinalResult();	      
  	      log << camel.evaluateSample(result) << ", ";
  	    }
  	}
      result = camel.getFinalResult();	      
      log << camel.evaluateSample(result) << ", ";
      
      log << static_cast<double>(clock() - start_t) / static_cast<double>(CLOCKS_PER_SEC)
  	  << std::endl;
      }

  log.close();


  /* Hart */
  log.open("hart.log");
  par.n_init_samples = 10;
  par.n_iterations = 190;

  for (size_t ii = 0; ii < 10; ++ii)
    {
      par.random_seed = ii;
      ExampleHartmann6 hart(par);
      vectord result(6);

      start_t = clock();
      hart.initializeOptimization();
      
      for (size_t jj = 0; jj < par.n_iterations; ++jj)
  	{      
  	  hart.stepOptimization();
  	  if (jj == 50)
  	    {
  	      result = hart.getFinalResult();	      
  	      log << hart.evaluateSample(result) << ", ";
  	    }
  	}
      result = hart.getFinalResult();	      
      log << hart.evaluateSample(result) << ", ";
      
      log << static_cast<double>(clock() - start_t) / static_cast<double>(CLOCKS_PER_SEC)
  	  << std::endl;
      }

  log.close();


  /***********************************************************************/
  par.n_init_samples = 2;
  par.n_iter_relearn = 1;
  
  par.l_type = L_MCMC;
  par.sc_type = SC_MAP;


  /* Branin */
  log.open("branin_mcmc.log");
  par.n_iterations = 198;

  for (size_t ii = 0; ii < 10; ++ii)
    {
      par.random_seed = ii;
      BraninNormalized branin(par);
      vectord result(2);

      start_t = clock();
      branin.initializeOptimization();
      
      for (size_t jj = 0; jj < par.n_iterations; ++jj)
	{      
	  branin.stepOptimization();
	  if (jj == 50)
	    {
	      result = branin.getFinalResult();	      
	      log << branin.evaluateSample(result) << ", ";
	    }
	}
      result = branin.getFinalResult();	      
      log << branin.evaluateSample(result) << ", ";
      
      log << static_cast<double>(clock() - start_t) / static_cast<double>(CLOCKS_PER_SEC)
	  << std::endl;
      }

  log.close();


  /* Camel */
  log.open("camel_mcmc.log");
  par.n_iterations = 98;

  for (size_t ii = 0; ii < 10; ++ii)
    {
      par.random_seed = ii;
      ExampleCamelback camel(par);
      vectord result(2);

      vectord lb(2); lb(0) = -2; lb(1) = -1;
      vectord ub(2); ub(0) =  2; ub(1) = 1;

      camel.setBoundingBox(lb,ub);

      start_t = clock();
      camel.initializeOptimization();
      
      for (size_t jj = 0; jj < par.n_iterations; ++jj)
	{      
	  camel.stepOptimization();
	  if (jj == 50)
	    {
	      result = camel.getFinalResult();	      
	      log << camel.evaluateSample(result) << ", ";
	    }
	}
      result = camel.getFinalResult();	      
      log << camel.evaluateSample(result) << ", ";
      
      log << static_cast<double>(clock() - start_t) / static_cast<double>(CLOCKS_PER_SEC)
	  << std::endl;
      }

  log.close();


  /* Hart */
  log.open("hart_mcmc.log");
  par.n_iterations = 198;

  for (size_t ii = 0; ii < 10; ++ii)
    {
      par.random_seed = ii;
      ExampleHartmann6 hart(par);
      vectord result(6);

      start_t = clock();
      hart.initializeOptimization();
      
      for (size_t jj = 0; jj < par.n_iterations; ++jj)
	{      
	  hart.stepOptimization();
	  if (jj == 50)
	    {
	      result = hart.getFinalResult();	      
	      log << hart.evaluateSample(result) << ", ";
	    }
	}
      result = hart.getFinalResult();	      
      log << hart.evaluateSample(result) << ", ";
      
      log << static_cast<double>(clock() - start_t) / static_cast<double>(CLOCKS_PER_SEC)
	  << std::endl;
      }

  log.close();


  return 0;
}