Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
include
shark
ObjectiveFunctions
Benchmarks
Himmelblau.h
Go to the documentation of this file.
1
/*!
2
*
3
*
4
* \brief Two-dimensional, real-valued Himmelblau function.
5
*
6
* Multi-modal benchmark function.
7
*
8
*
9
*
10
* \author -
11
* \date -
12
*
13
*
14
* \par Copyright 1995-2017 Shark Development Team
15
*
16
* <BR><HR>
17
* This file is part of Shark.
18
* <https://shark-ml.github.io/Shark/>
19
*
20
* Shark is free software: you can redistribute it and/or modify
21
* it under the terms of the GNU Lesser General Public License as published
22
* by the Free Software Foundation, either version 3 of the License, or
23
* (at your option) any later version.
24
*
25
* Shark is distributed in the hope that it will be useful,
26
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
* GNU Lesser General Public License for more details.
29
*
30
* You should have received a copy of the GNU Lesser General Public License
31
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
32
*
33
*/
34
#ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_HIMMELBLAU_H
35
#define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_HIMMELBLAU_H
36
37
#include <
shark/ObjectiveFunctions/AbstractObjectiveFunction.h
>
38
#include <
shark/Core/Random.h
>
39
40
namespace
shark
{
namespace
benchmarks{
41
/**
42
* \brief Multi-modal two-dimensional continuous Himmelblau benchmark function.
43
*
44
* Implements Himmelblau's real-valued, multi-modal benchmark function. The
45
* function is limited to two dimensions. Please see:
46
* http://en.wikipedia.org/wiki/Himmelblau%27s_function
47
* for further information.
48
* \ingroup benchmarks
49
*/
50
struct
Himmelblau
:
public
SingleObjectiveFunction
{
51
/**
52
* \brief Constructs an instance of the function.
53
*/
54
Himmelblau
() {
55
m_features
|=
CAN_PROPOSE_STARTING_POINT
;
56
}
57
58
/// \brief From INameable: return the class name.
59
std::string
name
()
const
60
{
return
"Himmelblau"
; }
61
62
std::size_t
numberOfVariables
()
const
{
63
return
2;
64
}
65
66
SearchPointType
proposeStartingPoint
()
const
{
67
RealVector x(
numberOfVariables
());
68
69
for
(std::size_t i = 0; i < x.size(); i++) {
70
x(i) =
random::uni
(*
mep_rng
, -3,3);
71
}
72
return
x;
73
}
74
75
/**
76
* \brief Evaluates the function for the supplied search point.
77
* \throws shark::Exception if the size of p does not equal 2.
78
*/
79
double
eval
(
const
SearchPointType
& p )
const
{
80
SIZE_CHECK
(p.size() == 2);
81
82
m_evaluationCounter
++;
83
84
return
(
85
sqr
(
sqr
( p( 0 ) ) + p( 1 ) - 11 ) +
86
sqr
( p( 0 ) +
sqr
( p( 1 ) ) - 7 )
87
);
88
}
89
};
90
91
}}
92
93
#endif