11 Eigen::MatrixXd KalmanFilter::ComputeGain(Eigen::MatrixXd
const& HP,
12 std::shared_ptr<muq::Modeling::LinearOperator> H,
13 Eigen::Ref<const Eigen::MatrixXd>
const& obsCov)
16 Eigen::MatrixXd S = H->Apply( HP.transpose() );
18 if((obsCov.rows()==1)||(obsCov.cols()==1)){
19 S += obsCov.asDiagonal();
24 Eigen::LDLT<Eigen::MatrixXd> solver(S);
25 Eigen::MatrixXd K = solver.solve( HP ).transpose();
32 std::pair<Eigen::VectorXd, Eigen::MatrixXd> KalmanFilter::Analyze(std::pair<Eigen::VectorXd, Eigen::MatrixXd>
const& dist,
33 std::shared_ptr<muq::Modeling::LinearOperator> H,
34 Eigen::Ref<const Eigen::VectorXd>
const& obsMean,
35 Eigen::Ref<const Eigen::MatrixXd>
const& obsCov)
39 const int obsDim = std::max(obsCov.rows(), obsCov.cols());
40 if(H->rows() != obsDim)
41 throw muq::WrongSizeError(
"In KalmanFilter::Analyze: The size of the observation noise covariance does not match the size of the observation operator. The observation operator returns a vector with " +
std::to_string(H->rows()) +
" components, but the noise covariance is a " +
std::to_string(obsDim) +
"x" +
std::to_string(obsDim) +
" matrix.");
43 if(H->cols() != dist.first.rows())
46 Eigen::VectorXd y = obsMean - H->Apply(dist.first);
48 Eigen::MatrixXd HP = H->Apply(dist.second);
51 Eigen::MatrixXd K = ComputeGain(HP, H, obsCov);
54 std::pair<Eigen::VectorXd, Eigen::MatrixXd> output;
56 output.first = dist.first + K*y;
58 output.second = dist.second - K*HP;
Exception to throw when matrices, vectors, or arrays are the wrong size.
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values