InvertedGenerationalDistance.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Inverted generational distance for comparing Pareto-front approximations.
5  *
6  *
7  * \author T. Voss, O.Krause
8  * \date 2010-2014
9  *
10  *
11  * \par Copyright 1995-2015 Shark Development Team
12  *
13  * <BR><HR>
14  * This file is part of Shark.
15  * <http://image.diku.dk/shark/>
16  *
17  * Shark is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Lesser General Public License as published
19  * by the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * Shark is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
29  *
30  */
31 #ifndef SHARK_ALGORITHMS_DIRECT_SEARCH_INDICATORS_INVERTED_GENERATIONAL_DISTANCE_H
32 #define SHARK_ALGORITHMS_DIRECT_SEARCH_INDICATORS_INVERTED_GENERATIONAL_DISTANCE_H
33 
34 #include <shark/LinAlg/Base.h>
35 #include <shark/Core/OpenMP.h>
36 
37 #include <algorithm>
38 #include <limits>
39 #include <vector>
40 
41 namespace shark {
42 
43 /**
44  * \brief Inverted generational distance for comparing Pareto-front approximations.
45  */
47 
48  template<
49  typename IteratorTypeA,
50  typename IteratorTypeB
51  >
52  double operator()( IteratorTypeA itPF, IteratorTypeA itePF, IteratorTypeB itRF, IteratorTypeB iteRF )
53  {
54  double result = 0.;
55  std::size_t noObjectives = e(*ita).size();
56  for( IteratorTypeA ita = itPF; ita != itePF; ++ita ) {
57  SIZE_CHECK(e(*ita).size() == noObjectives);
58 
59  double tmp = std::numeric_limits<double>::max();
60  for( IteratorTypeB itb = itRF; itb != iteRF; ++itb ) {
61  SIZE_CHECK(e(*itb).size() == noObjectives);
62  double sum = 0.;
63  for( unsigned int i = 0; i < noObjectives; i++ ) {
64  sum += sqr( e(*itb)[i] - e(*ita)[i] );
65  }
66  tmp = std::min( tmp, sum );
67  }
68  result += tmp;
69  }
70 
71  return std::sqrt( result ) / noObjectives;
72  }
73 
74  /// \brief Given a pareto front, returns the index of the points which is the least contributer
75  template<typename Extractor, typename ParetofrontType>
76  std::size_t leastContributor( Extractor extractor, const ParetofrontType & front)
77  {
78  std::vector<double> relativeApproximation(front.size());
79  SHARK_PARALLEL_FOR( int i = 0; i < static_cast< int >( front.size() ); i++ ) {
80  relativeApproximation[i] = (*this)( front.begin()+i,front.begin()+(i+1), front.begin(), front.end(), extractor );
81  }
82 
83  return std::min_element( relativeApproximation.begin(), relativeApproximation.end() ) - relativeApproximation.begin();
84  }
85 
86  /// \brief Updates the internal variables of the indicator using a whole population.
87  ///
88  /// Empty for this Indicator
89  /// \param extractor Functor returning the fitness values
90  /// \param set The set of points.
91  template<typename Extractor, typename PointSet>
92  void updateInternals(Extractor extractor, PointSet const& set){
93  (void)extractor;
94  (void)set;
95  }
96 
97  template<typename Archive>
98  void serialize( Archive & archive, const unsigned int version ) {
99  (void)archive;
100  (void)version;
101  }
102 
103 };
104 }
105 #endif