[shark] 32/58: fixed small bugs
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Mar 16 10:05:31 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository shark.
commit ea51413b3e7b49bcb815b62fc9c13ddacf208f06
Author: Oswin <oswin.krause at di.ku.dk>
Date: Thu Feb 4 17:08:52 2016 +0100
fixed small bugs
---
include/shark/Algorithms/DirectSearch/CMSA.h | 36 ++++++++++++++++++----------
src/Algorithms/DirectSearch/CMA.cpp | 2 +-
src/Algorithms/DirectSearch/CMSA.cpp | 29 +++++++++-------------
3 files changed, 35 insertions(+), 32 deletions(-)
diff --git a/include/shark/Algorithms/DirectSearch/CMSA.h b/include/shark/Algorithms/DirectSearch/CMSA.h
index 7c579ff..60ccf8d 100644
--- a/include/shark/Algorithms/DirectSearch/CMSA.h
+++ b/include/shark/Algorithms/DirectSearch/CMSA.h
@@ -72,7 +72,7 @@ class CMSA : public AbstractSingleObjectiveOptimizer<RealVector > {
public:
/// \brief Default c'tor.
- CMSA() : m_mu( 100 ), m_lambda( 200 ) {
+ CMSA() : m_mu( 100 ), m_lambda( 200 ), m_userSetMu(false),m_userSetLambda(false), m_initSigma(-1) {
m_features |= REQUIRES_VALUE;
}
@@ -114,26 +114,33 @@ public:
/// \brief Executes one iteration of the algorithm.
SHARK_EXPORT_SYMBOL void step(ObjectiveFunctionType const& function);
+
+ /// \brief sets the initial step length sigma
+ ///
+ /// It is by default <=0 which means that sigma =1/sqrt(numVariables)
+ void setInitialSigma(double initSigma){
+ m_initSigma = initSigma;
+ }
+ /// \brief Sets the number of selected samples
+ void setMu(std::size_t mu){
+ m_mu = mu;
+ m_userSetMu = true;
+ }
+ /// \brief Sets the number of sampled points
+ void setLambda(std::size_t lambda){
+ m_lambda = lambda;
+ m_userSetLambda = true;
+ }
/// \brief Accesses the size of the parent population.
std::size_t mu() const {
return m_mu;
}
- /// \brief Accesses the size of the parent population, allows for l-value semantics.
- std::size_t & mu() {
- return m_mu;
- }
-
/// \brief Accesses the size of the offspring population.
std::size_t lambda() const {
return m_lambda;
}
-
- /// \brief Accesses the size of the offspring population, allows for l-value semantics.
- std::size_t & lambda() {
- return m_lambda;
- }
protected:
/// \brief The type of individual used by the CMSA
typedef Individual< RealVector, double, LightChromosome > IndividualType;
@@ -146,18 +153,21 @@ protected:
/// \brief Initializes the internal data structures of the CMSA
SHARK_EXPORT_SYMBOL void doInit(
- AbstractConstraintHandler<SearchPointType> const* handler,
std::vector<SearchPointType> const& points,
std::vector<ResultType> const& functionValues,
std::size_t lambda,
- std::size_t mu
+ std::size_t mu,
+ double initialSigma
);
private:
std::size_t m_numberOfVariables; ///< Stores the dimensionality of the search space.
std::size_t m_mu; ///< The size of the parent population.
std::size_t m_lambda; ///< The size of the offspring population, needs to be larger than mu.
+ bool m_userSetMu; /// <The user set a value via setMu, do not overwrite with default
+ bool m_userSetLambda; /// <The user set a value via setMu, do not overwrite with default
double m_initSigma; ///< The initial step size
+
double m_sigma; ///< The current step size.
double m_cSigma;
double m_cC; ///< Constant for adapting the covariance matrix.
diff --git a/src/Algorithms/DirectSearch/CMA.cpp b/src/Algorithms/DirectSearch/CMA.cpp
index 1576114..b05985c 100644
--- a/src/Algorithms/DirectSearch/CMA.cpp
+++ b/src/Algorithms/DirectSearch/CMA.cpp
@@ -171,7 +171,7 @@ void CMA::init( ObjectiveFunctionType & function, SearchPointType const& p) {
std::size_t lambda = m_userSetLambda? m_lambda:CMA::suggestLambda( p.size() );
std::size_t mu = m_userSetMu? m_mu:CMA::suggestMu(lambda, m_recombinationType);
RANGE_CHECK(mu < lambda);
- double sigma = m_initSigma > 0? m_initSigma : 1.0/std::sqrt(double(m_numberOfVariables));
+ double sigma = (m_initSigma > 0)? m_initSigma : 1.0/std::sqrt(double(p.size()));
doInit(
points,
functionValues,
diff --git a/src/Algorithms/DirectSearch/CMSA.cpp b/src/Algorithms/DirectSearch/CMSA.cpp
index 9d93839..53fc6d8 100644
--- a/src/Algorithms/DirectSearch/CMSA.cpp
+++ b/src/Algorithms/DirectSearch/CMSA.cpp
@@ -63,20 +63,19 @@ namespace{
void CMSA::init( ObjectiveFunctionType & function, SearchPointType const& p) {
SIZE_CHECK(p.size() == function.numberOfVariables());
checkFeatures(function);
- function.init();
std::vector<RealVector> points(1,p);
std::vector<double> functionValues(1,function.eval(p));
- std::size_t lambda = 4 * p.size();
- std::size_t mu = lambda / 4;
- AbstractConstraintHandler<SearchPointType> const* handler = 0;
- if (function.hasConstraintHandler())
- handler = &function.getConstraintHandler();
+
+ std::size_t lambda = m_userSetLambda? m_lambda:4 * p.size();
+ std::size_t mu = m_userSetMu? m_mu:lambda / 4;
+ RANGE_CHECK(mu < lambda);
+ double sigma = (m_initSigma > 0)? m_initSigma : 1.0/std::sqrt(double(p.size()));
doInit(
- handler,
points,
functionValues,
lambda,
- mu
+ mu,
+ sigma
);
}
void CMSA::init(
@@ -87,22 +86,16 @@ void CMSA::init(
double initialSigma,
const boost::optional< RealMatrix > & initialCovarianceMatrix
) {
-
SIZE_CHECK(p.size() == function.numberOfVariables());
checkFeatures(function);
- function.init();
std::vector<RealVector> points(1,p);
std::vector<double> functionValues(1,function.eval(p));
- m_initSigma = initialSigma;
- AbstractConstraintHandler<SearchPointType> const* handler = 0;
- if (function.hasConstraintHandler())
- handler = &function.getConstraintHandler();
doInit(
- handler,
points,
functionValues,
lambda,
- mu
+ mu,
+ initialSigma
);
if(initialCovarianceMatrix){
m_mutationDistribution.covarianceMatrix() = *initialCovarianceMatrix;
@@ -111,11 +104,11 @@ void CMSA::init(
}
void CMSA::doInit(
- AbstractConstraintHandler<SearchPointType> const* constraints,
std::vector<SearchPointType> const& initialSearchPoints,
std::vector<ResultType> const& initialValues,
std::size_t lambda,
- std::size_t mu
+ std::size_t mu,
+ double sima
) {
m_numberOfVariables = initialSearchPoints[0].size();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/shark.git
More information about the debian-science-commits
mailing list