Пример #1
0
				bool eval_x ( NOMAD::Eval_Point   & x          ,
								const NOMAD::Double & h_max      ,
								bool                & count_eval   ) const {

						R_CheckUserInterrupt();

						double *x0;
						int n = x.get_n();
						int m = x.get_m();
						x0 = (double *)malloc(sizeof(double)*n);
						for(int i=0;i<n;i++)
						{
								x0[i]=x[i].value();
						}


						double *ret_value = eval_f(m, n, x0);
						for(int i=0;i<m;i++)
								x.set_bb_output  ( i , ret_value[i]  ); // objective value

						count_eval = true; // count a black-box evaluation

						free(x0);
						free(ret_value);

						return true;       // the evaluation succeeded
				}
Пример #2
0
/*--------------------------------------------*/
bool NOMAD::TGP_Model::predict(NOMAD::Eval_Point &x , bool pred_outside_bnds)
{
    if (!_error_str.empty())
        return false;

    if (!_model_computed)
    {
        _error_str = "NOMAD::TGP_Model::compute() has not been called";
        return false;
    }

    int i , i0 , ix , m = x.get_m() , nx = x.size();

    // reset point outputs:
    x.set_eval_status(NOMAD::EVAL_FAIL);
    for (i = 0 ; i < m ; ++i)
        x.set_bb_output(i , NOMAD::Double());

    // check dimensions:
    if (m != static_cast<int>(_bbot.size()) ||
        (nx != _n0 && nx != _n))
    {
        _error_str = "predict error: bad x dimensions";
        return false;
    }

    double ZZ , * XX = new double[_n];

    // set the coordinates and check the bounds:
    for (i = 0 ; i < _n ; ++i)
    {

        ix = (nx == _n0) ? _fv_index[i] : i;

        if (!pred_outside_bnds)
        {
            i0 = _fv_index[i];
            if (x[ix] < _lb[i0] || x[ix] > _ub[i0])
            {
                delete [] XX;
                return false; // this is not an error
            }
        }

        XX[i] = x[ix].value();
    }

    // predictions (one for each output):
    for (i = 0 ; i < m ; ++i)
        if (_tgp_models[i])
        {
            if (!_tgp_models[i]->predict(XX        ,
                                         _n        ,
                                         ZZ        ,
                                         _tgp_rect))
            {
                std::ostringstream oss;
                oss << "predict error: problem with model #" << i;
                _error_str = oss.str();
                break;
            }
            x.set_bb_output(i , ZZ);
        }

    delete [] XX;

    if (!_error_str.empty())
    {
        x.set_eval_status(NOMAD::EVAL_FAIL);
        return false;
    }

    x.set_eval_status(NOMAD::EVAL_OK);
    return true;
}