Skip to content

Commit

Permalink
moved convenience function set_str_algo from parameters to cmaparamet…
Browse files Browse the repository at this point in the history
…ers in order to set 'sep' flag while setting the algorithm
  • Loading branch information
Emmanuel Benazera committed Oct 8, 2014
1 parent 31d5e3c commit 5c83a39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
17 changes: 17 additions & 0 deletions src/cmaparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ namespace libcmaes
*/
void set_noisy();

/**
* \brief sets the optimization algorithm.
* @param algo as string from cmaes,ipop,bipop,acmaes,aipop,abipop,sepcmaes,sepipop,sepbipop,sepacmaes,sepaipop,sepabipop
*/
void set_str_algo(const std::string &algo)
{
std::map<std::string,int>::const_iterator mit;
if ((mit = Parameters<TGenoPheno>::_algos.find(algo))!=Parameters<TGenoPheno>::_algos.end())
Parameters<TGenoPheno>::_algo = (*mit).second;
if (algo.find("sep")!=std::string::npos)
_sep = true;
else LOG(ERROR) << "unknown algorithm " << algo << std::endl;
}

/**
* \brief fix parameters for sep-CMA-ES, using only the diagonal of covariance matrix.
*/
Expand Down Expand Up @@ -197,6 +211,9 @@ namespace libcmaes
// stopping criteria.
bool _has_max_iter = true; /**< MaxIter criteria: automatically stop running after 100+50*((D+2)^2)/lambda iterations. */
};

template<class TGenoPheno>
std::map<std::string,int> Parameters<TGenoPheno>::_algos = {{"cmaes",0},{"ipop",1},{"bipop",2},{"acmaes",3},{"aipop",4},{"abipop",5},{"sepcmaes",6},{"sepipop",7},{"sepbipop",8},{"sepacmaes",9},{"sepipop",10},{"sepbipop",11}};
}

#endif
16 changes: 0 additions & 16 deletions src/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,6 @@ namespace libcmaes
_algo = algo;
}

/**
* \brief sets the optimization algorithm.
* @param algo as string from cmaes,ipop,bipop,acmaes,aipop,abipop,sepcmaes,sepipop,sepbipop,sepacmaes,sepaipop,sepabipop
*/
void set_str_algo(const std::string &algo)
{
std::map<std::string,int>::const_iterator mit;
if ((mit = Parameters<TGenoPheno>::_algos.find(algo))!=Parameters<TGenoPheno>::_algos.end())
_algo = (*mit).second;
else LOG(ERROR) << "unknown algorithm " << algo << std::endl;
}

/**
* \brief returns which algorithm is set for the optimization at hand.
* @return algorithm integer code
Expand Down Expand Up @@ -514,10 +502,6 @@ namespace libcmaes

static std::map<std::string,int> _algos; /**< of the form { {"cmaes",0}, {"ipop",1}, ...} */;
};

template<class TGenoPheno>
std::map<std::string,int> Parameters<TGenoPheno>::_algos = {{"cmaes",0},{"ipop",1},{"bipop",2},{"acmaes",3},{"aipop",4},{"abipop",5},{"sepcmaes",6},{"sepipop",7},{"sepbipop",8},{"sepacmaes",9},{"sepipop",10},{"sepbipop",11}};

}

#endif

0 comments on commit 5c83a39

Please sign in to comment.