-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.cc
More file actions
29 lines (21 loc) · 817 Bytes
/
example.cc
File metadata and controls
29 lines (21 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <lopti/hook-jeevs.h>
using lopti::hook_jeevs_minimizer; // minimizer class
using lopti::make_objective;
// Array-type
typedef lvv::array<double,2> V; // == double X[2]
// Objective Function
double rosenbrock_fn (V& X) { return 100 * (X[1]-X[0]*X[0])*(X[1]-X[0]*X[0]) + (1-X[0])*(1-X[0]); };
int main() {
V X = {{ -1.2, 1 }}; // X0 - starting point.
V S = {{ 0.2, 0.2 }}; // step0 - initial step
hook_jeevs_minimizer<V> m;
// minimizer config
m.objective ( make_objective<V> (&rosenbrock_fn,"rosenbrock") );
m.x0 (X);
m.step0 (S);
m.max_iter (500);
// Result
V X_min = m.argmin();
double y_min = m.ymin();
cout << "Minimum: " << y_min << " at point: " << X_min << endl;
}