[shark] 39/58: fixed bugs in PolynomialMutation and SimulatedBinaryCrossover by checking with Debs original code. Now NSGAII and SMS-EMOA behave reasonable
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Mar 16 10:05:32 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 5c950d25eccba2d7077a10cf86388d6f20a7b1d9
Author: Oswin <oswin.krause at di.ku.dk>
Date: Tue Feb 9 07:44:38 2016 +0100
fixed bugs in PolynomialMutation and SimulatedBinaryCrossover by checking with Debs original code. Now NSGAII and SMS-EMOA behave reasonable
---
.../Operators/Mutation/PolynomialMutation.h | 37 +++++++--------
.../Recombination/SimulatedBinaryCrossover.h | 52 +++++++++++-----------
2 files changed, 41 insertions(+), 48 deletions(-)
diff --git a/include/shark/Algorithms/DirectSearch/Operators/Mutation/PolynomialMutation.h b/include/shark/Algorithms/DirectSearch/Operators/Mutation/PolynomialMutation.h
index 8cbf1f3..051ae20 100644
--- a/include/shark/Algorithms/DirectSearch/Operators/Mutation/PolynomialMutation.h
+++ b/include/shark/Algorithms/DirectSearch/Operators/Mutation/PolynomialMutation.h
@@ -42,7 +42,7 @@ namespace shark {
struct PolynomialMutator {
/// \brief Default c'tor.
- PolynomialMutator() : m_nm( 20.0 ) {}
+ PolynomialMutator() : m_nm( 25.0 ) {}
/// \brief Initializes the operator for the supplied box-constraints
void init( RealVector const& lower, RealVector const& upper ) {
@@ -58,34 +58,29 @@ namespace shark {
/// \param [in,out] ind Individual to be mutated.
template<typename IndividualType>
void operator()( IndividualType & ind )const{
- double delta, deltaQ, expp, u = 0.;
-
RealVector& point = ind.searchPoint();
for( unsigned int i = 0; i < point.size(); i++ ) {
if( Rng::coinToss( m_prob ) ) {
- u = Rng::uni( 0., 1. );
- if( point[i] <= m_lower( i ) || point[i] >= m_upper( i ) ) {
- point[i] = u * (m_upper( i ) - m_lower( i ) ) + m_lower( i );
+ if( point[i] < m_lower( i ) || point[i] > m_upper( i ) ) {
+ point[i] = Rng::uni(m_lower(i),m_upper(i));
} else {
- // Calculate delta
- if( (point[i] - m_lower( i ) ) < (m_upper( i ) - point[i]) )
- delta = (point[i] - m_lower( i ) ) / (m_upper( i ) - m_lower( i ) );
- else
- delta = (m_upper( i ) - point[i]) / (m_upper( i ) - m_lower( i ));
-
- delta = 1. - delta;
- expp = (m_nm + 1.);
- delta = ::pow(delta , expp);
- expp = 1. / expp;
-
+ // Calculate normalized distance from boundaries
+ double delta1 = (m_upper( i ) - point[i]) / (m_upper( i ) - m_lower( i ));
+ double delta2 = (point[i] - m_lower( i ) ) / (m_upper( i ) - m_lower( i ));
+
+ //compute change in delta
+ double deltaQ=0;
+ double u = Rng::uni(0,1);
if( u <= .5 ) {
- deltaQ = 2. * u + (1 - 2. * u) * delta;
- deltaQ = ::pow(deltaQ, expp) - 1. ;
+ double delta = std::pow(delta1 , m_nm + 1.);
+ deltaQ = 2.0 * u + (1.0 - 2.0 * u) * delta;
+ deltaQ = std::pow(deltaQ, 1.0/(m_nm+1.0)) - 1. ;
} else {
- deltaQ = 2. - 2. * u + 2. * (u - .5) * delta;
- deltaQ = 1. - ::pow(deltaQ , expp);
+ double delta = std::pow(delta2 , m_nm + 1.);
+ deltaQ = 2 * (1- u) + 2. * (u - .5) * delta;
+ deltaQ = 1. - std::pow(deltaQ , 1.0/(m_nm+1.0));
}
point[i] += deltaQ * (m_upper( i ) - m_lower( i ) );
diff --git a/include/shark/Algorithms/DirectSearch/Operators/Recombination/SimulatedBinaryCrossover.h b/include/shark/Algorithms/DirectSearch/Operators/Recombination/SimulatedBinaryCrossover.h
index f659a3e..befd3b0 100644
--- a/include/shark/Algorithms/DirectSearch/Operators/Recombination/SimulatedBinaryCrossover.h
+++ b/include/shark/Algorithms/DirectSearch/Operators/Recombination/SimulatedBinaryCrossover.h
@@ -77,35 +77,33 @@ namespace shark {
y2 = point2[i];
}
- double betaQ = 0.0;
- if( std::abs(y2 - y1) > 1E-7 ) {
- // Find beta value
- double beta = 0;
- if( (y1 - m_lower( i )) > (m_upper( i ) - y2) )
- beta = 1 + 2 * (m_upper( i ) - y2) / (y2 - y1);
- else
- beta = 1 + 2 * (y1 - m_lower( i )) / (y2 - y1);
-
-
- double expp = m_nc + 1.;
- // Find alpha
- double alpha = 2. - std::pow(1.0/beta , expp);
- double u = Rng::uni( 0., 1. );
-
- if( u <= 1. / alpha ) {
- alpha *= u;
- betaQ = std::pow( alpha, 1.0/expp );
- } else {
- alpha *= u;
- alpha = 1. / (2. - alpha);
- betaQ = std::pow( alpha, 1.0/expp );
- }
- } else { // if genes are equal -> from Deb's implementation, not contained in any paper
- betaQ = 1.;
+ double betaQ1 = 0.0;
+ double betaQ2 = 0.0;
+ if( std::abs(y2 - y1) < 1E-7 )continue;//equal
+
+ // Find beta value2
+ double beta1 = 1 + 2 * (y1 - m_lower( i )) / (y2 - y1);
+ double beta2 = 1 + 2 * (m_upper( i ) - y2) / (y2 - y1);
+ double expp = m_nc + 1.;
+ // Find alpha
+ double alpha1 = 2. - std::pow(beta1 , -expp);
+ double alpha2 = 2. - std::pow(beta2 , -expp);
+
+ double u = Rng::uni( 0., 1. );
+ alpha1 *=u;
+ alpha2 *=u;
+ if( u > 1. / alpha1 ) {
+ alpha1 = 1. / (2. - alpha1);
+ }
+ if( u > 1. / alpha2 ) {
+ alpha2 = 1. / (2. - alpha2);
}
+ betaQ1 = std::pow( alpha1, 1.0/expp );
+ betaQ2 = std::pow( alpha2, 1.0/expp );
- point1[i] = 0.5 * ((y1 + y2) - betaQ * (y2 - y1));
- point2[i] = 0.5 * ((y1 + y2) + betaQ * (y2 - y1));
+ //recombine points
+ point1[i] = 0.5 * ((y1 + y2) - betaQ1 * (y2 - y1));
+ point2[i] = 0.5 * ((y1 + y2) + betaQ2 * (y2 - y1));
// randomly swap loci
if( Rng::coinToss() ) std::swap(point1[i], point2[i]);
--
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