n2p2 - A neural network potential package
|
Weight updates based on simple gradient descent methods. More...
#include <GradientDescent.h>
Public Types | |
enum | DescentType { DT_FIXED , DT_ADAM } |
Enumerate different gradient descent variants. More... | |
Public Member Functions | |
GradientDescent (std::size_t const sizeState, DescentType const type) | |
GradientDescent class constructor. More... | |
virtual | ~GradientDescent () |
Destructor. More... | |
void | setState (double *state) |
Set pointer to current state. More... | |
void | setError (double const *const error, std::size_t const size=1) |
Set pointer to current error vector. More... | |
void | setJacobian (double const *const jacobian, std::size_t const columns=1) |
Set pointer to current Jacobi matrix. More... | |
void | update () |
Perform connection update. More... | |
void | setParametersFixed (double const eta) |
Set parameters for fixed step gradient descent algorithm. More... | |
void | setParametersAdam (double const eta, double const beta1, double const beta2, double const epsilon) |
Set parameters for Adam algorithm. More... | |
std::string | status (std::size_t epoch) const |
Status report. More... | |
std::vector< std::string > | statusHeader () const |
Header for status report file. More... | |
std::vector< std::string > | info () const |
Information about gradient descent settings. More... | |
Public Member Functions inherited from nnp::Updater | |
virtual void | setState (double *state)=0 |
Set pointer to current state. More... | |
virtual void | setError (double const *const error, std::size_t const size=1)=0 |
Set pointer to current error vector. More... | |
virtual void | setJacobian (double const *const jacobian, std::size_t const columns=1)=0 |
Set pointer to current Jacobi matrix. More... | |
virtual void | update ()=0 |
Perform single update of state vector. More... | |
virtual std::string | status (std::size_t epoch) const =0 |
Status report. More... | |
virtual std::vector< std::string > | statusHeader () const =0 |
Header for status report file. More... | |
virtual std::vector< std::string > | info () const =0 |
Information about this updater. More... | |
virtual void | setupTiming (std::string const &prefix="upd") |
Activate detailed timing. More... | |
virtual void | resetTimingLoop () |
Start a new timing loop (e.g. More... | |
virtual std::map< std::string, Stopwatch > | getTiming () const |
Return timings gathered in stopwatch map. More... | |
Private Attributes | |
DescentType | type |
double | eta |
Learning rate \(\eta\). More... | |
double | beta1 |
Decay rate 1 (Adam). More... | |
double | beta2 |
Decay rate 2 (Adam). More... | |
double | epsilon |
Small scalar. More... | |
double | eta0 |
Initial learning rate. More... | |
double | beta1t |
Decay rate 1 to the power of t (Adam). More... | |
double | beta2t |
Decay rate 2 to the power of t (Adam). More... | |
double * | state |
State vector pointer. More... | |
double const * | error |
Error pointer (single double value). More... | |
double const * | gradient |
Gradient vector pointer. More... | |
std::vector< double > | m |
First moment estimate (Adam). More... | |
std::vector< double > | v |
Second moment estimate (Adam). More... | |
Additional Inherited Members | |
Protected Member Functions inherited from nnp::Updater | |
Updater (std::size_t const sizeState) | |
Constructor. More... | |
Protected Attributes inherited from nnp::Updater | |
bool | timing |
Whether detailed timing is enabled. More... | |
bool | timingReset |
Internal loop timer reset switch. More... | |
std::size_t | sizeState |
Number of neural network connections (weights + biases). More... | |
std::string | prefix |
Prefix for timing stopwatches. More... | |
std::map< std::string, Stopwatch > | sw |
Stopwatch map for timing. More... | |
Weight updates based on simple gradient descent methods.
Definition at line 29 of file GradientDescent.h.
Enumerate different gradient descent variants.
Enumerator | |
---|---|
DT_FIXED | Fixed step size. |
DT_ADAM | Adaptive moment estimation (Adam). |
Definition at line 33 of file GradientDescent.h.
GradientDescent::GradientDescent | ( | std::size_t const | sizeState, |
DescentType const | type | ||
) |
GradientDescent class constructor.
[in] | sizeState | Number of neural network connections (weights and biases). |
[in] | type | Descent type used for step size. |
Definition at line 25 of file GradientDescent.cpp.
References DT_ADAM, DT_FIXED, m, nnp::Updater::sizeState, type, and v.
|
inlinevirtual |
|
virtual |
Set pointer to current state.
[in,out] | state | Pointer to state vector (weights vector), will be changed in-place upon calling update(). |
Implements nnp::Updater.
Definition at line 58 of file GradientDescent.cpp.
References state.
|
virtual |
Set pointer to current error vector.
[in] | error | Pointer to error (difference between reference and neural network potential output). |
[in] | size | Number of error vector entries. |
Implements nnp::Updater.
Definition at line 65 of file GradientDescent.cpp.
References error.
|
virtual |
Set pointer to current Jacobi matrix.
[in] | jacobian | Derivatives of error with respect to weights. |
[in] | columns | Number of gradients provided. |
Implements nnp::Updater.
Definition at line 73 of file GradientDescent.cpp.
References gradient.
|
virtual |
Perform connection update.
Update the connections via steepest descent method.
Implements nnp::Updater.
Definition at line 81 of file GradientDescent.cpp.
References beta1, beta1t, beta2, beta2t, DT_ADAM, DT_FIXED, epsilon, eta, eta0, gradient, m, nnp::Updater::sizeState, state, type, and v.
void GradientDescent::setParametersFixed | ( | double const | eta | ) |
Set parameters for fixed step gradient descent algorithm.
[in] | eta | Step size = ratio of gradient subtracted from current weights. |
Definition at line 120 of file GradientDescent.cpp.
References eta.
Referenced by nnp::Training::setupTraining().
void GradientDescent::setParametersAdam | ( | double const | eta, |
double const | beta1, | ||
double const | beta2, | ||
double const | epsilon | ||
) |
Set parameters for Adam algorithm.
[in] | eta | Step size (corresponds to \(\alpha\) in Adam publication). |
[in] | beta1 | Decay rate 1 (first moment). |
[in] | beta2 | Decay rate 2 (second moment). |
[in] | epsilon | Small scalar. |
Definition at line 127 of file GradientDescent.cpp.
References beta1, beta1t, beta2, beta2t, epsilon, eta, and eta0.
Referenced by nnp::Training::setupTraining().
|
virtual |
Status report.
[in] | epoch | Current epoch. |
Implements nnp::Updater.
Definition at line 144 of file GradientDescent.cpp.
References beta1t, beta2t, DT_ADAM, eta, m, nnp::Updater::sizeState, nnp::strpr(), type, and v.
|
virtual |
Header for status report file.
Implements nnp::Updater.
Definition at line 167 of file GradientDescent.cpp.
References nnp::createFileHeader(), DT_ADAM, and type.
|
virtual |
Information about gradient descent settings.
Implements nnp::Updater.
Definition at line 202 of file GradientDescent.cpp.
References beta1, beta2, DT_ADAM, DT_FIXED, epsilon, eta, nnp::Updater::sizeState, nnp::strpr(), type, and v.
|
private |
Definition at line 118 of file GradientDescent.h.
Referenced by GradientDescent(), info(), status(), statusHeader(), and update().
|
private |
Learning rate \(\eta\).
Definition at line 120 of file GradientDescent.h.
Referenced by info(), setParametersAdam(), setParametersFixed(), status(), and update().
|
private |
Decay rate 1 (Adam).
Definition at line 122 of file GradientDescent.h.
Referenced by info(), setParametersAdam(), and update().
|
private |
Decay rate 2 (Adam).
Definition at line 124 of file GradientDescent.h.
Referenced by info(), setParametersAdam(), and update().
|
private |
Small scalar.
Definition at line 126 of file GradientDescent.h.
Referenced by info(), setParametersAdam(), and update().
|
private |
Initial learning rate.
Definition at line 128 of file GradientDescent.h.
Referenced by setParametersAdam(), and update().
|
private |
Decay rate 1 to the power of t (Adam).
Definition at line 130 of file GradientDescent.h.
Referenced by setParametersAdam(), status(), and update().
|
private |
Decay rate 2 to the power of t (Adam).
Definition at line 132 of file GradientDescent.h.
Referenced by setParametersAdam(), status(), and update().
|
private |
State vector pointer.
Definition at line 134 of file GradientDescent.h.
Referenced by setState(), and update().
|
private |
Error pointer (single double value).
Definition at line 136 of file GradientDescent.h.
Referenced by setError().
|
private |
Gradient vector pointer.
Definition at line 138 of file GradientDescent.h.
Referenced by setJacobian(), and update().
|
private |
First moment estimate (Adam).
Definition at line 140 of file GradientDescent.h.
Referenced by GradientDescent(), status(), and update().
|
private |
Second moment estimate (Adam).
Definition at line 142 of file GradientDescent.h.
Referenced by GradientDescent(), info(), status(), and update().