Discus.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Convex quadratic benchmark function.
5  *
6  *
7  * \author -
8  * \date 2010-2011
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_OBJECTIVEFUNCTIONS_BENCHMARKS_DISCUS_H
32 #define SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_DISCUS_H
33 
35 #include <shark/Rng/GlobalRng.h>
36 
37 namespace shark {
38 /**
39  * \brief Convex quadratic benchmark function.
40  */
42 
43  Discus(std::size_t numberOfVariables = 5,double alpha = 1.E-3) : m_alpha(alpha) {
45  m_numberOfVariables = numberOfVariables;
46  }
47 
48  /// \brief From INameable: return the class name.
49  std::string name() const
50  { return "Discus"; }
51 
52  std::size_t numberOfVariables()const{
53  return m_numberOfVariables;
54  }
55 
57  return true;
58  }
59 
60  /// \brief Adjusts the number of variables if the function is scalable.
61  /// \param [in] numberOfVariables The new dimension.
63  m_numberOfVariables = numberOfVariables;
64  }
65 
67  RealVector x(numberOfVariables());
68 
69  for (std::size_t i = 0; i < x.size(); i++) {
70  x(i) = Rng::uni(0,1);
71  }
72  return x;
73  }
74 
75  double eval(const SearchPointType &p) const {
77  double sum = sqr(p(0));
78  for (std::size_t i = 1; i < p.size(); i++)
79  sum += m_alpha * sqr(p(i));
80 
81  return sum;
82  }
83 
84  double alpha() const {
85  return m_alpha;
86  }
87 
88  void setAlpha(double alpha) {
89  m_alpha = alpha;
90  }
91 
92 private:
93  double m_alpha;
94  std::size_t m_numberOfVariables;
95 };
96 }
97 
98 #endif