CMSA.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief Implements the CMSA.
6  *
7  * The algorithm is described in
8  *
9  * H. G. Beyer, B. Sendhoff (2008).
10  * Covariance Matrix Adaptation Revisited: The CMSA Evolution Strategy
11  * In Proceedings of the Tenth International Conference on Parallel Problem Solving from Nature
12  * (PPSN X), pp. 123-132, LNCS, Springer-Verlag
13  *
14  * \par Copyright (c) 1998-2008:
15  * Institut für Neuroinformatik
16  *
17  * \author -
18  * \date -
19  *
20  *
21  * \par Copyright 1995-2015 Shark Development Team
22  *
23  * <BR><HR>
24  * This file is part of Shark.
25  * <http://image.diku.dk/shark/>
26  *
27  * Shark is free software: you can redistribute it and/or modify
28  * it under the terms of the GNU Lesser General Public License as published
29  * by the Free Software Foundation, either version 3 of the License, or
30  * (at your option) any later version.
31  *
32  * Shark is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35  * GNU Lesser General Public License for more details.
36  *
37  * You should have received a copy of the GNU Lesser General Public License
38  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
39  *
40  */
41 //===========================================================================
42 
43 
44 #ifndef SHARK_ALGORITHMS_DIRECTSEARCH_CMSA_H
45 #define SHARK_ALGORITHMS_DIRECTSEARCH_CMSA_H
46 
47 #include <shark/Core/DLLSupport.h>
51 
52 
53 namespace shark {
54  /**
55  * \brief Implements the CMSA.
56  *
57  * The algorithm is described in
58  *
59  * H. G. Beyer, B. Sendhoff (2008).
60  * Covariance Matrix Adaptation Revisited: The CMSA Evolution Strategy
61  * In Proceedings of the Tenth International Conference on Parallel Problem Solving from Nature
62  * (PPSN X), pp. 123-132, LNCS, Springer-Verlag
63  */
64  class CMSA : public AbstractSingleObjectiveOptimizer<RealVector > {
65  /** \cond */
66 
67  struct LightChromosome {
68  RealVector step;
69  double sigma;
70  };
71  /** \endcond */
72  /**
73  * \brief Individual type of the CMSA implementation.
74  */
76 
77  public:
78 
79  /**
80  * \brief Default c'tor.
81  */
82  CMSA() : m_mu( 100 ), m_lambda( 200 ) {
84  }
85 
86  /// \brief From INameable: return the class name.
87  std::string name() const
88  { return "CMSA"; }
89 
90  /**
91  * \brief Calculates the center of gravity of the given population \f$ \in \mathbb{R}^d\f$.
92  *
93  *
94  */
95  template<typename Container, typename Extractor>
96  RealVector cog( const Container & container, const Extractor & e ) {
97 
98  RealVector result( m_numberOfVariables, 0. );
99 
100  for( std::size_t j = 0; j < container.size(); j++ )
101  result += 1./m_mu * e( container[j] );
102 
103  return result;
104  }
105 
106  SHARK_EXPORT_SYMBOL void read( InArchive & archive );
107  SHARK_EXPORT_SYMBOL void write( OutArchive & archive ) const;
108 
110  /**
111  * \brief Initializes the algorithm for the supplied objective function.
112  */
114 
115  /**
116  * \brief Executes one iteration of the algorithm.
117  */
118  SHARK_EXPORT_SYMBOL void step(ObjectiveFunctionType const& function);
119 
120  /**
121  * \brief Accesses the size of the parent population.
122  */
123  std::size_t mu() const {
124  return m_mu;
125  }
126 
127  /**
128  * \brief Accesses the size of the parent population, allows for l-value semantics.
129  */
130  std::size_t & mu() {
131  return m_mu;
132  }
133 
134  /**
135  * \brief Accesses the size of the offspring population.
136  */
137  std::size_t lambda() const {
138  return m_lambda;
139  }
140 
141  /**
142  * \brief Accesses the size of the offspring population, allows for l-value semantics.
143  */
144  std::size_t & lambda() {
145  return m_lambda;
146  }
147  protected:
148 
149  std::size_t m_numberOfVariables; ///< Stores the dimensionality of the search space.
150  std::size_t m_mu; ///< The size of the parent population.
151  std::size_t m_lambda; ///< The size of the offspring population, needs to be larger than mu.
152 
153  double m_sigma; ///< The current step size.
154  double m_cSigma;
155  double m_cC; ///< Constant for adapting the covariance matrix.
156 
157  RealVector m_mean; ///< The current cog of the population.
158 
159  shark::MultiVariateNormalDistribution m_mutationDistribution; ///< Multi-variate normal mutation distribution.
160  private:
161  /**
162  * \brief Updates the strategy parameters based on the supplied offspring population.
163  */
164  SHARK_EXPORT_SYMBOL void updateStrategyParameters( const std::vector< IndividualType > & offspringNew ) ;
165  };
166 }
167 
168 #endif