[shark] 29/58: changed interface once again. working
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 81df3230d6bc07fae594f5c5289b32946fff1675
Author: Oswin Krause <oswin.krause at di.ku.dk>
Date: Fri Jan 15 11:11:05 2016 +0100
changed interface once again. working
---
Test/Algorithms/DirectSearch/CMA.cpp | 10 ++++----
include/shark/Algorithms/DirectSearch/CMA.h | 37 +++--------------------------
src/Algorithms/DirectSearch/CMA.cpp | 16 ++++++-------
3 files changed, 17 insertions(+), 46 deletions(-)
diff --git a/Test/Algorithms/DirectSearch/CMA.cpp b/Test/Algorithms/DirectSearch/CMA.cpp
index 40f41a7..d7e3098 100644
--- a/Test/Algorithms/DirectSearch/CMA.cpp
+++ b/Test/Algorithms/DirectSearch/CMA.cpp
@@ -60,8 +60,9 @@ BOOST_AUTO_TEST_CASE( CMA__Ellipsoid_Niko )
Ellipsoid elli(N, 1E6);
CMA cma;
- cma.init(elli, x0);
- cma.setSigma(0.1);
+ std::size_t lambda = CMA::suggestLambda(N);
+ cma.init(elli, x0,lambda,CMA::suggestMu(lambda),0.1);
+ BOOST_REQUIRE(cma.sigma() == 0.1);
for(unsigned i=0; i<6000; i++) cma.step( elli );
BOOST_CHECK(cma.solution().value < 1E-8);
@@ -75,8 +76,9 @@ BOOST_AUTO_TEST_CASE( CMA_Sphere_Niko )
Sphere sphere(N);
CMA cma;
- cma.init(sphere, x0);
- cma.setSigma(1e-4);
+ std::size_t lambda = CMA::suggestLambda(N);
+ cma.init(sphere, x0,lambda,CMA::suggestMu(lambda),1.e-4);
+ BOOST_REQUIRE(cma.sigma() == 1.e-4);
bool sigmaHigh = false;
bool condHigh = false;
diff --git a/include/shark/Algorithms/DirectSearch/CMA.h b/include/shark/Algorithms/DirectSearch/CMA.h
index 9f20c42..f7c9881 100644
--- a/include/shark/Algorithms/DirectSearch/CMA.h
+++ b/include/shark/Algorithms/DirectSearch/CMA.h
@@ -132,16 +132,6 @@ public:
return m_sigma;
}
- /** \brief Accesses the current step size. */
- void setSigma(double sigma) {
- m_sigma = sigma;
- }
-
- void setInitSigma(double initSigma){
- m_initSigma =initSigma;
- }
-
-
/** \brief Accesses the current population mean. */
RealVector const& mean() const {
return m_mean;
@@ -189,13 +179,6 @@ public:
}
/**
- * \brief Returns a mutable reference to the lower bound on sigma times smalles eigenvalue.
- */
- double& lowerBound() {
- return m_lowerBound;
- }
-
- /**
* \brief Returns the size of the parent population \f$\mu\f$.
*/
std::size_t mu() const {
@@ -203,13 +186,6 @@ public:
}
/**
- * \brief Returns a mutabl rference to the size of the parent population \f$\mu\f$.
- */
- std::size_t& mu(){
- return m_mu;
- }
-
- /**
* \brief Returns a immutable reference to the size of the offspring population \f$\mu\f$.
*/
std::size_t lambda()const{
@@ -217,13 +193,6 @@ public:
}
/**
- * \brief Returns a mutable reference to the size of the offspring population \f$\mu\f$.
- */
- std::size_t & lambda(){
- return m_lambda;
- }
-
- /**
* \brief Returns eigenvectors of covariance matrix (not considering step size)
*/
RealMatrix const& eigenVectors() const {
@@ -259,9 +228,10 @@ protected:
SHARK_EXPORT_SYMBOL void doInit(
AbstractConstraintHandler<SearchPointType> const* handler,
std::vector<SearchPointType> const& points,
- std::vector<ResultType> const&,
+ std::vector<ResultType> const& functionValues,
+ std::size_t mu,
std::size_t lambda,
- std::size_t mu
+ double initialSigma
);
private:
@@ -271,7 +241,6 @@ private:
RecombinationType m_recombinationType; ///< Stores the recombination type.
- double m_initSigma;
double m_sigma;
double m_cC;
double m_c1;
diff --git a/src/Algorithms/DirectSearch/CMA.cpp b/src/Algorithms/DirectSearch/CMA.cpp
index 26f24a2..e81ef78 100644
--- a/src/Algorithms/DirectSearch/CMA.cpp
+++ b/src/Algorithms/DirectSearch/CMA.cpp
@@ -91,7 +91,6 @@ std::size_t CMA::suggestMu( std::size_t lambda, RecombinationType recomb) {
CMA::CMA()
:m_recombinationType( SUPERLINEAR )
-, m_initSigma( 0 )
, m_sigma( 0 )
, m_cC( 0 )
, m_c1( 0 )
@@ -166,17 +165,17 @@ void CMA::init( ObjectiveFunctionType & function, SearchPointType const& p) {
function.init();
std::vector<RealVector> points(1,p);
std::vector<double> functionValues(1,function.eval(p));
- std::size_t lambda = CMA::suggestLambda( p.size() );
- std::size_t mu = CMA::suggestMu(lambda, m_recombinationType);
AbstractConstraintHandler<SearchPointType> const* handler = 0;
if (function.hasConstraintHandler())
handler = &function.getConstraintHandler();
+ std::size_t lambda = CMA::suggestLambda( p.size() );
doInit(
handler,
points,
functionValues,
lambda,
- mu
+ CMA::suggestMu(lambda, m_recombinationType),
+ 1.0/std::sqrt(double(m_numberOfVariables))
);
}
@@ -196,7 +195,6 @@ void CMA::init(
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();
@@ -205,7 +203,8 @@ void CMA::init(
points,
functionValues,
lambda,
- mu
+ mu,
+ initialSigma
);
if(initialCovarianceMatrix){
m_mutationDistribution.covarianceMatrix() = *initialCovarianceMatrix;
@@ -217,12 +216,13 @@ void CMA::doInit(
std::vector<SearchPointType> const& initialSearchPoints,
std::vector<ResultType> const& initialValues,
std::size_t lambda,
- std::size_t mu
+ std::size_t mu,
+ double initialSigma
) {
m_numberOfVariables =initialSearchPoints[0].size();
m_lambda = lambda;
m_mu = mu;
- m_sigma = (m_initSigma == 0)? 1.0/std::sqrt(double(m_numberOfVariables)): m_initSigma;
+ m_sigma = initialSigma;
m_mean.resize( m_numberOfVariables );
m_evolutionPathC.resize( m_numberOfVariables );
--
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