-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsteepest_descent.h
71 lines (51 loc) · 1.3 KB
/
steepest_descent.h
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// NOTE: there is 2nd implementation: http://www.netlib.org/opt/hooke.c
#ifndef LOPTI_STEEPEST_DESCENT
#define LOPTI_STEEPEST_DESCENT
#include <lopti/lopti.h>
#ifndef MINIMIZER
#define MINIMIZER steepest_descent_minimizer
#endif
#include <cassert>
//using namespace std;
#include <lvv/array.h>
//using namespace lvv;
using lvv::array;
namespace lopti {
template<typename V>
struct MINIMIZER : minimizer<V> {
MINIMIZER_MEMBERS; OBJECTIVE_TYPES;
explicit MINIMIZER () : minimizer<V>("steepest_descent") {};
//virtual minimizer<V>& tau (T _tau) { tau_ = _tau; return *this; };
V& argmin () {
/*
def steepest(x0):
i = 0
iMax = 10
x = x0
Delta = 1
alpha = 1
while i<iMax and Delta>10**(-5):
p = -Jacobian(x)
xOld = x
x = x + alpha*p
Delta = sum((x-xOld)**2)
print x
i += 1
*/
int i = 0;
int iMax = 10;
X = X0;
Delta = 1
alpha = 1
while i<iMax and Delta>10**(-5):
p = -Jacobian(x)
xOld = x
x = x + alpha*p
Delta = sum((x-xOld)**2)
print x
i += 1
}
private:
}; // class
} // namespace lopti
#endif // LOPTI_H