adaptive_moment_estimation.h
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// A D A P T I V E M O M E N T E S T I M A T I O N
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#ifndef ADAPTIVEMOMENTESTIMATION_H
10#define ADAPTIVEMOMENTESTIMATION_H
11
12// System includes
13
14#include <string>
15#include <sstream>
16#include <iostream>
17#include <fstream>
18#include <algorithm>
19#include <functional>
20#include <limits>
21#include <cmath>
22#include <ctime>
23#include <chrono>
24#include <time.h>
25#include <iostream>
26#include <ctime>
27#include <ratio>
28#include <chrono>
29
30// OpenNN includes
31
32#include "loss_index.h"
33#include "optimization_algorithm.h"
34#include "config.h"
35
36namespace OpenNN
37{
38
39struct AdaptiveMomentEstimationData;
40
43
51
53{
54
55public:
56
57 // Constructors
58
59 explicit AdaptiveMomentEstimation();
60
62
64
65 // Training operators
66
67 const type& get_initial_learning_rate() const;
68 const type& get_beta_1() const;
69 const type& get_beta_2() const;
70 const type& get_epsilon() const;
71
72 // Stopping criteria
73
74 const type& get_loss_goal() const;
75 const type& get_maximum_time() const;
76
77 // Set methods
78
80
81 void set_batch_samples_number(const Index& new_batch_samples_number);
82
83 void set_default();
84
85 // Get methods
86
87 Index get_batch_samples_number() const;
88
89 // Training operators
90
91 void set_initial_learning_rate(const type&);
92 void set_beta_1(const type&);
93 void set_beta_2(const type&);
94 void set_epsilon(const type&);
95
96 // Training parameters
97
98 void set_maximum_epochs_number(const Index&);
99
100 // Stopping criteria
101
102 void set_loss_goal(const type&);
103 void set_maximum_time(const type&);
104
105 // Training methods
106
108
110
112
113 // Serialization methods
114
115 Tensor<string, 2> to_string_matrix() const;
116
117 void from_XML(const tinyxml2::XMLDocument&);
118
119 void write_XML(tinyxml2::XMLPrinter&) const;
120
123
124private:
125
126 // TRAINING OPERATORS
127
129
130 type initial_learning_rate = static_cast<type>(0.001);
131
133
134 type initial_decay = type(0);
135
137
138 type beta_1 = static_cast<type>(0.9);
139
141
142 type beta_2 = static_cast<type>(0.999);
143
145
146 type epsilon =static_cast<type>(1.e-7);
147
148 // Stopping criteria
149
151
152 type training_loss_goal = type(0);
153
155
157
159
160 Index maximum_selection_failures = numeric_limits<Index>::max();
161
163
164 type maximum_time = type(3600);
165
167
169
170#ifdef OPENNN_CUDA
171 #include "../../opennn-cuda/opennn-cuda/adaptive_moment_estimation_cuda.h"
172#endif
173
174};
175
176
178{
180
182
184
186
187 void set(AdaptiveMomentEstimation*);
188
189 void print() const;
190
191 AdaptiveMomentEstimation* adaptive_moment_estimation_pointer = nullptr;
192
193 Index learning_rate_iteration = 0;
194
195 Tensor<type, 1> gradient_exponential_decay;
196 Tensor<type, 1> square_gradient_exponential_decay;
197
198 Index iteration;
199};
200
201}
202
203#endif
const type & get_epsilon() const
Returns epsilon.
const type & get_maximum_time() const
Returns the maximum training time.
const type & get_beta_2() const
Returns beta 2.
void from_XML(const tinyxml2::XMLDocument &)
void set_default()
Sets the members of the optimization algorithm object to their default values.
type initial_learning_rate
Initial learning rate.
const type & get_beta_1() const
Returns beta 1.
Tensor< string, 2 > to_string_matrix() const
Writes as matrix of strings the most representative atributes.
type beta_1
Exponential decay over gradient estimates.
string write_optimization_algorithm_type() const
Return the algorithm optimum for your model.
type epsilon
Small number to prevent any division by zero.
void set_batch_samples_number(const Index &new_batch_samples_number)
Set number of samples in each batch. Default 1000.
type maximum_time
Maximum training time. It is used as a stopping criterion.
void update_parameters(LossIndexBackPropagation &, AdaptiveMomentEstimationData &)
Update iteration parameters.
type initial_decay
Learning rate decay over each update.
type training_loss_goal
Goal value for the loss. It is used as a stopping criterion.
Index maximum_epochs_number
Maximum epochs number.
void write_XML(tinyxml2::XMLPrinter &) const
Index batch_samples_number
Training and selection batch size.
Index maximum_selection_failures
Maximum number of times when selection error increases.
const type & get_initial_learning_rate() const
Returns the initial learning rate.
type beta_2
Exponential decay over square gradient estimates.
This abstract class represents the concept of loss index composed of an error term and a regularizati...
Definition: loss_index.h:48
This structure contains the optimization algorithm results.