-
Notifications
You must be signed in to change notification settings - Fork 0
/
grad.hpp
executable file
·76 lines (51 loc) · 1.4 KB
/
grad.hpp
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
#pragma once
#ifndef GRAD_H
#define GRAD_H
#include <iostream>
#include "min.hpp"
class Grad {
public:
Grad(Function & func, std::vector<double> pos, double conval_ = 1e-5);
void fullMin(size_t iterlimit = 200);
std::vector<double> const& iter();
std::vector<double> const& getpos() const;
std::vector<double> & setPos();
std::vector<double> const& getDir();
std::vector<double> const& getGrad() const;
void updateGrad();
virtual bool hasConverged(double val) const;
virtual bool hasConverged() const;
size_t itercount() const;
void info(std::ostream & out = std::cout) const;
protected:
virtual void setDir() = 0;
void linesearchDot();
Function & fn;
double conval;
size_t counter;
std::vector<double> lastpos;
std::vector<double> lastdir;
std::vector<double> lastgrad;
};
class SD : public Grad {
public:
SD(Function & func, std::vector<double> pos, double conval_ = 1e-5);
protected:
virtual void setDir();
};
class CG : public Grad {
public:
CG(Function & func, std::vector<double> pos, double conval_ = 1e-5);
protected:
virtual void setDir();
virtual void updateParams();
double beta;
};
class CGPR : public CG {
public:
CGPR(Function & func, std::vector<double> pos, double conval_ = 1e-5);
protected:
virtual void updateParams();
};
void printpos(std::vector<double> pos, std::ostream & out = std::cout);
#endif