strawlab / adskalman-rs

Kalman filter implementation in Rust
Apache License 2.0
60 stars 8 forks source link

Covariance Matrix Symmetry assertion. #18

Closed jose-rincon closed 8 months ago

jose-rincon commented 8 months ago

We've encountered a scenario where our covariance matrix fails the symmetry assertion defined in the debug macro debug_assert_symmetric!. Instead of halting the execution with assert_relative_eq, we are exploring the possibility of having a warning issued, allowing the Kalman filter to continue functioning within our pipeline.

We believe this adjustment would enhance the robustness and flexibility of your library in real-world scenarios, allowing users to choose whether to halt on this assertion or receive a warning.

If you find this proposal acceptable, we are more than willing to contribute to the implementation or provide additional information to facilitate the process.

Thank you for your time and consideration. We appreciate the valuable work you do on maintaining this repository. Best regards, Jose Rincon.

astraw commented 8 months ago

Dear Jose, I'm not sure how allowing non-symmetric covariance matrices will improve robustness. That said, I don't think the current panic behavior is the right thing to do. I would be OK with returning an Err(ErrorKind::CovarianceNotPositiveSemiDefinite.into()) error.

What CovarianceUpdateMethod are you using? I would be surprised if you get this error with the Joseph Form or the forced symmetric mode. Or are you starting with non-symmetric covariance matrices?

jose-rincon commented 8 months ago

Hi Andrew. Thank you so much for your prompt response. Considering your suggestion of returning an Err(ErrorKind::CovarianceNotPositiveSemiDefinite.into()) error, we believe this would indeed be a more graceful way of handling the situation without causing a panic. We are currently utilizing the Joseph Form for covariance updates. We look forward to your further guidance on this matter. thank you! We are starting with symmetric covariance matrices.

astraw commented 8 months ago

Dear Jose, OK, I've made the change discussed in 8e1ab7e2a9d38b1fd54dfbd94721020836bd9717. Thanks for the suggestion. I published this in version 0.15.1.

astraw commented 8 months ago

By the way, I learned about the Joseph form in this fantasic book: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python/blob/master/07-Kalman-Filter-Math.ipynb

jose-rincon commented 8 months ago

Thank you so much Andrew! And thank you so much for sharing the book. I appreciate it!