forked from sudz123/Optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
42 lines (34 loc) · 1.35 KB
/
test.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
#include <iostream>
#include <Eigen/Dense>
#include "../Optimizer/optimizer"
using namespace std;
using namespace Eigen;
using namespace Optimizer;
double func (double x) {
return pow(x + 10, 2);
}
double func2 (VectorXd x) {
return x.squaredNorm();
}
int main () {
cout << "Using Function: (x + 10)^2 for single variable algorithms testing." << endl;
cout << "Test Bounding Phase:" << endl;
double ipt = 5.4;
Vector2d range = BoundingPhase(func, ipt);
cout << "Range from bounding Phase for initial point :" << ipt << endl;
cout << range << endl;
cout << "Derivatives at " << ipt << endl;
cout << Derivative(func, ipt) << endl;
cout << "Finding optimal point using above range for Newton Rapshon Method." << endl;
cout << "Optimal Point is: ";
cout << NewtonRapshon (func, range) << endl;;
cout << "Testing SVOptimize on (x + 10)^2 with initial point 5.4." << endl;
cout << "The Optimal Point obtained is: ";
cout << SVOptimize(func, 5.4) << endl;
cout << "Testing Gradient function using func2 with 3 variables" << endl;
cout << Gradient(func2, Vector3d(3, 3, 4)) << endl;
cout << "Testing DFP on sum squared function with 3 variables and initial point (4, -3, 7)." << endl;
cout << "The Optimal Point obtained is: " << endl;
Vector3d x(4, -3, 7);
cout << DFP(func2, x) << endl;
}