RVEA.h
Go to the documentation of this file.
1//===========================================================================
2/*!
3 *
4 *
5 * \brief Implements the RVEA algorithm.
6 *
7 * \author Bjoern Bugge Grathwohl
8 * \date March 2017
9 *
10 * \par Copyright 1995-2017 Shark Development Team
11 *
12 * <BR><HR>
13 * This file is part of Shark.
14 * <https://shark-ml.github.io/Shark/>
15 *
16 * Shark is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Lesser General Public License as published
18 * by the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * Shark is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with Shark. If not, see <http://www.gnu.org/licenses/>.
28 *
29 */
30//===========================================================================
31
32#ifndef SHARK_ALGORITHMS_DIRECT_SEARCH_RVEA
33#define SHARK_ALGORITHMS_DIRECT_SEARCH_RVEA
34
43
44namespace shark {
45
46/// \brief Implements the RVEA algorithm.
47///
48/// Implementation of the RVEA algorithm from the following paper:
49/// R. Cheng, Y. Jin, M. Olhofer, and B. Sendhoff, “A reference vector guided
50/// evolutionary algorithm for many-objective optimization,” IEEE Transactions on
51/// Evolutionary Computation, Vol 20, Issue 5, October 2016
52/// http://dx.doi.org/10.1109/TEVC.2016.2519378
53/// \ingroup multidirect
54class RVEA : public AbstractMultiObjectiveOptimizer<RealVector>
55{
56public:
57 SHARK_EXPORT_SYMBOL RVEA(random::rng_type & rng = random::globalRng);
58
59 std::string name() const{
60 return "RVEA";
61 }
62
63 double crossoverProbability() const{
64 return m_crossoverProbability;
65 }
66
68 return m_crossoverProbability;
69 }
70
71 double nm() const{
72 return m_mutation.m_nm;
73 }
74
75 double & nm(){
76 return m_mutation.m_nm;
77 }
78
79 double nc() const{
80 return m_crossover.m_nc;
81 }
82
83 double & nc(){
84 return m_crossover.m_nc;
85 }
86
87 double alpha() const{
88 return m_selection.m_alpha;
89 }
90
91 double & alpha(){
92 return m_selection.m_alpha;
93 }
94
95 double adaptationFrequency() const{
96 return m_adaptParam;
97 }
98
100 return m_adaptParam;
101 }
102
103 /// \brief Size of parent population and number of reference vectors.
104 ///
105 /// In the RVEA algorithm, the exact mu value is determined by the
106 /// simplex-lattice design (Lattice.h), so the user cannot set it directly.
107 /// Instead, one must set the approxMu() value, which will be used as a
108 /// parameter in the lattice. If one wants to know the exact mu value, set
109 /// approxMu() to RVEA::suggestMu(n, m) where n is the objective dimension
110 /// and m is the approximate mu. Then the actual mu value will not be
111 /// changed in the initialization.
112 std::size_t mu() const{
113 return m_mu;
114 }
115
116 std::size_t numInitPoints() const{
117 return m_mu;
118 }
119
120 std::size_t approxMu() const{
121 return m_approxMu;
122 }
123
124 std::size_t & approxMu(){
125 return m_approxMu;
126 }
127
128 RealMatrix referenceVectors() const{
129 return m_referenceVectors;
130 }
131
132 RealMatrix & referenceVectors(){
133 return m_referenceVectors;
134 }
135
136 RealMatrix initialReferenceVectors() const{
137 return m_adaptation.m_initVecs;
138 }
139
140 std::size_t maxIterations() const{
141 return m_selection.m_maxIters;
142 }
143
144 std::size_t & maxIterations(){
145 return m_selection.m_maxIters;
146 }
147
148 /// \brief True if the reference vectors will be adapted.
149 ///
150 /// Returns true if the algorithm will adapt the unit reference vectors in
151 /// the current iteration. This is controlled by the adaptationFreqency()
152 /// parameter; a value of, e.g., 0.2 will make the algorithm readapt
153 /// reference vectors every 20% of the iteration. Running the algorithm for
154 /// 1000 iterations will then make it readapt on iteration 0, 200, 400, etc.
156 return m_curIteration % static_cast<std::size_t>(
157 std::ceil(adaptationFrequency() * m_selection.m_maxIters)
158 ) == 0;
159 }
160
161 template <typename Archive>
162 void serialize(Archive & archive){
163#define S(var) archive & BOOST_SERIALIZATION_NVP(var)
164 S(m_crossoverProbability);
165 S(m_mu);
166 S(m_approxMu);
167 S(m_parents);
168 S(m_best);
169 S(m_crossover);
170 S(m_mutation);
171 S(m_adaptParam);
172 S(m_curIteration);
173 S(m_referenceVectors);
174 S(m_referenceVectorMinAngles);
175 S(m_selection);
176 S(m_adaptation);
177#undef S
178 }
179
180 using AbstractMultiObjectiveOptimizer<RealVector >::init;
182 ObjectiveFunctionType const& function,
183 std::vector<SearchPointType> const & initialSearchPoints
184 );
186 ObjectiveFunctionType const & function
187 );
188 SHARK_EXPORT_SYMBOL static std::size_t suggestMu(
189 std::size_t n, std::size_t const approx_mu);
190protected:
193 std::vector<SearchPointType> const & initialSearchPoints,
194 std::vector<ResultType> const & functionValues,
195 RealVector const & lowerBounds,
196 RealVector const & upperBounds,
197 std::size_t const approx_mu,
198 double const nm,
199 double const nc,
200 double const crossover_prob,
201 double const alph,
202 double const fr,
203 std::size_t const max_iterations,
204 std::vector<Preference> const & referenceVectorsPreferences = std::vector<Preference>()
205 );
206
207 SHARK_EXPORT_SYMBOL std::vector<IndividualType> generateOffspring() const;
209 std::vector<IndividualType> const & offspringvec
210 );
211
212 std::vector<IndividualType> m_parents;
213
214private:
215 random::rng_type * m_rng;
216 double m_crossoverProbability; ///< Probability of crossover happening.
217 /// \brief Size of parent population
218 ///
219 /// It is also the number of reference vectors.
220 std::size_t m_mu;
221 /// \brief The "approximate" value of mu that the user asked for.
222 ///
223 /// The actual value of mu is determined via the simplex-lattice design for
224 /// the unit reference vectors. It will always be the same as
225 /// RVEA::suggestMu(n, m_approxMu) where n is the number of objectives.
226 std::size_t m_approxMu;
228 PolynomialMutator m_mutation;
229 /// \brief Hyperparameter controlling reference vector adaptation rate.
230 ///
231 /// A value of 0.2 makes the algorithm adapt the reference vectors every 20%
232 /// of the iterations. If the algorithm runs for a total of 1000 iterations,
233 /// they will be readjusted on iteration 0, 200, 400, etc. Is is called
234 /// "f_r" in the paper.
235 double m_adaptParam;
236 /// \brief Current iteration of the algorithm.
237 ///
238 /// The algorithm maintains knowledge of how long it has been running as
239 /// this is required by parts of the RVEA algorithm.
240 std::size_t m_curIteration;
241
242 /// \brief The active set of unit reference vectors.
243 RealMatrix m_referenceVectors;
244 /// \brief Contains the minimum angles between reference vectors.
245 ///
246 /// For each reference vector i, position i in this vector is the smallest
247 /// angle between reference vector i and all the other reference vectors.
248 RealVector m_referenceVectorMinAngles;
251};
252
253} // namespace shark
254
255#endif // SHARK_ALGORITHMS_DIRECT_SEARCH_RVEA