-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kalman.py: column vector or row vector? #81
Comments
Could you define current_x_hat as a 1d vector instead ? Then it would be broadcasted to a 2x1 array or 1x2 array depending on the orientation of To me, one good feature of numpy is that it has |
@albop As you suggest, I dropped conversion to 2d array in the |
Thanks for letting me know about this error. In the end I just corrected the exercise by flattening the vector ex post. I didn't flatten everything inside Kalman because I want the inner workings to be transparent --- this module is more instructive rather than for heavy duty use. |
Hi,
in the study group session today, we found some unexpected behavior in the script given in the solution to Exercise 3 in "A First Look at the Kalman Filter".
I think I identified the problem:
kn.current_x_hat
has to be "flattened":kn.current_x_hat
is a column vector (2x1), whilex
is a row vector (1x2), sox - kn.current_x_hat
becomes 2x2, and hencenp.sum((x - kn.current_x_hat)**2)
gets doubled.Here's how we got the "unexpected behavior":
http://nbviewer.ipython.org/gist/oyamad/1f9b66fda3679f85f794
(Please see the second half part starting with "Exercise 3".)
One may say that the problem is caused by the implementation design of
Kalman
, wherecurrent_xhat
is implemented as a column vector. Mathematically it is legitimate, but in python we do not have to care in many cases as numpy guesses correctly to compute e.g.np.dot(A, x)
even ifx
is a row vector. It might be better to consistently stick to row vectors.The text was updated successfully, but these errors were encountered: