DiffPowers.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief -
5  *
6  * \author -
7  * \date -
8  *
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 #ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_DIFFPOWERS_H
31 #define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_DIFFPOWERS_H
32 
34 #include <shark/Core/Random.h>
35 
36 namespace shark {
38 
39  DiffPowers(std::size_t numberOfVariables = 5) {
41  m_numberOfVariables = numberOfVariables;
42  }
43 
44  /// \brief From INameable: return the class name.
45  std::string name() const
46  { return "DiffPowers"; }
47 
48  std::size_t numberOfVariables()const{
49  return m_numberOfVariables;
50  }
51 
53  return true;
54  }
55 
56  /// \brief Adjusts the number of variables if the function is scalable.
57  /// \param [in] numberOfVariables The new dimension.
59  m_numberOfVariables = numberOfVariables;
60  }
61 
63  RealVector x(numberOfVariables());
64 
65  for (std::size_t i = 0; i < x.size(); i++) {
66  x(i) = random::uni(*mep_rng, 0,1);
67  }
68  return x;
69  }
70 
71  double eval( const SearchPointType & p ) const {
73  double sum = 0;
74  for( std::size_t i = 0; i < p.size(); i++ ){
75  sum += std::pow( std::abs( p( i ) ), 2. + (10.*i) / (p.size() - 1.) );
76  }
77  return sum;
78  }
79 private:
80  std::size_t m_numberOfVariables;
81 };
82 }
83 
84 #endif