21 #ifndef KALMAN_FILTER__ESRCF_HPP_
22 #define KALMAN_FILTER__ESRCF_HPP_
37 namespace kalman_filter
47 template<
int32_t NumStates,
int32_t ProcessNoiseDim>
59 const Eigen::Matrix<float32_t, NumStates, ProcessNoiseDim> & GQ_chol_prod)
60 : m_model_ptr{&model},
61 m_is_mat1_covariance{
false},
62 m_B_mat{GQ_chol_prod},
63 m_GQ_factor{GQ_chol_prod} {}
72 const Eigen::Matrix<float32_t, NumStates, ProcessNoiseDim> & GQ_chol_prod,
73 const state_vec_t & x0,
74 const square_mat_t & P0_chol)
75 :
Esrcf{model, GQ_chol_prod}
82 void reset(
const state_vec_t & x0)
84 m_model_ptr->reset(x0);
91 void reset(
const state_vec_t & x0,
const square_mat_t & P0_chol)
94 m_square_mat2 = P0_chol;
95 m_is_mat1_covariance =
false;
102 return m_is_mat1_covariance ? m_square_mat1 : m_square_mat2;
110 const square_mat_t & cov_mat = m_is_mat1_covariance ? m_square_mat1 : m_square_mat2;
111 square_mat_t & jac_mat = m_is_mat1_covariance ? m_square_mat2 : m_square_mat1;
113 m_model_ptr->compute_jacobian_and_predict(jac_mat, dt);
116 jac_mat = jac_mat * cov_mat;
118 m_srcf_core.right_lower_triangularize_matrices(jac_mat, m_B_mat);
119 m_is_mat1_covariance = !m_is_mat1_covariance;
120 m_B_mat = m_GQ_factor;
128 template<
int32_t NumObs>
130 const Eigen::Matrix<float32_t, NumObs, 1U> & z,
131 const Eigen::Matrix<float32_t, NumObs, NumStates> & H,
132 const Eigen::Matrix<float32_t, NumObs, 1U> & R_diag)
134 square_mat_t & cov_mat = m_is_mat1_covariance ? m_square_mat1 : m_square_mat2;
136 m_state_tmp = m_model_ptr->get_state();
140 likelihood += m_srcf_core.scalar_update(
148 m_model_ptr->reset(m_state_tmp);
161 m_state_tmp = m_model_ptr->get_state();
162 m_state_tmp -= x_mix;
163 const float32_t sq_prob = sqrtf(self_transition_prob);
164 square_mat_t & cov = m_is_mat1_covariance ? m_square_mat1 : m_square_mat2;
166 m_state_tmp *= sq_prob;
167 m_srcf_core.right_lower_triangularize_matrices(cov, m_state_tmp);
168 m_model_ptr->reset(x_mix);
184 const state_vec_t & x_other,
185 square_mat_t & cov_other,
186 const index_t rank_other = NumStates)
189 m_state_tmp = x_other;
190 m_state_tmp -= m_model_ptr->get_state();
192 const float32_t sq_prob = sqrtf(other_transition_prob);
193 m_state_tmp *= sq_prob;
194 cov_other *= sq_prob;
195 square_mat_t & cov = m_is_mat1_covariance ? m_square_mat1 : m_square_mat2;
199 m_srcf_core.zero_row(cov, m_state_tmp, i,
index_t(), 1U);
200 m_srcf_core.zero_row(cov, cov_other, i,
index_t(), rank_other);
202 m_srcf_core.zero_row(cov, cov, i, i + 1, NumStates);
209 state_vec_t m_state_tmp;
210 square_mat_t m_square_mat1;
211 square_mat_t m_square_mat2;
213 Eigen::Matrix<float32_t, NumStates, ProcessNoiseDim> m_B_mat;
214 Eigen::Matrix<float32_t, NumStates, ProcessNoiseDim> m_GQ_factor;
215 static_assert(NumStates > 0U,
"must have positive number of states");
216 static_assert(ProcessNoiseDim > 0U,
"must have positive number of process noise dimensions");
222 #endif // KALMAN_FILTER__ESRCF_HPP_