ReferenceVectorAdaptation.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief Reference vector adaptation for 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  * <http://shark-ml.org/>
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_OPERATORS_REFERENCE_VECTOR_ADAPTATION_H
33 #define SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_REFERENCE_VECTOR_ADAPTATION_H
34 
35 #include <shark/LinAlg/Base.h>
37 
38 namespace shark {
39 /**
40  * \brief Reference vector adaptation for the RVEA algorithm.
41  *
42  * This operator is supposed to be applied regularly in the RVEA algorithm to
43  * adjust the set of reference vectors to better match a scaled pareto front.
44  * See below paper for details:
45  * R. Cheng, Y. Jin, M. Olhofer, and B. Sendhoff, “A reference vector guided
46  * evolutionary algorithm for many-objective optimization,” IEEE Transactions on
47  * Evolutionary Computation, Vol 20, Issue 5, October 2016
48  * http://dx.doi.org/10.1109/TEVC.2016.2519378
49  */
50 template <typename IndividualType>
52 {
53  /**
54  * \brief Apply adaptation operator and update the angles.
55  */
56  void operator()(
57  std::vector<IndividualType> const & population,
58  RealMatrix & referenceVectors,
59  RealVector & minAngles)
60  {
61  auto f = unpenalizedFitness(population);
62  const std::size_t sz = f.size();
63  const std::size_t w = f[0].size();
64  RealVector diff(w);
65  for(std::size_t i = 0; i < w; ++i)
66  {
67  double max = std::numeric_limits<double>::min();
68  double min = std::numeric_limits<double>::max();
69  for(std::size_t j = 0; j < sz; ++j)
70  {
71  max = std::max(max, f[j][i]);
72  min = std::min(min, f[j][i]);
73  }
74  double d = max - min;
75  diff[i] = (d == 0) ? 1 : d;
76  }
77  referenceVectors = m_initVecs * repeat(diff, m_initVecs.size1());
78  for(std::size_t i = 0; i < referenceVectors.size1(); ++i)
79  {
80  row(referenceVectors, i) /= norm_2(row(referenceVectors, i));
81  }
82  updateAngles(referenceVectors, minAngles);
83  }
84 
85  /**
86  * \brief Compute the minimum angles between unit vectors.
87  */
88  static void updateAngles(
89  RealMatrix const & referenceVectors,
90  RealVector & minAngles)
91  {
92  const std::size_t s = referenceVectors.size1();
93  const RealMatrix m = acos(prod(referenceVectors,
94  trans(referenceVectors))) +
95  to_diagonal(RealVector(s, 1e10));
96  for(std::size_t i = 0; i < s; ++i)
97  {
98  minAngles[i] = min(row(m, i));
99  }
100  }
101 
102  template <typename Archive>
103  void serialize(Archive & archive)
104  {
105  archive & m_initVecs;
106  }
107 
108  /// \brief The set of initial reference vectors.
109  ///
110  /// This must be set before the operator is called the first time.
111  RealMatrix m_initVecs;
112 };
113 
114 } // namespace shark
115 
116 #endif // SHARK_ALGORITHMS_DIRECT_SEARCH_OPERATORS_REFERENCE_VECTOR_ADAPTATION_H