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();
246 double Pasym = 0.5 * (
P -
P.transpose()).array().abs().mean();
247 double Pdiag =
P.diagonal().array().abs().sum();
248 double Poffdiag = (
P.array().abs().sum() - Pdiag)
251 double Kmean =
K.array().abs().mean();
253 string s =
strpr(
"%10zu %10zu %16.8E %16.8E %16.8E %16.8E %16.8E",
254 epoch,
numUpdates, Pdiag, Poffdiag, Pasym, Kmean,
q);
270 vector<string> header;
272 vector<string> title;
273 vector<string> colName;
274 vector<string> colInfo;
275 vector<size_t> colSize;
276 title.push_back(
"Kalman filter status report.");
277 colSize.push_back(10);
278 colName.push_back(
"epoch");
279 colInfo.push_back(
"Training epoch.");
280 colSize.push_back(10);
281 colName.push_back(
"nupdates");
282 colInfo.push_back(
"Number of updates performed.");
283 colSize.push_back(16);
284 colName.push_back(
"Pdiag");
285 colInfo.push_back(
"Mean of absolute diagonal values of error covariance "
287 colSize.push_back(16);
288 colName.push_back(
"Poffdiag");
289 colInfo.push_back(
"Mean of absolute off-diagonal values of error "
290 "covariance matrix P.");
291 colSize.push_back(16);
292 colName.push_back(
"Pasym");
293 colInfo.push_back(
"Asymmetry of P, i.e. mean of absolute values of "
294 "asymmetric part 0.5*(P - P^T).");
295 colSize.push_back(16);
296 colName.push_back(
"Kmean");
297 colInfo.push_back(
"Mean of abolute compontents of Kalman gain matrix K.");
298 colSize.push_back(16);
299 colName.push_back(
"q");
300 colInfo.push_back(
"Magnitude of process noise (= diagonal entries of Q).");
303 colSize.push_back(16);
304 colName.push_back(
"eta");
305 colInfo.push_back(
"Learning rate.");
309 colSize.push_back(16);
310 colName.push_back(
"lambda");
311 colInfo.push_back(
"Forgetting factor for fading memory KF.");
312 colSize.push_back(16);
313 colName.push_back(
"kgamma");
314 colInfo.push_back(
"Forgetting gain k * gamma(k).");
327 v.push_back(
strpr(
"KalmanType::KT_STANDARD (%d)\n",
type));
331 v.push_back(
strpr(
"q0 = %12.4E\n",
q0 ));
332 v.push_back(
strpr(
"qtau = %12.4E\n",
qtau ));
333 v.push_back(
strpr(
"qmin = %12.4E\n",
qmin ));
334 v.push_back(
strpr(
"eta0 = %12.4E\n",
eta0 ));
340 v.push_back(
strpr(
"KalmanType::KT_FADINGMEMORY (%d)\n",
type));
344 v.push_back(
strpr(
"q0 = %12.4E\n",
q0 ));
345 v.push_back(
strpr(
"qtau = %12.4E\n",
qtau ));
346 v.push_back(
strpr(
"qmin = %12.4E\n",
qmin ));
348 v.push_back(
strpr(
"nu = %12.4E\n",
nu ));
350 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)