Cigar.h
Go to the documentation of this file.
1/*!
2 *
3 *
4 * \brief Convex quadratic benchmark function with single dominant axis
5
6 *
7 *
8 * \author -
9 * \date -
10 *
11 *
12 * \par Copyright 1995-2017 Shark Development Team
13 *
14 * <BR><HR>
15 * This file is part of Shark.
16 * <https://shark-ml.github.io/Shark/>
17 *
18 * Shark is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU Lesser General Public License as published
20 * by the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * Shark is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with Shark. If not, see <http://www.gnu.org/licenses/>.
30 *
31 */
32#ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_CIGAR_H
33#define SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_CIGAR_H
34
36#include <shark/Core/Random.h>
37
38namespace shark {namespace benchmarks{
39/**
40 * \brief Convex quadratic benchmark function with single dominant axis
41* \ingroup benchmarks
42 */
44
45 Cigar(std::size_t numberOfVariables = 5, double alpha=1.E-3) : m_alpha(alpha) {
48 m_numberOfVariables = numberOfVariables;
49 }
50
51 /// \brief From INameable: return the class name.
52 std::string name() const
53 { return "Cigar"; }
54
55 std::size_t numberOfVariables()const{
56 return m_numberOfVariables;
57 }
58
60 return true;
61 }
62
64 m_numberOfVariables = numberOfVariables;
65 }
66
68 RealVector x(numberOfVariables());
69
70 for (std::size_t i = 0; i < x.size(); i++) {
71 x(i) = random::uni(*mep_rng, 0, 1);
72 }
73 return x;
74 }
75
76 double eval(const SearchPointType &p) const {
78
79 double sum = m_alpha * sqr(p(0));
80 for (std::size_t i = 1; i < p.size(); i++)
81 sum += sqr(p(i));
82
83 return sum;
84 }
85 double evalDerivative(SearchPointType const& p, FirstOrderDerivative & derivative ) const {
86 derivative.resize(p.size());
87 noalias(derivative) = 2* p;
88 derivative(0) = 2 * m_alpha * p(0);
89 return eval(p);
90 }
91
92 double alpha() const {
93 return m_alpha;
94 }
95
96 void setAlpha(double alpha) {
97 m_alpha = alpha;
98 }
99
100private:
101 double m_alpha;
102 std::size_t m_numberOfVariables;
103};
104}}
105
106#endif // SHARK_EA_CIGAR_H