Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
include
shark
ObjectiveFunctions
Benchmarks
DiffPowers.h
Go to the documentation of this file.
1
/*!
2
*
3
*
4
* \brief -
5
*
6
* \author -
7
* \date -
8
*
9
*
10
* \par Copyright 1995-2017 Shark Development Team
11
*
12
* <BR><HR>
13
* This file is part of Shark.
14
* <https://shark-ml.github.io/Shark/>
15
*
16
* Shark is free software: you can redistribute it and/or modify
17
* it under the terms of the GNU Lesser General Public License as published
18
* by the Free Software Foundation, either version 3 of the License, or
19
* (at your option) any later version.
20
*
21
* Shark is distributed in the hope that it will be useful,
22
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
* GNU Lesser General Public License for more details.
25
*
26
* You should have received a copy of the GNU Lesser General Public License
27
* along with Shark. If not, see <http://www.gnu.org/licenses/>.
28
*
29
*/
30
#ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_DIFFPOWERS_H
31
#define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_DIFFPOWERS_H
32
33
#include <
shark/ObjectiveFunctions/AbstractObjectiveFunction.h
>
34
#include <
shark/Core/Random.h
>
35
36
37
/// \brief Different powers objective function.
38
///
39
/// each dimension is of the form x^a for varying a. This function is ill-conditioned close to the optimum.
40
/// \ingroup benchmarks
41
namespace
shark
{
namespace
benchmarks{
42
struct
DiffPowers
:
public
SingleObjectiveFunction
{
43
44
DiffPowers
(std::size_t
numberOfVariables
= 5) {
45
m_features
|=
CAN_PROPOSE_STARTING_POINT
;
46
m_numberOfVariables =
numberOfVariables
;
47
}
48
49
/// \brief From INameable: return the class name.
50
std::string
name
()
const
51
{
return
"DiffPowers"
; }
52
53
std::size_t
numberOfVariables
()
const
{
54
return
m_numberOfVariables;
55
}
56
57
bool
hasScalableDimensionality
()
const
{
58
return
true
;
59
}
60
61
/// \brief Adjusts the number of variables if the function is scalable.
62
/// \param [in] numberOfVariables The new dimension.
63
void
setNumberOfVariables
( std::size_t
numberOfVariables
){
64
m_numberOfVariables =
numberOfVariables
;
65
}
66
67
SearchPointType
proposeStartingPoint
()
const
{
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
{
77
m_evaluationCounter
++;
78
double
sum = 0;
79
for
( std::size_t i = 0; i < p.size(); i++ ){
80
sum += std::pow( std::abs( p( i ) ), 2. + (10.*i) / (p.size() - 1.) );
81
}
82
return
sum;
83
}
84
private
:
85
std::size_t m_numberOfVariables;
86
};
87
}}
88
89
#endif