-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_paper.cpp
72 lines (52 loc) · 1.91 KB
/
test_paper.cpp
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
72
#include <fstream>
#include <iostream>
#include <iomanip>
#include "papersheet.h"
#include "tr_optim.h"
using namespace std;
int lines = 11, columns = 11;
int dims = 3;
void my_target_papersheet_hess(double *x_val, double *y_val, double *gradient, double *hessian) {
return target_papersheet_hess(lines, columns, x_val, y_val, gradient, hessian);
}
int main(int argc, const char *argv[]) {
int n_vars = lines * columns * dims;
double xx[n_vars];
double seglen = 0.3;
int i, j;
for (i = 0; i < lines; i++)
for (j = 0; j < columns; j++) {
int pt = 3 * (i * columns + j);
xx[pt + 0] = seglen * (j - columns / 2);
xx[pt + 1] = seglen * (lines / 2 - i);
xx[pt + 2] = -1.0;
}
for (i = 0; i < lines; i++)
for (j = 0; j < columns; j++) {
int pt = 3 * (i * columns + j);
cout << xx[pt + 0] << "\t" << xx[pt + 1] << "\t" << xx[pt + 2] << endl;
}
// Read initial position.
// fstream fs;
// fs.open(argv[1], std::fstream::in);
// fs >> xx[0] >> xx[1];
// trust_region_optimization(target_rosenbrock_hess, 2, xx, 0.1);
double yy[1];
double gg[lines * columns * dims];
double hh[lines * columns * dims * lines * columns * dims];
my_target_papersheet_hess(xx, yy, gg, hh);
double *res = trust_region_optimization(my_target_papersheet_hess, n_vars, xx, 0.1, 1e-4, 500);
for (i = 0; i < lines; i++)
for (j = 0; j < columns; j++) {
int pt = 3 * (i * columns + j);
cout << res[pt + 0] << "\t" << res[pt + 1] << "\t" << res[pt + 2] << endl;
}
fstream fs;
fs.open(argv[1], std::fstream::out);
for (i = 0; i < lines; i++)
for (j = 0; j < columns; j++) {
int pt = 3 * (i * columns + j);
fs << res[pt + 0] << "\t" << res[pt + 1] << "\t" << res[pt + 2] << endl;
}
return 0;
}