Commit b384ae05 authored by Konstantinos Chatzilygeroudis's avatar Konstantinos Chatzilygeroudis
Browse files

A few more parameters for CMA-ES

parent 6804a9cb
...@@ -99,7 +99,7 @@ struct Params { ...@@ -99,7 +99,7 @@ struct Params {
}; };
#ifdef USE_LIBCMAES #ifdef USE_LIBCMAES
struct opt_cmaes : public defaults::opt_cmaes { struct opt_cmaes : public defaults::opt_cmaes {
BO_PARAM(double, max_fun_evals, 500); BO_PARAM(int, max_fun_evals, 500);
BO_PARAM(double, fun_tolerance, 1e-6); BO_PARAM(double, fun_tolerance, 1e-6);
BO_PARAM(double, xrel_tolerance, 1e-6); BO_PARAM(double, xrel_tolerance, 1e-6);
}; };
......
...@@ -68,7 +68,7 @@ namespace limbo { ...@@ -68,7 +68,7 @@ namespace limbo {
BO_PARAM(int, restarts, 1); BO_PARAM(int, restarts, 1);
/// @ingroup opt_defaults /// @ingroup opt_defaults
/// maximum number of calls to the function to be optimized /// maximum number of calls to the function to be optimized
BO_PARAM(double, max_fun_evals, -1); BO_PARAM(int, max_fun_evals, -1);
/// @ingroup opt_defaults /// @ingroup opt_defaults
/// threshold based on the difference in value of a fixed number /// threshold based on the difference in value of a fixed number
/// of trials: if bigger than 0, it enables the tolerance criteria /// of trials: if bigger than 0, it enables the tolerance criteria
...@@ -112,8 +112,19 @@ namespace limbo { ...@@ -112,8 +112,19 @@ namespace limbo {
/// @ingroup opt_defaults /// @ingroup opt_defaults
/// upper bound (in input) for cmaes /// upper bound (in input) for cmaes
BO_PARAM(double, ubound, 1.0); BO_PARAM(double, ubound, 1.0);
/// @ingroup opt_defaults
/// if stochastic, the mean of the
/// last distribution is returned
/// otherwise, the best ever candidate
/// is returned. If handle_uncertainty is on,
/// this is also enabled.
BO_PARAM(bool, stochastic, false);
/// @ingroup opt_defaults
/// number of parent population
/// -1 to automatically determine
BO_PARAM(int, lambda, -1);
}; };
} } // namespace defaults
namespace opt { namespace opt {
/// @ingroup opt /// @ingroup opt
...@@ -127,7 +138,7 @@ namespace limbo { ...@@ -127,7 +138,7 @@ namespace limbo {
/// - int variant /// - int variant
/// - int elitism /// - int elitism
/// - int restarts /// - int restarts
/// - double max_fun_evals /// - int max_fun_evals
/// - double fun_tolerance /// - double fun_tolerance
/// - double xrel_tolerance /// - double xrel_tolerance
/// - double fun_target /// - double fun_target
...@@ -136,6 +147,8 @@ namespace limbo { ...@@ -136,6 +147,8 @@ namespace limbo {
/// - bool verbose /// - bool verbose
/// - double lb (lower bounds) /// - double lb (lower bounds)
/// - double ub (upper bounds) /// - double ub (upper bounds)
/// - bool stochastic
/// - int lambda
template <typename Params> template <typename Params>
struct Cmaes { struct Cmaes {
public: public:
...@@ -167,11 +180,14 @@ namespace limbo { ...@@ -167,11 +180,14 @@ namespace limbo {
double sigma = 0.5; double sigma = 0.5;
std::vector<double> x0(init.data(), init.data() + init.size()); std::vector<double> x0(init.data(), init.data() + init.size());
CMAParameters<> cmaparams(x0, sigma); CMAParameters<> cmaparams(x0, sigma, Params::opt_cmaes::lambda());
_set_common_params(cmaparams, dim); _set_common_params(cmaparams, dim);
// the optimization itself // the optimization itself
CMASolutions cmasols = cmaes<>(f_cmaes, cmaparams); CMASolutions cmasols = cmaes<>(f_cmaes, cmaparams);
if (Params::opt_cmaes::stochastic() || Params::opt_cmaes::handle_uncertainty())
return cmasols.xmean();
return cmasols.get_best_seen_candidate().get_x_dvec(); return cmasols.get_best_seen_candidate().get_x_dvec();
} }
...@@ -192,13 +208,14 @@ namespace limbo { ...@@ -192,13 +208,14 @@ namespace limbo {
double sigma = 0.5 * std::abs(Params::opt_cmaes::ubound() - Params::opt_cmaes::lbound()); double sigma = 0.5 * std::abs(Params::opt_cmaes::ubound() - Params::opt_cmaes::lbound());
std::vector<double> x0(init.data(), init.data() + init.size()); std::vector<double> x0(init.data(), init.data() + init.size());
// -1 for automatically decided lambda, 0 is for random seeding of the internal generator. // -1 for automatically decided lambda, 0 is for random seeding of the internal generator.
CMAParameters<GenoPheno<pwqBoundStrategy>> cmaparams(dim, &x0.front(), sigma, -1, 0, gp); CMAParameters<GenoPheno<pwqBoundStrategy>> cmaparams(dim, &x0.front(), sigma, Params::opt_cmaes::lambda(), 0, gp);
_set_common_params(cmaparams, dim); _set_common_params(cmaparams, dim);
// the optimization itself // the optimization itself
CMASolutions cmasols = cmaes<GenoPheno<pwqBoundStrategy>>(f_cmaes, cmaparams); CMASolutions cmasols = cmaes<GenoPheno<pwqBoundStrategy>>(f_cmaes, cmaparams);
//cmasols.print(std::cout, 1, gp); if (Params::opt_cmaes::stochastic() || Params::opt_cmaes::handle_uncertainty())
//to_f_representation return gp.pheno(cmasols.xmean());
return gp.pheno(cmasols.get_best_seen_candidate().get_x_dvec()); return gp.pheno(cmasols.get_best_seen_candidate().get_x_dvec());
} }
...@@ -259,7 +276,7 @@ namespace limbo { ...@@ -259,7 +276,7 @@ namespace limbo {
cmaparams.set_quiet(!Params::opt_cmaes::verbose()); cmaparams.set_quiet(!Params::opt_cmaes::verbose());
} }
}; };
} } // namespace opt
} } // namespace limbo
#endif
#endif #endif
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment