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