rlabbe / filterpy

Python Kalman filtering and optimal estimation library. Implements Kalman filter, particle filter, Extended Kalman filter, Unscented Kalman filter, g-h (alpha-beta), least squares, H Infinity, smoothers, and more. Has companion book 'Kalman and Bayesian Filters in Python'.
MIT License
3.23k stars 614 forks source link

Column vector shape annoyances #235

Open rlabbe opened 3 years ago

rlabbe commented 3 years ago

KalmanFilter uses a 2d column vector for x, UKF uses a 1d array. This is inconsistent. the column vector is also very annoying. If len(x)==9, batch_filter will return the mean as a [N, 9, 1] shaped array. Generally speaking you can't slice that easily because of the extra 1 dimension, and if you have a bunch of infrastructure for plotting and analysis you have to write it to handle cases where data is in the form of [N,9] (such as ground truth data) and when it is in [N, 9, 1].

I also think the 'reshape anything that isn't shaped as the code expects' is pretty disasterous. It's essentially impossible to get correct for short amounts of data (what if len(zs) is 9, good luck figuring that one out). No matter what I do, I get bug reports on the reshape functions.

I think it is okay to require x and z to be a 1-D array, period. It could break some code, so maybe a deprecation cycle, or just do it in 2.0 where I drop 2.7 support.

I'm not sure this is a good idea; do we end up with operations that generate 2d column vectors; this needs to be tested carefully.

I added all of this mostly because it is pedagogical code, and getting all the matrices right is hard. It also works as a 1d scalar kf (len(x)==1). But that is just absurd - no one should actually be doing a 1d kf using this class.