n2p2 - A neural network potential package
|
Implementation of the Kalman filter method. More...
#include <KalmanFilter.h>
Public Types | |
enum | KalmanType { KT_STANDARD , KT_FADINGMEMORY } |
Enumerate different Kalman filter types. More... | |
Public Member Functions | |
KalmanFilter (std::size_t const sizeState, KalmanType const type) | |
Kalman filter class constructor. More... | |
virtual | ~KalmanFilter () |
Destructor. More... | |
void | setSizeObservation (std::size_t const sizeObservation) |
Set observation vector size. More... | |
void | setState (double *state) |
Set pointer to current state. More... | |
void | setError (double const *const error) |
Set pointer to current error vector. More... | |
void | setError (double const *const error, std::size_t const size) |
Set pointer to current error vector. More... | |
void | setJacobian (double const *const jacobian) |
Set pointer to current Jacobi matrix. More... | |
void | setJacobian (double const *const jacobian, std::size_t const columns) |
Set pointer to current Jacobi matrix. More... | |
void | update () |
Update error covariance matrix and state vector. More... | |
void | update (std::size_t const sizeObservation) |
Update error covariance matrix and state vector. More... | |
void | setParametersStandard (double const epsilon, double const q0, double const qtau, double const qmin, double const eta0, double const etatau, double const etamax) |
Set parameters for standard Kalman filter. More... | |
void | setParametersFadingMemory (double const epsilon, double const q0, double const qtau, double const qmin, double const lambda, double const nu) |
Set parameters for fading memory Kalman filter. 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 Kalman filter settings. More... | |
KalmanType | getType () const |
Getter for type. More... | |
std::size_t | getSizeObservation () const |
Getter for sizeObservation. More... | |
std::size_t | getNumUpdates () const |
Getter for numUpdates. More... | |
double | getEta () const |
Getter for eta. More... | |
double | getEpsilon () const |
Getter for epsilon. More... | |
double | getQ0 () const |
Getter for q0. More... | |
double | getQtau () const |
Getter for qtau. More... | |
double | getQmin () const |
Getter for qmin. More... | |
double | getLambda () const |
Getter for lambda. More... | |
double | getNu () const |
Getter for nu. More... | |
double | getGamma () const |
Getter for gamma. 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 | |
KalmanType | type |
Kalman filter type. More... | |
std::size_t | sizeObservation |
Size of observation (measurement) vector. More... | |
std::size_t | numUpdates |
Total number of updates performed. More... | |
double | epsilon |
Error covariance initialization parameter \(\epsilon\). More... | |
double | q |
Process noise \(q\). More... | |
double | q0 |
Process noise initial value \(q_0\). More... | |
double | qtau |
Process noise exponential decay parameter \(q_{\tau}\). More... | |
double | qmin |
Process noise minimum value \(q_{\text{min}}\). More... | |
double | eta |
Learning rate \(\eta\). More... | |
double | eta0 |
Learning rate initial value \(\eta_0\). More... | |
double | etatau |
Learning rate exponential increase parameter \(\eta_{\tau}\). More... | |
double | etamax |
Learning rate maximum value \(\eta_{\text{max}}\). More... | |
double | lambda |
Forgetting factor for fading memory Kalman filter. More... | |
double | nu |
Parameter for fading memory Kalman filter. More... | |
double | gamma |
Forgetting gain factor gamma for fading memory Kalman filter. More... | |
Eigen::Map< Eigen::VectorXd > * | w |
State vector. More... | |
Eigen::Map< Eigen::VectorXd const > * | xi |
Error vector. More... | |
Eigen::Map< Eigen::MatrixXd const > * | H |
Derivative matrix. More... | |
Eigen::MatrixXd | P |
Error covariance matrix. More... | |
Eigen::MatrixXd | K |
Kalman gain matrix. More... | |
Eigen::MatrixXd | X |
Intermediate result X = P . H. 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... | |
Implementation of the Kalman filter method.
Definition at line 31 of file KalmanFilter.h.
Enumerate different Kalman filter types.
Enumerator | |
---|---|
KT_STANDARD | Regular Kalman filter. |
KT_FADINGMEMORY | Kalman filtering with fading memory modification. |
Definition at line 35 of file KalmanFilter.h.
KalmanFilter::KalmanFilter | ( | std::size_t const | sizeState, |
KalmanType const | type | ||
) |
Kalman filter class constructor.
[in] | sizeState | Size of the state vector w. |
[in] | type | Kalman filter type (see KalmanType). |
Definition at line 27 of file KalmanFilter.cpp.
References H, K, KT_FADINGMEMORY, KT_STANDARD, P, sizeObservation, nnp::Updater::sizeState, type, w, and xi.
|
virtual |
void KalmanFilter::setSizeObservation | ( | std::size_t const | sizeObservation | ) |
Set observation vector size.
[in] | size | Size of the observation vector. |
If the size of the observation vector is known in advance it can be set here.
Definition at line 76 of file KalmanFilter.cpp.
References sizeObservation.
Referenced by nnp::Training::update().
|
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 83 of file KalmanFilter.cpp.
References nnp::Updater::sizeState, and w.
void KalmanFilter::setError | ( | double const *const | error | ) |
Set pointer to current error vector.
[in] | error | Pointer to error (difference between reference and neural network potential output). |
Definition at line 90 of file KalmanFilter.cpp.
References setError(), and sizeObservation.
Referenced by setError().
|
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.
void KalmanFilter::setJacobian | ( | double const *const | jacobian | ) |
Set pointer to current Jacobi matrix.
[in] | jacobian | Derivatives of error with respect to weights. |
Definition at line 104 of file KalmanFilter.cpp.
References setJacobian(), and sizeObservation.
Referenced by setJacobian().
|
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.
|
virtual |
Update error covariance matrix and state vector.
Implements nnp::Updater.
Definition at line 119 of file KalmanFilter.cpp.
References sizeObservation, and update().
Referenced by update().
void nnp::KalmanFilter::update | ( | std::size_t const | sizeObservation | ) |
Update error covariance matrix and state vector.
[in] | sizeObservation | Size of the observation vector. |
void KalmanFilter::setParametersStandard | ( | double const | epsilon, |
double const | q0, | ||
double const | qtau, | ||
double const | qmin, | ||
double const | eta0, | ||
double const | etatau, | ||
double const | etamax | ||
) |
Set parameters for standard Kalman filter.
[in] | epsilon | Error covariance initialization parameter \(\epsilon\). |
[in] | q0 | Process noise initial value \(q_0\). |
[in] | qtau | Process noise exponential decay parameter \(q_{\tau}\). |
[in] | qmin | Process noise minimum value \(q_{\text{min}}\). |
[in] | eta0 | Initial learning rate \(\eta_0\). |
[in] | etatau | Learning rate exponential increase parameter \(\eta_{\tau}\). |
[in] | etamax | Learning rate maximum value \(\eta_{\text{max}}\). |
Definition at line 199 of file KalmanFilter.cpp.
References epsilon, eta, eta0, etamax, etatau, P, q, q0, qmin, and qtau.
Referenced by nnp::Training::setupTraining().
void KalmanFilter::setParametersFadingMemory | ( | double const | epsilon, |
double const | q0, | ||
double const | qtau, | ||
double const | qmin, | ||
double const | lambda, | ||
double const | nu | ||
) |
Set parameters for fading memory Kalman filter.
[in] | epsilon | Error covariance initialization parameter \(\epsilon\). |
[in] | q0 | Process noise initial value \(q_0\). |
[in] | qtau | Process noise exponential decay parameter \(q_{\tau}\). |
[in] | qmin | Process noise minimum value \(q_{\text{min}}\). |
[in] | lambda | Forgetting factor \(\lambda\). |
[in] | nu | Fading memory parameter \(\nu\). |
Definition at line 222 of file KalmanFilter.cpp.
References epsilon, gamma, lambda, nu, P, q, q0, qmin, and qtau.
Referenced by nnp::Training::setupTraining().
|
virtual |
Status report.
[in] | epoch | Current epoch. |
Implements nnp::Updater.
Definition at line 243 of file KalmanFilter.cpp.
References eta, gamma, K, KT_FADINGMEMORY, KT_STANDARD, lambda, numUpdates, P, q, nnp::Updater::sizeState, nnp::strpr(), and type.
|
virtual |
Header for status report file.
Implements nnp::Updater.
Definition at line 268 of file KalmanFilter.cpp.
References nnp::createFileHeader(), KT_FADINGMEMORY, KT_STANDARD, and type.
|
virtual |
Information about Kalman filter settings.
Implements nnp::Updater.
Definition at line 321 of file KalmanFilter.cpp.
References epsilon, eta0, etamax, etatau, KT_FADINGMEMORY, KT_STANDARD, lambda, nu, q0, qmin, qtau, sizeObservation, nnp::Updater::sizeState, nnp::strpr(), and type.
|
inline |
|
inline |
Getter for sizeObservation.
Definition at line 248 of file KalmanFilter.h.
References sizeObservation.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
double nnp::KalmanFilter::getGamma | ( | ) | const |
Getter for gamma.
|
private |
Kalman filter type.
Definition at line 196 of file KalmanFilter.h.
Referenced by getType(), info(), KalmanFilter(), status(), and statusHeader().
|
private |
Size of observation (measurement) vector.
Definition at line 198 of file KalmanFilter.h.
Referenced by getSizeObservation(), info(), KalmanFilter(), setError(), setJacobian(), setSizeObservation(), and update().
|
private |
Total number of updates performed.
Definition at line 200 of file KalmanFilter.h.
Referenced by getNumUpdates(), and status().
|
private |
Error covariance initialization parameter \(\epsilon\).
Definition at line 202 of file KalmanFilter.h.
Referenced by getEpsilon(), info(), setParametersFadingMemory(), and setParametersStandard().
|
private |
Process noise \(q\).
Definition at line 204 of file KalmanFilter.h.
Referenced by setParametersFadingMemory(), setParametersStandard(), and status().
|
private |
Process noise initial value \(q_0\).
Definition at line 206 of file KalmanFilter.h.
Referenced by getQ0(), info(), setParametersFadingMemory(), and setParametersStandard().
|
private |
Process noise exponential decay parameter \(q_{\tau}\).
Definition at line 208 of file KalmanFilter.h.
Referenced by getQtau(), info(), setParametersFadingMemory(), and setParametersStandard().
|
private |
Process noise minimum value \(q_{\text{min}}\).
Definition at line 210 of file KalmanFilter.h.
Referenced by getQmin(), info(), setParametersFadingMemory(), and setParametersStandard().
|
private |
Learning rate \(\eta\).
Definition at line 212 of file KalmanFilter.h.
Referenced by getEta(), setParametersStandard(), and status().
|
private |
Learning rate initial value \(\eta_0\).
Definition at line 214 of file KalmanFilter.h.
Referenced by info(), and setParametersStandard().
|
private |
Learning rate exponential increase parameter \(\eta_{\tau}\).
Definition at line 216 of file KalmanFilter.h.
Referenced by info(), and setParametersStandard().
|
private |
Learning rate maximum value \(\eta_{\text{max}}\).
Definition at line 218 of file KalmanFilter.h.
Referenced by info(), and setParametersStandard().
|
private |
Forgetting factor for fading memory Kalman filter.
Definition at line 220 of file KalmanFilter.h.
Referenced by getLambda(), info(), setParametersFadingMemory(), and status().
|
private |
Parameter for fading memory Kalman filter.
Definition at line 222 of file KalmanFilter.h.
Referenced by getNu(), info(), and setParametersFadingMemory().
|
private |
Forgetting gain factor gamma for fading memory Kalman filter.
Definition at line 224 of file KalmanFilter.h.
Referenced by setParametersFadingMemory(), and status().
|
private |
State vector.
Definition at line 226 of file KalmanFilter.h.
Referenced by KalmanFilter(), and setState().
|
private |
|
private |
|
private |
Error covariance matrix.
Definition at line 232 of file KalmanFilter.h.
Referenced by KalmanFilter(), setParametersFadingMemory(), setParametersStandard(), and status().
|
private |
Kalman gain matrix.
Definition at line 234 of file KalmanFilter.h.
Referenced by KalmanFilter(), and status().
|
private |
Intermediate result X = P . H.
Definition at line 236 of file KalmanFilter.h.