Repository navigation
Conversation
This was referenced Nov 24, 2026
`FilterResults.kalman_gain` computes the gain from the predicted state and forecast error covariance matrices of every period when the filter did not store it (`MEMORY_NO_GAIN`). If memory conservation also skipped storing those matrices (`memory_conserve=True`, `MEMORY_CONSERVE`, or `MEMORY_NO_GAIN` with `MEMORY_NO_PREDICTED_COV` or `MEMORY_NO_FORECAST_COV`), it read the few matrices that the filter keeps for its own use as if they were those of the first periods. For an ARMA(1, 1) with 20 observations it raised "IndexError: index 2 is out of bounds for axis 2 with size 2", and with 2 observations it returned wrong values without an error. Changes - `kalman_gain` raises a ValueError that says that the gain is not available if memory conservation was used to avoid storing it and the predicted state or forecast error covariance matrices, as `predict` does for in-sample predictions without the arrays it needs. - `versionchanged` note in its docstring. Not changed - The gain stored by the filter, and the gain computed with `MEMORY_NO_GAIN` alone, which uses the stored covariance matrices. Tests - For `MEMORY_CONSERVE`, and `MEMORY_NO_GAIN` with `MEMORY_NO_PREDICTED_COV` or with `MEMORY_NO_FORECAST_COV`, with 2 and 20 observations, `kalman_gain` raises the ValueError (all 6 fail on main, with IndexError for 20 observations and no error for 2). - With `MEMORY_NO_GAIN` alone, the computed gain equals the gain stored by a filter without memory conservation (passes on main too).
bashtage
force-pushed
the
wip-ss-kalman-gain-conserve
branch
from
November 28, 2026 21:36
3a08953 to
b5624cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No conflict in
kalman_filter.pywith #11028, #11035-#11037, #11039 or #11071-#11073. Other open statespace PRs also append tests at the end of the same test files: keep both appended blocks.FilterResults.kalman_gaincomputes the gain from the predicted stateand forecast error covariance matrices of every period when the filter
did not store it (
MEMORY_NO_GAIN). If memory conservation also skippedstoring those matrices (
memory_conserve=True,MEMORY_CONSERVE, orMEMORY_NO_GAINwithMEMORY_NO_PREDICTED_COVorMEMORY_NO_FORECAST_COV), it read the few matrices that the filterkeeps for its own use as if they were those of the first periods. For an
ARMA(1, 1) with 20 observations it raised "IndexError: index 2 is out of
bounds for axis 2 with size 2", and with 2 observations it returned wrong
values without an error.
Changes
kalman_gainraises a ValueError that says that the gain is notavailable if memory conservation was used to avoid storing it and the
predicted state or forecast error covariance matrices, as
predictdoes for in-sample predictions without the arrays it needs.
versionchangednote in its docstring.Not changed
MEMORY_NO_GAINalone, which uses the stored covariance matrices.Tests
For
MEMORY_CONSERVE, andMEMORY_NO_GAINwithMEMORY_NO_PREDICTED_COVor withMEMORY_NO_FORECAST_COV, with 2 and 20observations,
kalman_gainraises the ValueError (all 6 fail on main,with IndexError for 20 observations and no error for 2).
With
MEMORY_NO_GAINalone, the computed gain equals the gain stored bya filter without memory conservation (passes on main too).
tests added / passed.
code/documentation is well formatted.
properly formatted commit message. See
NumPy's guide.
AI Disclosure
Contributions must comply with the statsmodels AI Policy.
Tick exactly one of the following. If AI tools were used, replace the
<...>placeholders in the second option with the tool name(s) and how the tool's output was
used.
Tool(s): Claude Code (Claude Opus 5.5).
Used for: finding the bug in a coverage audit of the state space models, writing the fix and its tests, and checking them (tests failing on the base, mutation check).
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.
🤖 Generated with Claude Code