Skip to content

Commit

Permalink
fixed standard deviation and error estimates when scaling is enabled,…
Browse files Browse the repository at this point in the history
… ref #129
  • Loading branch information
Emmanuel Benazera committed Mar 16, 2015
1 parent 994a203 commit a90e91c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/cmasolutions.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,16 @@ namespace libcmaes
template<class TGenoPheno=GenoPheno<NoBoundStrategy>>
inline dVec stds(const CMAParameters<TGenoPheno> &cmaparams) const
{
dVec phen_xmean = cmaparams.get_gp().pheno(_xmean);
dVec stds;
if (!cmaparams.is_sep() && !cmaparams.is_vd())
return cmaparams.get_gp().pheno(static_cast<dVec>(_cov.diagonal().cwiseSqrt()));
stds = _cov.diagonal().cwiseSqrt();
else if (cmaparams.is_sep())
return cmaparams.get_gp().pheno(static_cast<dVec>(_sepcov.cwiseSqrt()));
stds = _sepcov.cwiseSqrt();
else if (cmaparams.is_vd())
return cmaparams.get_gp().pheno(static_cast<dVec>((dVec::Constant(cmaparams.dim(),1.0)+_v.cwiseProduct(_v)).cwiseSqrt().cwiseProduct(_sepcov)));
return dVec(); // should never reach here.
stds = (dVec::Constant(cmaparams.dim(),1.0)+_v.cwiseProduct(_v)).cwiseSqrt().cwiseProduct(_sepcov);
dVec phen_xmean_std = cmaparams.get_gp().pheno(static_cast<dVec>(_xmean + stds));
return (phen_xmean_std - phen_xmean).cwiseAbs();
}

/**
Expand All @@ -311,13 +314,7 @@ namespace libcmaes
template<class TGenoPheno=GenoPheno<NoBoundStrategy>>
inline dVec errors(const CMAParameters<TGenoPheno> &cmaparams) const
{
if (!cmaparams.is_sep() && !cmaparams.is_vd())
return cmaparams.get_gp().pheno(static_cast<dVec>(std::sqrt(_sigma)*_cov.diagonal().cwiseSqrt()));
else if (cmaparams.is_sep())
return cmaparams.get_gp().pheno(static_cast<dVec>(std::sqrt(_sigma)*_sepcov.cwiseSqrt()));
else if (cmaparams.is_vd())
return cmaparams.get_gp().pheno(static_cast<dVec>(std::sqrt(_sigma)*(dVec::Constant(cmaparams.dim(),1.0)+_v.cwiseProduct(_v)).cwiseSqrt().cwiseProduct(_sepcov)));
return dVec(); // should never reach here.
return std::sqrt(_sigma)*stds(cmaparams);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/test-functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ DEFINE_bool(with_gradient,false,"whether to use the function gradient when avail
DEFINE_bool(with_num_gradient,false,"whether to use numerical gradient injection");
DEFINE_bool(with_edm,false,"whether to compute expected distance to minimum when optimization has completed");
DEFINE_bool(with_stds,false,"whether to compute and print the standard deviation for every parameter");
DEFINE_bool(with_errors,false,"whether to compute the errors");
DEFINE_bool(with_corr,false,"whether to compute and print the correlation matrix (may not fit in memory in large-scale settings)");
DEFINE_bool(mt,false,"whether to use parallel evaluation of objective function");
DEFINE_bool(initial_fvalue,false,"whether to compute initial objective function value at x0");
Expand Down Expand Up @@ -632,6 +633,8 @@ CMASolutions cmaes_opt()
LOG(INFO) << "EDM=" << cmasols.edm() << " / EDM/fm=" << cmasols.edm() / cmasols.best_candidate().get_fvalue() << std::endl;
if (FLAGS_with_stds)
std::cout << "stds=" << cmasols.stds(cmaparams).transpose() << std::endl;
if (FLAGS_with_errors)
std::cout << "errors=" << cmasols.errors(cmaparams).transpose() << std::endl;
if (FLAGS_with_corr)
std::cout << "correlation=" << cmasols.corr() << std::endl;
return cmasols;
Expand Down

0 comments on commit a90e91c

Please sign in to comment.