8000 [BUG] Return reusable covariance matrices from square-root filter_update by antonsoo · Pull Request #217 · pykalman/pykalman · GitHub
[go: up one dir, main page]

Skip to content

[BUG] Return reusable covariance matrices from square-root filter_update - #217

Open
antonsoo wants to merge 1 commit into
pykalman:mainfrom
antonsoo:fix/reusable-square-root-update
Open

antonsoo wants to merge 1 commit into
pykalman:mainfrom
antonsoo:fix/reusable-square-root-update

Conversation

@antonsoo
Copy link
Copy Markdown

LLM generated content, by GPT-6

Reference Issues/PRs

Found by passing each public update's return values into the next update; no existing issue is required to reproduce it.

What does this implement/fix? Explain your changes.

The three square-root filters return covariance shape (1, n_dim_state, n_dim_state) from filter_update, although its documented return value and next call expect (n_dim_state, n_dim_state). Consequently, a second streaming update fails:

import numpy as np
from pykalman.sqrt import CholeskyKalmanFilter

kf = CholeskyKalmanFilter(n_dim_state=2, n_dim_obs=1)
mean, covariance = kf.filter_update(np.zeros(2), np.eye(2), [0.1])
print(covariance.shape)  # currently (1, 2, 2); should be (2, 2)
kf.filter_update(mean, covariance, [0.2])

Select the single reconstructed covariance at the return sites of CholeskyKalmanFilter, BiermanKalmanFilter and the square-root AdditiveUnscentedKalmanFilter. The reconstruction helper and batch methods retain their sequence shapes.

Does your contribution introduce a new dependency? If yes, which one?

No.

What should a reviewer concentrate their feedback on?

Direct reuse of the returned covariance, including one-state filters and missing observations. Existing tests assign results into preallocated arrays, which hides the extra axis.

Did you add any tests for the change?

Twelve new cases fail before and pass after, checking consecutive updates against batch filtering and preserving inputs. The full suite passes 53 tests; configured pre-commit hooks pass. The new cases also pass with NumPy 1.26.4 as well as NumPy 2.5.3.

Any other comments?

A separate check on real ECG samples covers 72 streams and 43,128 updates across all three filters, one/two states, two noise levels and present/missing observations. All streams previously failed on direct reuse. After this change they complete and agree with an independent linear-Gaussian recurrence within 1.11e-14 for means and 7.61e-15 for covariances. All batch outputs remain identical. This validates streaming behavior, not physiological model accuracy.

PR checklist

  • The title uses [BUG].
  • Regression tests added; no new estimator or dependency.

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

Successfully merging this pull request may close these issues.

1 participant

0