Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
include
shark
ObjectiveFunctions
Benchmarks
CigarDiscus.h
Go to the documentation of this file.
1
/*!
2
*
3
*
4
* \brief Convex quadratic benchmark function.
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_BENCHMARK_CIGARDISCUS_H
33
#define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_CIGARDISCUS_H
34
35
#include <
shark/ObjectiveFunctions/AbstractObjectiveFunction.h
>
36
#include <
shark/Core/Random.h
>
37
38
namespace
shark
{
namespace
benchmarks{
39
/**
40
* \brief Convex quadratic benchmark function.
41
* \ingroup benchmarks
42
*/
43
class
CigarDiscus
:
public
SingleObjectiveFunction
{
44
public
:
45
46
CigarDiscus
(std::size_t
numberOfVariables
= 5,
double
alpha
=1E-3) : m_alpha(
alpha
) {
47
m_features
|=
CAN_PROPOSE_STARTING_POINT
;
48
m_numberOfVariables =
numberOfVariables
;
49
}
50
51
/// \brief From INameable: return the class name.
52
std::string
name
()
const
53
{
return
"CigarDiscus"
; }
54
55
std::size_t
numberOfVariables
()
const
{
56
return
m_numberOfVariables;
57
}
58
59
bool
hasScalableDimensionality
()
const
{
60
return
true
;
61
}
62
63
/// \brief Adjusts the number of variables if the function is scalable.
64
/// \param [in] numberOfVariables The new dimension.
65
void
setNumberOfVariables
( std::size_t
numberOfVariables
){
66
m_numberOfVariables =
numberOfVariables
;
67
}
68
69
SearchPointType
proposeStartingPoint
()
const
{
70
RealVector x(
numberOfVariables
());
71
72
for
(std::size_t i = 0; i < x.size(); i++) {
73
x(i) =
random::uni
(*
mep_rng
, 0, 1);
74
}
75
return
x;
76
}
77
78
double
eval
(
const
SearchPointType
&p)
const
{
79
m_evaluationCounter
++;
80
81
double
sum = m_alpha *
sqr
(p(0)) +
sqr
(p(p.size() - 1));
82
double
alpha
= ::sqrt(m_alpha);
83
for
(std::size_t i = 1; i < p.size()-1; i++)
84
sum +=
alpha
*
sqr
(p(i));
85
86
return
sum;
87
}
88
89
double
alpha
()
const
{
90
return
m_alpha;
91
}
92
93
void
setAlpha
(
double
alpha
) {
94
m_alpha =
alpha
;
95
}
96
97
private
:
98
double
m_alpha;
99
std::size_t m_numberOfVariables;
100
};
101
}}
102
103
#endif