本文整理汇总了C++中nomad::Double::value方法的典型用法代码示例。如果您正苦于以下问题:C++ Double::value方法的具体用法?C++ Double::value怎么用?C++ Double::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nomad::Double
的用法示例。
在下文中一共展示了Double::value方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LH_values_for_var_i
void LH_values_for_var_i ( int ind ,
int p ,
NOMAD::Point & x, const NOMAD::Point &lb, const NOMAD::Point & ub,
const vector<NOMAD::bb_input_type> &bbin) {
NOMAD::Random_Pickup rp(p);
int i;
NOMAD::Double v;
double UB = ub[ind].value();
double LB = lb[ind].value();
for ( i = 0 ; i < p ; ++i ) {
double w = (UB - LB)/p;
v = LB + ( i + rand()/NOMAD::D_INT_MAX ) * w;
if( bbin[ind]!= NOMAD::CONTINUOUS)
{
x[rp.pickup()] =(int) v.value();
}
else{
x[rp.pickup()] = v;
}
}
}
示例2: rp
/*-----------------------------------------------------------*/
void NOMAD::LH_Search::values_for_var_i ( int p ,
const NOMAD::Double & delta ,
const NOMAD::Double & delta_max ,
const NOMAD::bb_input_type & bbit ,
const NOMAD::Double & lb ,
const NOMAD::Double & ub ,
NOMAD::Point & x ) const
{
// categorical variables have already been treated as fixed variables:
if ( bbit == NOMAD::CATEGORICAL )
return;
int i;
NOMAD::Double v;
NOMAD::Random_Pickup rp (p);
bool rounding = ( bbit != NOMAD::CONTINUOUS );
bool lb_def = lb.is_defined();
bool ub_def = ub.is_defined();
double w = ( ( lb_def && ub_def ) ?
ub.value()-lb.value() : 1.0 ) / p;
// main loop:
for ( i = 0 ; i < p ; ++i )
{
// both bounds exist:
if ( lb_def && ub_def )
v = lb + ( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w;
// one of the bounds does not exist:
else
{
// lb exists, and ub not: mapping [0;1] --> [lb;+INF[
if ( lb_def )
v = lb + 10 * delta_max * sqrt ( - log ( NOMAD::DEFAULT_EPSILON +
( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) );
// lb does not exist:
else
{
// ub exists, and lb not: mapping [0;1] --> ]-INF;ub]
if ( ub_def )
v = ub - delta_max * 10 *
sqrt ( -log ( NOMAD::DEFAULT_EPSILON +
( i +NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) );
// there are no bounds: mapping [0;1] --> ]-INF;+INF[
else
v = (NOMAD::RNG::rand()%2 ? -1.0 : 1.0) * delta_max * 10 *
sqrt ( - log ( NOMAD::DEFAULT_EPSILON +
( i + NOMAD::RNG::rand()/NOMAD::D_INT_MAX ) * w ) );
}
}
// rounding:
if ( rounding )
v = v.round();
// projection to mesh (with ref=0):
v.project_to_mesh ( 0.0 , delta , lb , ub );
// affectation + permutation:
x[rp.pickup()] = v;
}
}
示例3: if
/*-----------------------------------*/
NOMAD::TGP_Output_Model::TGP_Output_Model
( const std::list<const NOMAD::Eval_Point *> & X_pts ,
int bbo_index ,
int seed ,
const NOMAD::Display & out )
: _out ( out ) ,
_p ( X_pts.size() ) ,
_Z ( new double[_p] ) ,
_Z_is_scaled ( false ) ,
_is_binary ( true ) ,
_bin_values ( 2 ) ,
_is_fixed ( false ) ,
_tgp_state ( NULL ) ,
_tgp_model ( NULL ) ,
_tgp_its ( NULL )
{
NOMAD::TGP_Output_Model::_force_quit = false;
_Z_scaling[0] = _Z_scaling[1] = 0.0;
std::list<const NOMAD::Eval_Point *>::const_iterator it , end = X_pts.end();
NOMAD::Double tmp , Zmin , Zmax , Zsum = 0.0;
int j = 0;
for ( it = X_pts.begin() ; it != end ; ++it ) {
// the output value:
tmp = (*it)->get_bb_outputs()[bbo_index];
_Z[j++] = tmp.value();
// Z scaling parameters (1/2):
Zsum += tmp;
if ( !Zmin.is_defined() || tmp < Zmin )
Zmin = tmp;
if ( !Zmax.is_defined() || tmp > Zmax )
Zmax = tmp;
// check if the output is binary:
if ( _is_binary ) {
if ( !_bin_values[0].is_defined() )
_bin_values[0] = tmp;
else if ( !_bin_values[1].is_defined() && tmp != _bin_values[0] )
_bin_values[1] = tmp;
else {
if ( tmp != _bin_values[0] && tmp != _bin_values[1] )
_is_binary = false;
}
}
}
// Z scaling parameters (1/2):
_Z_scaling[0] = (Zmax - Zmin).value();
// the output is fixed:
if ( _Z_scaling[0] == 0.0 )
_is_fixed = true;
else {
_Z_scaling[1] = (Zsum/_p).value() / _Z_scaling[0];
if ( !_is_binary )
_bin_values = NOMAD::Point(2);
// RNG (random number generator):
int state[] = { 896 , 265 , 371 };
// if seed==0, the model will be the same as the one constructed in R,
// with values taken from the R tgp functions for:
// set.seed(0)
// state <- sample(seq(0, 999), 3)
// otherwise use rand() to get three different integers in [0;999]:
if ( seed != 0 ) {
state[0] = NOMAD::RNG::rand()%1000;
while ( state[1] == state[0] )
state[1] = NOMAD::RNG::rand()%1000;
while ( state[2] == state[0] || state[2] == state[1] )
state[2] = NOMAD::RNG::rand()%1000;
}
_tgp_state = newRNGstate ( three2lstate ( state ) );
// importance tempering:
_tgp_its = new Temper ( NOMAD::TGP_Output_Model::_ditemps );
}
}
示例4: get_update_basis
/**
\return A double with the update basis tau.
*/
double get_update_basis ( void ) const { return _update_basis.value(); }
示例5: Exception
//.........这里部分代码省略.........
nbbok = _bb_nbo[k];
ibbo=0;
for ( j = 0 ; j < nbbok ; ++j )
{
fin >> s;
if ( fin.fail() )
{
failed = true;
break;
}
toupper(s);
if (s.compare("REJECT")==0)
{
*it_count=false; // Rejected points are not counted
(*it)->set_eval_status(NOMAD::EVAL_USER_REJECT);
break;
}
else
{
d.atof(s);
(*it_count)=true;
}
//
if (s.compare("FAIL")==0)
{
failed = true;
break;
}
if ( !d.is_defined() )
{
is_defined = false;
break;
}
if ( d.value() >= NOMAD::INF ) {
is_inf = true;
break;
}
(*it)->set_bb_output ( ibbo++ , d );
}
// the evaluation failed:
if ( failed || !is_defined || is_inf )
{
(*it)->set_eval_status ( NOMAD::EVAL_FAIL );
} else
list_all_failed_eval=false;
// stop the evaluations if h > h_max or if a 'EB' constraint is violated:
if ( !( k < _bb_exe.size() - 1 && interrupt_evaluations ( *(*it) , h_max ) && list_all_interrupt ))
list_all_interrupt=false;
}
fin.close();
if (list_all_failed_eval || list_all_interrupt)
break;
}
}
// delete the blackbox input and output files:
// -------------------------------------------
remove ( bb_input_file_name.c_str () );
remove ( bb_output_file_name.c_str() );
bool at_least_one_eval_ok=false;
int index_cnt_eval = _p.get_index_cnt_eval();
// update eval status and check that at least one was ok
it_count=list_count_eval.begin();
for (it=it_begin;it!=it_end;++it,++it_count)
{
if ( (*it)->get_eval_status() == NOMAD::EVAL_IN_PROGRESS )
(*it)->set_eval_status ( NOMAD::EVAL_OK );
if (!at_least_one_eval_ok && (*it)->is_eval_ok())
at_least_one_eval_ok=true;
// count_eval from bb_outputs:
// --------------------------
if ( index_cnt_eval >= 0 && (*it)->get_bb_outputs()[index_cnt_eval]==0)
*it_count=false;
}
return at_least_one_eval_ok;
}