25GradientDescent::GradientDescent(
size_t const sizeState,
41 throw runtime_error(
"ERROR: Unknown GradientDescent type.\n");
46 throw runtime_error(
"ERROR: Wrong GradientDescent dimensions.\n");
85 for (std::size_t i = 0; i <
sizeState; ++i)
92 for (std::size_t i = 0; i <
sizeState; ++i)
94 double const g = (*error) * -
gradient[i];
130 double const epsilon)
146 string s =
strpr(
"%10zu %16.8E", epoch,
eta);
152 for (std::size_t i = 0; i <
sizeState; ++i)
159 s +=
strpr(
" %16.8E %16.8E %16.8E %16.8E",
169 vector<string> header;
171 vector<string> title;
172 vector<string> colName;
173 vector<string> colInfo;
174 vector<size_t> colSize;
175 title.push_back(
"Gradient descent status report.");
176 colSize.push_back(10);
177 colName.push_back(
"epoch");
178 colInfo.push_back(
"Training epoch.");
179 colSize.push_back(16);
180 colName.push_back(
"eta");
181 colInfo.push_back(
"Step size.");
184 colSize.push_back(16);
185 colName.push_back(
"beta1t");
186 colInfo.push_back(
"Decay rate 1 to the power of t.");
187 colSize.push_back(16);
188 colName.push_back(
"beta2t");
189 colInfo.push_back(
"Decay rate 2 to the power of t.");
190 colSize.push_back(16);
191 colName.push_back(
"mag_m");
192 colInfo.push_back(
"Mean of absolute first momentum (m).");
193 colSize.push_back(16);
194 colName.push_back(
"mag_v");
195 colInfo.push_back(
"Mean of absolute second momentum (v).");
208 v.push_back(
strpr(
"GradientDescentType::DT_FIXED (%d)\n",
type));
210 v.push_back(
strpr(
"eta = %12.4E\n",
eta));
214 v.push_back(
strpr(
"GradientDescentType::DT_ADAM (%d)\n",
type));
216 v.push_back(
strpr(
"eta = %12.4E\n",
eta));
void setParametersFixed(double const eta)
Set parameters for fixed step gradient descent algorithm.
void setParametersAdam(double const eta, double const beta1, double const beta2, double const epsilon)
Set parameters for Adam algorithm.
std::string status(std::size_t epoch) const
Status report.
double epsilon
Small scalar.
DescentType
Enumerate different gradient descent variants.
@ DT_ADAM
Adaptive moment estimation (Adam).
@ DT_FIXED
Fixed step size.
std::vector< std::string > statusHeader() const
Header for status report file.
std::vector< double > v
Second moment estimate (Adam).
double beta2t
Decay rate 2 to the power of t (Adam).
double beta1t
Decay rate 1 to the power of t (Adam).
double eta0
Initial learning rate.
double eta
Learning rate .
double const * gradient
Gradient vector pointer.
double beta1
Decay rate 1 (Adam).
std::vector< double > m
First moment estimate (Adam).
void setJacobian(double const *const jacobian, std::size_t const columns=1)
Set pointer to current Jacobi matrix.
void setState(double *state)
Set pointer to current state.
double beta2
Decay rate 2 (Adam).
double const * error
Error pointer (single double value).
std::vector< std::string > info() const
Information about gradient descent settings.
double * state
State vector pointer.
void setError(double const *const error, std::size_t const size=1)
Set pointer to current error vector.
void update()
Perform connection update.
Base class for different weight update methods.
std::size_t sizeState
Number of neural network connections (weights + biases).
string strpr(const char *format,...)
String version of printf function.
vector< string > createFileHeader(vector< string > const &title, vector< size_t > const &colSize, vector< string > const &colName, vector< string > const &colInfo, char const &commentChar)