Newer
Older

Michal Kravcenko
committed
/**
* DESCRIPTION OF THE FILE
*
* @author Michal Kravčenko
* @date 19.2.19 -
*/
#ifndef LIB4NEURO_GRADIENTDESCENTSINGLEITEM_H
#define LIB4NEURO_GRADIENTDESCENTSINGLEITEM_H
#include "../settings.h"
#include "../constants.h"

Michal Kravcenko
committed
#include "../ErrorFunction/ErrorFunctions.h"
#include "GradientDescentBB.h"
namespace lib4neuro {
/**
*
*/
class GradientDescentSingleItem : public GradientLearningMethod {

Michal Kravcenko
committed
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
private:
/**
* Threshold for the successful ending of the optimization - deviation from minima
*/
double tolerance;
/**
*
*/
double max_error;
/**
* Number of iterations to reset step size to tolerance/10.0
*/
size_t restart_frequency;
/**
*
*/
size_t batch;
/**
*
*/
size_t iter_max;
/**
* Maximal number of iterations - optimization will stop after that, even if not converged
*/
long long int maximum_niters;
/**
* Vector of minima coordinates
*/
std::vector<double> optimal_parameters;

Michal Kravcenko
committed
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
protected:
/**
* Finds the optimal value of step-length in direction @d from position @x of function @f
* @param f
* @param x
* @param d
* @param n_elems
* @return
*/
virtual double get_optimal_step_size(lib4neuro::ErrorFunction &f, std::vector<double> &x, std::vector<double> &d, size_t n_elems);
public:
/**
* Creates an instance of Gradient Descent Optimizer (i.e. back-propagation)
* @param epsilon Threshold for the successful ending of the optimization - deviation from minima
* @param n_to_restart Number of iterations to reset step size to tolerance/10.0
* @param max_iters Maximal number of iterations - optimization will stop after that, even if not converged
*/
LIB4NEURO_API explicit GradientDescentSingleItem(double epsilon = 1e-3, size_t n_to_restart = 100, int max_iters = 1000, size_t batch = 0);
/**
* Deallocates the instance
*/
LIB4NEURO_API ~GradientDescentSingleItem();
/**
*
* @param ef
*/
LIB4NEURO_API void optimize(lib4neuro::ErrorFunction &ef, std::ofstream* ofs = nullptr) override;
/**
*
* @return
*/
LIB4NEURO_API std::shared_ptr<std::vector<double>> get_parameters() override;

Michal Kravcenko
committed
};
}
#endif //LIB4NEURO_GRADIENTDESCENTSINGLEITEM_H