コード例 #1
0
ファイル: Evaluator.cpp プロジェクト: martinjrobins/dakota
/*--------------------------------------------------------*/
void NOMAD::Evaluator::compute_h ( NOMAD::Eval_Point & x ) const
{
  if ( x.get_bb_outputs().size() != _p.get_bb_nb_outputs() ) {
    std::ostringstream err;
    err << "Evaluator::compute_h(x): x has a wrong number of blackbox outputs ("
	<< x.get_bb_outputs().size() << " != "
	<< _p.get_bb_nb_outputs() << ")";
    throw NOMAD::Exception ( "Evaluator.cpp" , __LINE__ , err.str() );
  }

  int                                        nbo  = _p.get_bb_nb_outputs();
  const std::vector<NOMAD::bb_output_type> & bbot = _p.get_bb_output_type();
  const NOMAD::Point                       & bbo  = x.get_bb_outputs();
  NOMAD::Double                              h    = 0.0 , bboi;

  x.set_EB_ok ( true );

  for ( int i = 0 ; i < nbo ; ++i ) {

    bboi = bbo[i];

    if ( bboi.is_defined()                                  &&
	 (bbot[i] == NOMAD::EB || bbot[i] == NOMAD::PEB_E ) &&
	 bboi > _p.get_h_min() ) {
      h.clear();
      x.set_h     ( h     );
      x.set_EB_ok ( false );
      return;
    }
    
    if ( bboi.is_defined() &&
	 ( bbot[i] == NOMAD::FILTER ||
	   bbot[i] == NOMAD::PB     ||
	   bbot[i] == NOMAD::PEB_P     ) ) {
      if ( bboi > _p.get_h_min() ) {
	switch ( _p.get_h_norm() ) {
	case NOMAD::L1:
	  h += bboi;
	  break;
	case NOMAD::L2:
	  h += bboi * bboi;
	  break;
	case NOMAD::LINF:
	  if ( bboi > h )
	    h = bboi;
	  break;
	}
      }
    }
  }

  if ( _p.get_h_norm() == NOMAD::L2 )
    h = h.sqrt();

  x.set_h ( h );
}
コード例 #2
0
/*---------------------------------------------------------*/
bool NOMAD::Directions::compute_halton_dir ( int                halton_index ,
					     int                mesh_index   ,
					     NOMAD::Double    & alpha_t_l    ,
					     NOMAD::Direction & halton_dir     ) const
{
  alpha_t_l.clear();

  int           i;
  NOMAD::Double d , norm = 0.0;
  NOMAD::Point  b ( _nc );

  for ( i = 0 ; i < _nc ; ++i ) 
  {
    d = Directions::get_phi ( halton_index , _primes[i] );
    b[i] = 2*d - 1.0;
    norm += b[i].pow2();
  }
  norm = norm.sqrt();

  // desired squared norm for q:

  NOMAD::direction_type hdt = halton_dir.get_type();

  NOMAD::Double target = ( hdt == NOMAD::ORTHO_2N || hdt == NOMAD::ORTHO_NP1_QUAD || hdt == NOMAD::ORTHO_NP1_NEG ) ?
    pow ( NOMAD::Mesh::get_mesh_update_basis() , abs(mesh_index) / 2.0 ) :
    pow ( NOMAD::Mesh::get_mesh_update_basis() , abs(mesh_index)       );
	

  NOMAD::Double x  = target.sqrt();
  NOMAD::Double fx = eval_ortho_norm ( x , norm , b , halton_dir );
  NOMAD::Double y  = 1.0 , fy , delta_x , abs_dx , min , delta_min , diff , eps;
  bool          inc , possible , set_eps = false;
  int           cnt = 0;

  while ( fx != target )
  {
	  
	  // safety test:
	  if ( ++cnt > 1000 )
	  {
#ifdef DEBUG
		  _out << std::endl << "Warning (" << "Directions.cpp" << ", " << __LINE__
		  << "): could not compute Halton direction for (t="
		  << halton_index << ", ell=" << mesh_index
		  << ")" << std::endl << std::endl;
#endif
		  alpha_t_l.clear();
		  halton_dir.clear();
		  return false;
	  }
	  
	  if ( set_eps ) 
	  {
		  eps     = 1e-8;
		  set_eps = false;
	  }
	  else
		  eps = 0.0;
	  
	  inc = ( fx < target );
	  
	  possible = false;
	  min      = 1e+20;
	  for ( i = 0 ; i < _nc ; ++i ) 
	  {
		  if ( b[i] != 0.0 ) 
		  {
			  if ( b[i] > 0.0 )
			  {
				  if ( inc )
					  diff  =  0.5+eps;
				  else
					  diff  = -0.5-eps;
			  }
			  else 
			  {
				  if ( inc )
					  diff  = -0.5-eps;
				  else
					  diff  =  0.5+eps;
			  }
			  
			  delta_x = norm * ( halton_dir[i] + diff) / b[i] - x;
			  
			  y = x + delta_x;
			  
			  if ( y > 0 )
			  {
				  abs_dx = delta_x.abs();
				  if ( abs_dx < min )
				  {
					  min       = abs_dx;
					  delta_min = delta_x;
					  possible  = true;
				  }
			  }
		  }
	  }
	  
	  if ( !possible ) {
#ifdef DEBUG
		  _out << std::endl << "Warning (" << "Directions.cpp" << ", " << __LINE__
		  << "): could not compute Halton direction for (t="
		  << halton_index << ", ell=" << mesh_index << ")"
		  << std::endl << std::endl;
#endif
		  alpha_t_l.clear();
		  halton_dir.clear();
		  return false;
	  }
	  
	  y  = x + delta_min;
	  fy = eval_ortho_norm ( y , norm , b , halton_dir );
	  
	  if ( fx == fy ) {
		  set_eps = true;
		  continue;
	  }
	  
	  if ( fy==target )
		  break;
	  
	  if ( inc && fy > target && fx > 0 ) {
		  eval_ortho_norm ( x , norm , b , halton_dir );
		  break;
	  }
	  
	  if ( !inc && fy < target && fy > 0 )
		  break;
	  
	  x  = y;
	  fx = fy;
  }

  alpha_t_l = y;

  return true;
}
コード例 #3
0
ファイル: TGP_Model.cpp プロジェクト: TheLoutre/nomad
/*----------------------------------------------------------------*/
void NOMAD::TGP_Model::eval_hf(const NOMAD::Point   &bbo    ,
                               const NOMAD::Double &h_min  ,
                               NOMAD::hnorm_type     h_norm ,
                               NOMAD::Double        &h      ,
                               NOMAD::Double        &f) const
{
    f.clear();
    h = 0.0;

    int m = bbo.size();

    if (m != static_cast<int>(_bbot.size()))
        throw NOMAD::Exception("TGP_Model.cpp" , __LINE__ ,
                               "TGP_Model::eval_hf() called with an invalid bbo argument");

    NOMAD::Double bboi;

    for (int i = 0 ; i < m ; ++i)
    {

        bboi = bbo[i];

        if (bboi.is_defined())
        {

            if (_bbot[i] == NOMAD::EB || _bbot[i] == NOMAD::PEB_E)
            {

                if (bboi > h_min)
                {
                    h.clear();
                    return;
                }
            }

            else if ((_bbot[i] == NOMAD::FILTER ||
                      _bbot[i] == NOMAD::PB     ||
                      _bbot[i] == NOMAD::PEB_P))
            {
                if (bboi > h_min)
                {
                    switch (h_norm)
                    {
                        case NOMAD::L1:
                            h += bboi;
                            break;
                        case NOMAD::L2:
                            h += bboi * bboi;
                            break;
                        case NOMAD::LINF:
                            if (bboi > h)
                                h = bboi;
                            break;
                    }
                }
            }

            else if (_bbot[i] == NOMAD::OBJ)
                f = bboi;
        }

    }

    if (h_norm == NOMAD::L2)
        h = h.sqrt();
}