示例#1
0
/*--------------------------------------------------*/
void NOMAD::Eval_Point::display(const NOMAD::Display &out , bool in_block) const
{
    if (in_block)
    {

        std::ostringstream oss;
        oss << "#" << _tag;
        out << NOMAD::open_block(oss.str())
            << "x    = ( ";
        NOMAD::Point::display(out , " " , 2  , NOMAD::Point::get_display_limit());
        out << " )" << std::endl
            << "F(x) = [ ";
        _bb_outputs.display(out , " " , 2 , NOMAD::Point::get_display_limit());
        out << " ]" << std::endl;
        if (_h.is_defined())
            out << "h    = " << _h << std::endl;
        if (_f.is_defined())
            out << "f    = " << _f << std::endl;
        out.close_block();
    }
    else
    {
        display_tag(out);
        out << " x=( ";
        NOMAD::Point::display(out , " " , 2  , NOMAD::Point::get_display_limit());
        out << " ) F(x)=[ ";
        _bb_outputs.display(out , " " , 2 , NOMAD::Point::get_display_limit());
        out << " ]";
        if (_h.is_defined())
            out << " h=" << _h;
        if (_f.is_defined())
            out << " f=" << _f;
    }
}
示例#2
0
/*---------------------------------------------------------*/
void NOMAD::Cache::display ( const NOMAD::Display & out ) const
{
    out << "number of cache points: " << size() << std::endl
    << "size in memory        : ";
    out.display_size_of ( _sizeof );
    out << std::endl << "cache file            : ";
    if ( _locked_file.empty() )
        out << "-" << std::endl;
    else
        out << _locked_file << std::endl;
    
#ifdef DEBUG
    int  nb = size();
    int cnt = 0;
    out << NOMAD::open_block ( "cache points" ) << std::endl;
    const NOMAD::Eval_Point * cur = begin();
    while ( cur ) {
        out << "point ";
        out.display_int_w ( ++cnt , nb );
        out << "/" << nb << ": ";
        cur->display_eval ( out , false );
        out << std::endl;
        cur = next();
    }
    out.close_block();
    
    // this display is repeated here as there can
    // be a lot of points displayed just before:
    out << "number of cache points: " << size() << std::endl
    << "size in memory        : ";
    out.display_size_of ( _sizeof );
    out << std::endl << "cache file            : ";
    if ( _locked_file.empty() )
        out << "-";
    else
        out << _locked_file;
    out << std::endl;
#endif
}
示例#3
0
/*-------------------------------------------------------*/
void NOMAD::TGP_Model::display_X_errors(const NOMAD::Display &out)
{
    if (_p == 0 || !_X)
    {
        out << "no interpolation points" << std::endl;
        return;
    }

    int               i , j , m = _bbot.size();
    NOMAD::Point      min_err(m) , max_err(m) , avg_err(m,0.0) , sd_err(m,0.0);
    NOMAD::Eval_Point x(_n , m);
    double          **err = new double * [_p];

    for (i = 0 ; i < _p ; ++i)
    {

        err[i] = new double[m];

        for (j = 0 ; j < _n ; ++j)
            x[j] = _X[i][j];

        if (predict(x , true))
        {

            for (j = 0 ; j < m ; ++j)
                if (_tgp_models[j])
                {

                    // relative error (in %) for point #i and output #j:
                    err[i][j] = (x.get_bb_outputs()[j].rel_err((_tgp_models[j]->get_Z())[i])
                                 * 100.0).value();

                    // out << "f=" << (_tgp_models[j]->get_Z())[i] << " "
                    //     << "m=" << x.get_bb_outputs()[j] << " err=" << err[i][j]
                    //     << std::endl;

                    if (!min_err[j].is_defined() || err[i][j] < min_err[j].value())
                        min_err[j] = err[i][j];

                    if (!max_err[j].is_defined() || err[i][j] > max_err[j].value())
                        max_err[j] = err[i][j];

                    avg_err[j] += err[i][j];
                }
        }
        else
        {
            for (j = 0 ; j <= i ; ++j)
                delete [] err[j];
            delete [] err;
            out << "cannot predict interpolation errors ("
                << _error_str << ")" << std::endl;
            return;
        }
    }

    for (j = 0 ; j < m ; ++j)
        if (_tgp_models[j])
        {

            // compute the median error:
            NOMAD::Double med_err;
            {
                if (_p == 1)
                    med_err = err[0][j];
                else if (_p == 2)
                    med_err = (err[0][j] + err[1][j]) / 2.0;

                else
                {
                    std::multiset<double> sorted_errors;
                    for (i = 0 ; i < _p ; ++i)
                        sorted_errors.insert(err[i][j]);
                    std::multiset<double>::const_iterator it , end = sorted_errors.end();
                    --end;
                    for (it = sorted_errors.begin() , i = 0 ; it != end ; ++it , ++i)
                    {
                        if (i == (_p+1)/2-1)
                        {
                            med_err = *it;
                            if (_p%2==0)
                            {
                                ++it;
                                med_err = (med_err + *it) / 2.0;
                            }
                            break;
                        }
                    }
                }
            }

            // compute the mean and the standard deviation:
            avg_err[j] /= _p;
            for (i = 0 ; i < _p ; ++i)
                sd_err[j] += (avg_err[j] - err[i][j]).pow2();
            sd_err[j] = (sd_err[j] / _p).sqrt();

            // display:
            if (m > 1)
            {
                std::ostringstream oss;
                oss << "output #" << j;
                if (_tgp_models[j]->is_fixed())
                    oss << " (fixed)";
                else if (_tgp_models[j]->is_binary())
                    oss << " (binary)";
                out << NOMAD::open_block(oss.str());
            }

            out << "min   : ";
            min_err[j].display(out , "%6.2f");
            out << std::endl << "max   : ";
            max_err[j].display(out , "%6.2f");
            out << std::endl << "median: ";
            med_err.display(out , "%6.2f");
            out << std::endl << "mean  : ";
            avg_err[j].display(out , "%6.2f");
            out << std::endl << "sd    : ";
            sd_err[j].display(out , "%6.2f");
            out << std::endl;

            if (m > 1)
                out.close_block();
        }

    for (i = 0 ; i < _p ; ++i)
        delete [] err[i];
    delete [] err;
}
示例#4
0
/*--------------------------------------------*/
void NOMAD::TGP_Model::display(const NOMAD::Display &out) const
{
    if (!_error_str.empty())
    {
        out << "error with model" << std::endl;
        return;
    }

    int i , j;

    // fixed variables:
    out << "fixed_var = [ " << _fv << "]" << std::endl;
    out << "av_index  = ";
    if (_av_index)
    {
        out << "[ ";
        for (i = 0 ; i < _n0 ; ++i)
            out << _av_index[i] << " ";
        out << "]" << std::endl;
    }
    else
        out << "NULL" << std::endl;
    out << "fv_index  = ";
    if (_fv_index)
    {
        out << "[ ";
        for (i = 0 ; i < _n ; ++i)
            out << _fv_index[i] << " ";
        out << "]" << std::endl;
    }
    else
        out << "NULL" << std::endl;

    // bounds:
    out << "lb        = [ " << _lb << "]" << std::endl
        << "ub        = [ " << _ub << "]" << std::endl
        << std::endl;

    // display X:
    if (!_X)
        out << "X = NULL" << std::endl;
    else
    {
        out << "X = [";
        for (i = 0 ; i < _p ; ++i)
        {
            out << "\t";
            for (j = 0 ; j < _n ; ++j)
                out << std::setw(15) << _X[i][j] << " ";
            out << ((i==_p-1) ? "]" : ";") << std::endl;
        }
        out << "size(X)=" << _p << "x" << _n << std::endl << std::endl;
    }

    // display XX:
    if (!_XX)
        out << "XX = NULL" << std::endl;
    else
    {
        out << "XX = [";
        for (i = 0 ; i < _n_XX ; ++i)
        {
            out << "\t";
            for (j = 0 ; j < _n ; ++j)
                out << std::setw(15) << _XX[i][j] << " ";
            out << ((i==_n_XX-1) ? "]" : ";") << std::endl;
        }
        out << "size(XX)=" << _n_XX << "x" << _n << std::endl << std::endl;
    }

    // display models:
    out << std::endl;
    if (_tgp_models)
    {
        int m = _bbot.size();
        for (i = 0 ; i < m ; ++i)
        {
            if (_tgp_models[i])
            {
                std::ostringstream oss;
                oss << "model #" << i;
                out.open_block(oss.str());
                _tgp_models[i]->display(out);
                out.close_block();
            }
            else
                out << "model #" << i << ": NULL" << std::endl;
            out << std::endl;
        }
    }
    else
        out << "no models" << std::endl << std::endl;
}
示例#5
0
/*----------------------------------------------------------------*/
void NOMAD::TGP_Model::display_Ds2x(const NOMAD::Display &out ,
                                    int          display_limit) const
{
    if (!_Ds2x || _n_XX == 0)
    {
        out << "matrix Ds2x has not been computed" << std::endl;
        return;
    }

    int            i , j , k , m = _bbot.size();
    NOMAD::Point *XX_pt;
    std::multiset<NOMAD::Model_Sorted_Point> pts;
    std::multiset<NOMAD::Model_Sorted_Point>::const_iterator it , end;

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

        if (m > 1)
        {
            std::ostringstream oss;
            oss << "output #" << i;
            out << NOMAD::open_block(oss.str());
        }

        if (_Ds2x[i])
        {

            // 1. sort:
            for (j = 0 ; j < _n_XX ; ++j)
            {

                // construct a NOMAD::Point from matrix _XX:
                XX_pt = new NOMAD::Point(_fv);
                for (k = 0 ; k < _n0 ; ++k)
                    if (_av_index[k] >= 0)
                        (*XX_pt)[k] = _XX[j][_av_index[k]];

                // insert this point in the sorted list:
                pts.insert(NOMAD::Model_Sorted_Point(XX_pt , -_Ds2x[i][j]));
            }

            // 2. display:
            end = pts.end();
            for (j = 0 , it = pts.begin() ; it != end ; ++it , ++j)
            {

                if (display_limit <= 0 || j < display_limit)
                {
                    out << "x=( ";
                    it->get_point()->display(out , " " , 6 , -1);
                    out << " ) Ds2x=" << it->get_dist()*-1.0 << std::endl;
                }

                else if (j == display_limit)
                    out << "..." << std::endl;

                delete it->get_point();
            }

            pts.clear();
        }
        else
            out << "NULL" << std::endl;

        if (m > 1)
            out.close_block();
    }
}