Shark machine learning library
About Shark
News!
Contribute
Credits and copyright
Downloads
Getting Started
Installation
Using the docs
Documentation
Tutorials
Quick references
Class list
Global functions
FAQ
Showroom
include
shark
ObjectiveFunctions
Benchmarks
Schwefel.h
Go to the documentation of this file.
1
/*!
2
*
3
*
4
* \brief Convex benchmark function.
5
*
6
*
7
* \author T. Voss
8
* \date 2010-2011
9
*
10
*
11
* \par Copyright 1995-2017 Shark Development Team
12
*
13
* <BR><HR>
14
* This file is part of Shark.
15
* <http://shark-ml.org/>
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_BENCHMARK_SCHWEFEL_H
32
#define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_SCHWEFEL_H
33
34
#include <
shark/ObjectiveFunctions/AbstractObjectiveFunction.h
>
35
#include <
shark/Core/Random.h
>
36
37
namespace
shark
{
38
/**
39
* \brief Convex benchmark function.
40
*/
41
struct
Schwefel
:
public
SingleObjectiveFunction
{
42
43
Schwefel
(std::size_t
numberOfVariables
= 5):m_numberOfVariables(
numberOfVariables
) {
44
m_features
|=
CAN_PROPOSE_STARTING_POINT
;
45
}
46
47
/// \brief From INameable: return the class name.
48
std::string
name
()
const
49
{
return
"Schwefel"
; }
50
51
std::size_t
numberOfVariables
()
const
{
52
return
m_numberOfVariables;
53
}
54
55
bool
hasScalableDimensionality
()
const
{
56
return
true
;
57
}
58
59
void
setNumberOfVariables
( std::size_t
numberOfVariables
){
60
m_numberOfVariables =
numberOfVariables
;
61
}
62
63
SearchPointType
proposeStartingPoint
()
const
{
64
RealVector x(
numberOfVariables
());
65
66
for
(std::size_t i = 0; i < x.size(); i++) {
67
x(i) =
random::gauss
(*
mep_rng
, 0,1);
68
}
69
return
x;
70
}
71
72
double
eval
(
const
SearchPointType
&p)
const
{
73
m_evaluationCounter
++;
74
double
value = 0;
75
double
sum= 0;
76
for
(std::size_t i = 0; i != m_numberOfVariables; ++i){
77
sum+= p(i);
78
value+=
sqr
(sum);
79
}
80
return
value;
81
}
82
private
:
83
std::size_t m_numberOfVariables;
84
};
85
86
}
87
88
#endif