Repository navigation
Expand file tree
/
Copy pathoptim.h
More file actions
121 lines (104 loc) · 3.54 KB
/
Copy pathoptim.h
File metadata and controls
121 lines (104 loc) · 3.54 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef OPTIM_H
#define OPTIM_H
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/SparseCore>
#include <list>
typedef Eigen::Triplet<double> T;
struct matCOO{
std::list<int> row;
std::list<int> col;
std::list<double> val;
uint nr,nc;
matCOO(){};
matCOO(uint size){nr = size;nc=size;};
matCOO(uint sizer,uint sizec){nr = sizer;nc=sizec;};
matCOO(Eigen::SparseMatrix<double> const & m);
Eigen::SparseMatrix<double> toSparseEigen();
Eigen::SparseMatrix<double> Extract(std::vector<bool> Mask,std::vector<int> const & NewIndice, int size);
void push(uint Prow,uint Pcol,double Pval){row.push_back(Prow);col.push_back(Pcol);val.push_back(Pval);};
int getDimRow(){return (int) nr;};
int getDimCol(){return (int) nc;};
bool isSquared(){return nr == nc;};
};
class BFGS{
const uint memorySize;
const uint problemSize;
std::list<Eigen::VectorXd> memoryX;
std::list<Eigen::VectorXd> memoryGrad;
public:
BFGS();
BFGS(uint memSize,uint pbSize);
void addDirection(double step, Eigen::VectorXd direction, Eigen::VectorXd gradNew, Eigen::VectorXd gradOld);
Eigen::VectorXd findDirection(Eigen::VectorXd gradf);
};
class gradientDescent{
double stepSize;
const double gradNormThres;
const uint iterMax;
public:
gradientDescent();
gradientDescent(double step, double gradN,int nbIter);
void setStep(double s){ this->stepSize = s;};
double step(){ return this->stepSize;};
double gradN(){ return this->gradNormThres;};
uint iMax(){ return this->iterMax;};
};
class gradientStrongWolf{
const double stepSize;
const double gradNormThres;
const double alpha1;
const double alpha2;
const uint maxStepReduction;
const uint iterMax;
public:
gradientStrongWolf();
gradientStrongWolf(double step, double gradN,double wOne, double wTwo,
int innerLoop,int nbIter);
double step(){ return this->stepSize;};
double gradN(){ return this->gradNormThres;};
double w1(){ return this->alpha1;};
double w2(){ return this->alpha2;};
uint innerMax(){ return this->maxStepReduction;};
uint iMax(){ return this->iterMax;};
};
class barzilaiBorwein{
const double gradNormThres;
const uint iterMax;
public:
barzilaiBorwein();
barzilaiBorwein(double gradN,int nbIter);
double gradN(){ return this->gradNormThres;};
uint iMax(){ return this->iterMax;};
double bbStep;
};
class barzilaiBorweinLS{
const double gradNormThres;
const double lineSearchFactor;
const double gammaWolfe;
const uint iterMax;
const uint memorySize;
protected:
std::list<double> costFunctionList;
public:
barzilaiBorweinLS();
barzilaiBorweinLS(double gradN,double lineSearch,double gammaW,int nbIter,int memSize);
double gradN(){ return this->gradNormThres;};
double lSearch(){ return this->lineSearchFactor;};
double gamma(){ return this->gammaWolfe;};
void addCost(double cost);
double minCost();
uint iMax(){ return this->iterMax;};
double bbStep;
};
class heavyBall{
const double Lips;
const double gradNormThres;
const uint iterMax;
public:
heavyBall();
heavyBall(double LispchitzConstant,double gradN,int nbIter);
double L(){ return this->Lips;};
double gradN(){ return this->gradNormThres;};
uint iMax(){ return this->iterMax;};
};
#endif