Skip to content
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

dot #424

Closed
wangchunlin opened this issue Jun 24, 2022 · 4 comments
Closed

dot #424

wangchunlin opened this issue Jun 24, 2022 · 4 comments

Comments

@wangchunlin
Copy link

In Kalman_filter.update(), dot(PHT,self.SI) does not work because PHT is 21 whilst self.SI is 11. so dot can not compute these two matrixs with different dimensions. Therefore, we should change it to PHT*self.SI. This is also true of other functions such as dot(self.K,self.y)

@rlabbe
Copy link
Owner

rlabbe commented Jun 24, 2022

Can you explain what you mean? dot is implementing matrix multiplications. In general, MxN @ NxP yields a shape of MxP the 2nd dimension of the first matrix must equal the 1st dimension of the second. So, 2x1 @ 1x1 yields a 2x1 result, which is correct.

'*' is element wise multiplication, and definitely not what you want to do.

I don't know 'does not work' means. You think the mathematical result is wrong, you are getting an exception, or ? If you are getting an exception, one of your matrices has the wrong dimensionality. Share an example and we can help you through it.

@wangchunlin
Copy link
Author

For example, in EKF.update(), self.K = PHT.dot(linalg.inv(self.S)) pops up an error: ValueError: shapes (3,) and (1,1) not aligned: 3 (dim 0) != 1 (dim 0)....In this code, the shape of PHT is (3,) whilst self.S is (1,1).

@wangchunlin
Copy link
Author

i met many such ValueError when using dot function.

@rlabbe
Copy link
Owner

rlabbe commented Jun 29, 2022

The filter needs to be designed correctly. You are either initializing it with the wrong values or your hx or jacobian is returning something of the wrong shape.

you can

print(ekf)

to see all of the matrices and identify where the problem is.

I'm going to close this as matrix multiplication is the correct behavior, not element-wise multiplication. But feel free to respond with example code if you want me to take a look. In your example PHT is shape 3, which is almost certainly wrong. It makes me think your H is designed wrong, or maybe P. H is supposed to convert P to an array shaped the same as your measurement. If PHT is shape 3, that tells me you are expecting z to be shape 3,. But then the shape of S is 1, and S is the covariance of the system in measurement, so it implies the shape of z is 1,. This is not consistent, and so it raises an exception. The math is correct, the input is wrong.

@rlabbe rlabbe closed this as completed Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants