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

error in batch_filter when using data with missing values #284

Open
crystal-butler opened this issue Jan 30, 2023 · 2 comments
Open

error in batch_filter when using data with missing values #284

crystal-butler opened this issue Jan 30, 2023 · 2 comments

Comments

@crystal-butler
Copy link

I have created a second order Kalman filter for 3-dimensional data that I can successfully apply using batch_filter() if I fill missing values in the input first. But if I try running the filter by assigning None to the missing values with df.replace(np.nan, None) (before turning my measurements into a list), I get the error:

TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

The call stack tracing the error is:

Xs, Ps, Xs_prior, Ps_prior = tracker.batch_filter(body8_joint_measurements)
self.update(z, R=R, H=H)
self.y = z - dot(H, self.x)

I found the related issue and fix for missing values using masked arrays in linear_case_filterpy.ipynb example, but should batch_filter() be working as-is when missing values are filled with None?

@jamieas
Copy link

jamieas commented Feb 20, 2023

It looks like batch_filter actually wants a list of measurements with None wherever there are missing measurements, as opposed to an array with None as values in the array. However, if you insert None, you get

ValueError: setting an array element with a sequence.

due to the line n = np.size(zs, 0) here:

https://github.com/rlabbe/filterpy/blob/master/filterpy/kalman/kalman_filter.py#L1744

@rlabbe does it make sense to change this to n = len(zs)?

@Jonny-air
Copy link

That didn't fix the issue for me. However a quick fix would be to check if any element of z is nan in the update fuction (and all other occurences)

replace if z is None: with if z is None or np.isnan(z).any():

That would achieve the expected behavior. Was there a particular motivation for not doing that?

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

3 participants