27KalmanFilter::KalmanFilter(
size_t const sizeState,
51 throw runtime_error(
"ERROR: Unknown Kalman filter type.\n");
56 throw runtime_error(
"ERROR: Wrong Kalman filter dimensions.\n");
99 new (
xi) Map<VectorXd const>(error, size);
112 size_t const columns)
114 new (
H) Map<MatrixXd const>(jacobian,
sizeState, columns);
134 X =
P.selfadjointView<Lower>() * (*
H);
138 MatrixXd A =
H->transpose() *
X;
162 P.noalias() -=
K *
X.transpose();
243 double Pasym = 0.5 * (
P -
P.transpose()).array().abs().mean();
244 double Pdiag =
P.diagonal().array().abs().sum();
245 double Poffdiag = (
P.array().abs().sum() - Pdiag)
248 double Kmean =
K.array().abs().mean();
250 string s =
strpr(
"%10zu %10zu %16.8E %16.8E %16.8E %16.8E %16.8E",
251 epoch,
numUpdates, Pdiag, Poffdiag, Pasym, Kmean,
q);
267 vector<string> header;
269 vector<string> title;
270 vector<string> colName;
271 vector<string> colInfo;
272 vector<size_t> colSize;
273 title.push_back(
"Kalman filter status report.");
274 colSize.push_back(10);
275 colName.push_back(
"epoch");
276 colInfo.push_back(
"Training epoch.");
277 colSize.push_back(10);
278 colName.push_back(
"nupdates");
279 colInfo.push_back(
"Number of updates performed.");
280 colSize.push_back(16);
281 colName.push_back(
"Pdiag");
282 colInfo.push_back(
"Mean of absolute diagonal values of error covariance "
284 colSize.push_back(16);
285 colName.push_back(
"Poffdiag");
286 colInfo.push_back(
"Mean of absolute off-diagonal values of error "
287 "covariance matrix P.");
288 colSize.push_back(16);
289 colName.push_back(
"Pasym");
290 colInfo.push_back(
"Asymmetry of P, i.e. mean of absolute values of "
291 "asymmetric part 0.5*(P - P^T).");
292 colSize.push_back(16);
293 colName.push_back(
"Kmean");
294 colInfo.push_back(
"Mean of abolute compontents of Kalman gain matrix K.");
295 colSize.push_back(16);
296 colName.push_back(
"q");
297 colInfo.push_back(
"Magnitude of process noise (= diagonal entries of Q).");
300 colSize.push_back(16);
301 colName.push_back(
"eta");
302 colInfo.push_back(
"Learning rate.");
306 colSize.push_back(16);
307 colName.push_back(
"lambda");
308 colInfo.push_back(
"Forgetting factor for fading memory KF.");
309 colSize.push_back(16);
310 colName.push_back(
"kgamma");
311 colInfo.push_back(
"Forgetting gain k * gamma(k).");
324 v.push_back(
strpr(
"KalmanType::KT_STANDARD (%d)\n",
type));
328 v.push_back(
strpr(
"q0 = %12.4E\n",
q0 ));
329 v.push_back(
strpr(
"qtau = %12.4E\n",
qtau ));
330 v.push_back(
strpr(
"qmin = %12.4E\n",
qmin ));
331 v.push_back(
strpr(
"eta0 = %12.4E\n",
eta0 ));
337 v.push_back(
strpr(
"KalmanType::KT_FADINGMEMORY (%d)\n",
type));
341 v.push_back(
strpr(
"q0 = %12.4E\n",
q0 ));
342 v.push_back(
strpr(
"qtau = %12.4E\n",
qtau ));
343 v.push_back(
strpr(
"qmin = %12.4E\n",
qmin ));
345 v.push_back(
strpr(
"nu = %12.4E\n",
nu ));
347 v.push_back(
strpr(
"OpenMP threads used: %d\n", nbThreads()));
void update()
Update error covariance matrix and state vector.
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.
double eta0
Learning rate initial value .
Eigen::Map< Eigen::MatrixXd const > * H
Derivative matrix.
double nu
Parameter for fading memory Kalman filter.
double qtau
Process noise exponential decay parameter .
std::string status(std::size_t epoch) const
Status report.
std::size_t sizeObservation
Size of observation (measurement) vector.
KalmanType type
Kalman filter type.
Eigen::Map< Eigen::VectorXd > * w
State vector.
double q0
Process noise initial value .
double lambda
Forgetting factor for fading memory Kalman filter.
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.
Eigen::MatrixXd X
Intermediate result X = P . H.
void setState(double *state)
Set pointer to current state.
std::vector< std::string > statusHeader() const
Header for status report file.
double etatau
Learning rate exponential increase parameter .
double etamax
Learning rate maximum value .
double gamma
Forgetting gain factor gamma for fading memory Kalman filter.
std::vector< std::string > info() const
Information about Kalman filter settings.
void setError(double const *const error)
Set pointer to current error vector.
std::size_t numUpdates
Total number of updates performed.
KalmanType
Enumerate different Kalman filter types.
@ KT_STANDARD
Regular Kalman filter.
@ KT_FADINGMEMORY
Kalman filtering with fading memory modification.
double qmin
Process noise minimum value .
void setSizeObservation(std::size_t const sizeObservation)
Set observation vector size.
Eigen::MatrixXd K
Kalman gain matrix.
double eta
Learning rate .
double epsilon
Error covariance initialization parameter .
Eigen::Map< Eigen::VectorXd const > * xi
Error vector.
Eigen::MatrixXd P
Error covariance matrix.
virtual ~KalmanFilter()
Destructor.
void setJacobian(double const *const jacobian)
Set pointer to current Jacobi matrix.
Base class for different weight update methods.
std::string prefix
Prefix for timing stopwatches.
std::size_t sizeState
Number of neural network connections (weights + biases).
bool timingReset
Internal loop timer reset switch.
std::map< std::string, Stopwatch > sw
Stopwatch map for timing.
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)