Shark machine learning library
Installation
Tutorials
Benchmarks
Documentation
Quick references
Class list
Global functions
examples
EA
SOO
CMASimple.cpp
Go to the documentation of this file.
1
/*!
2
*
3
*
4
* \brief Example for running CMA-ES on an exemplary benchmark function.
5
6
*
7
*
8
* \author tvoss
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
// Implementation of the CMA-ES
33
#include <
shark/Algorithms/DirectSearch/CMA.h
>
34
// Access to benchmark functions
35
#include <
shark/ObjectiveFunctions/Benchmarks/Benchmarks.h
>
36
37
using namespace
shark
;
38
using namespace
std;
39
40
int
main
(
int
argc,
char
** argv ) {
41
42
// Adjust the floating-point format to scientific and increase output precision.
43
cout.setf( ios_base::scientific );
44
cout.precision( 10 );
45
46
// Instantiate the problem.
47
benchmarks::Sphere
sphere( 2 );
48
// Initialize the optimizer for the objective function instance.
49
CMA
cma;
50
cma.
setInitialSigma
(0.1);
// Explicitely set initial global step size.
51
sphere.
init
();
52
cma.
init
( sphere, sphere.
proposeStartingPoint
());
53
54
// Iterate the optimizer until a solution of sufficient quality is found.
55
do
{
56
cma.
step
( sphere );
57
58
// Report information on the optimizer state and the current solution to the console.
59
cout << sphere.
evaluationCounter
() <<
" "
<< cma.
solution
().value <<
" "
<< cma.
solution
().point <<
" "
<< cma.
sigma
() << endl;
60
}
while
(cma.
solution
().value > 1E-20 );
61
}