Repository navigation
Conversation
This was referenced Nov 22, 2026
bashtage
force-pushed
the
wip-ss-filter-option-flags
branch
from
November 24, 2026 11:48
6d4cdd0 to
29759e9
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
The `versionchanged` note of the `complex_step` argument also says that the results no longer initialize the state again without complex step, which made the derivatives of the first period of the smoothed state and of `initial_state_cov` wrong. `KalmanFilter.filter`, whose results had the wrong `initial_state_cov` too, gets no note here because statsmodels#11028, statsmodels#11035 and statsmodels#11036 change its docstring and code next to `complex_step`; the release note covers it.
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
The `versionchanged` note of the `complex_step` argument also says that the results no longer initialize the state again without complex step, which made the derivatives of the first period of the smoothed state and of `initial_state_cov` wrong. `KalmanFilter.filter`, whose results had the wrong `initial_state_cov` too, gets no note here because statsmodels#11028, statsmodels#11035 and statsmodels#11036 change its docstring and code next to `complex_step`; the release note covers it.
bashtage
force-pushed
the
wip-ss-filter-option-flags
branch
from
November 25, 2026 12:12
29759e9 to
b8d6b78
Compare
4 of 5 tasks
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 27, 2026
The `versionchanged` note of the `complex_step` argument also says that the results no longer initialize the state again without complex step, which made the derivatives of the first period of the smoothed state and of `initial_state_cov` wrong. `KalmanFilter.filter`, whose results had the wrong `initial_state_cov` too, gets no note here because statsmodels#11028, statsmodels#11035 and statsmodels#11036 change its docstring and code next to `complex_step`; the release note covers it.
`KalmanFilter._filter` passed its options positionally to `_initialize_filter`, whose signature has `tolerance` before `filter_timing`, so the two were swapped. `filter(filter_timing=1)` ran with the model's timing and a convergence tolerance of 1 (llf -76.37 instead of -76.27 for an AR(1) with an approximate diffuse initialization), and `filter(tolerance=1e-4)` ran with the model's tolerance (1e-19) and the tolerance as the timing. `loglike`, `loglikeobs` and `smooth` pass these options through `_filter`, so they were affected in the same way. Changes: `_filter` passes every option to `_initialize_filter` by keyword, and `KalmanFilter.filter` has a `versionchanged` note. Not changed: options set on the model, and the other options given to `filter` (they were already passed in the right positions). Tests: `filter_timing=1` and `tolerance=1e-4` given to `filter`, `smooth`, `loglike` and `loglikeobs` give the output of the same option set on the model (results options, period of convergence, llf, filtered and smoothed states, loglikelihood values), and the options change the loglikelihood (and a looser tolerance converges earlier), so that the comparison is not vacuous. A second test checks that each of the seven options given to `filter` reaches the compiled filter and matches the option set on the model. 10 of the 15 new tests fail on main; the other five guard the options that were already passed correctly.
Options given for one call to `KalmanFilter.filter`, `loglike`, `loglikeobs` or `smooth` reach the compiled filter, but the results and the concentrated-likelihood adjustment read the boolean options of the model instead: - `FilterResults.update_filter` copied the bitmasks (`filter_method`, `inversion_method`, ...) from the compiled filter, but kept the boolean flags (`filter_concentrated`, `invert_lu`, `filter_collapsed`, `memory_no_*`, ...) that `update_representation` had read from the model, and the output is built from those flags. So `filter(inversion_method=INVERT_LU).standardized_forecasts_error` was all zeros (the compiled filter does not compute it for LU, and the Python fallback was skipped), `filter(filter_method=FILTER_CONVENTIONAL | FILTER_CONCENTRATED)` returned a loglikelihood without the scale terms (-46.09 instead of -64.85 for an AR(1)) and scale 1, the reverse (a concentrated model filtered with `filter_method= FILTER_CONVENTIONAL`) returned nan, and `FILTER_COLLAPSED` given as an argument returned forecasts of the collapsed (k_states) series. - `loglike` and `loglikeobs` decided whether to concentrate the scale from the model's `filter_method`, so `loglike(filter_method=... | FILTER_CONCENTRATED)` was wrong in the same way. Changes: - `update_filter` sets the boolean options from the bitmasks of the compiled filter (the same descriptors the model uses), right after copying the bitmasks. - `loglike` and `loglikeobs` test FILTER_CONCENTRATED on the compiled filter's `filter_method`; `loglikeobs` picks its default `conserve_memory` from the `filter_method` it is given. - `versionchanged` note in `KalmanFilter.filter`. Not changed: results of options set on the model (the flags of the model and of the compiled filter agree then); the fixed-scale override of `filter_concentrated` in `update_filter`; `smooth(filter_method=...)`, which still raises TypeError in `KalmanSmoother._initialize_smoother` (filter_method is passed twice; fixed separately). Tests: for INVERT_LU, SOLVE_LU, FILTER_CONCENTRATED (known and exact diffuse initialization), removing FILTER_CONCENTRATED from a concentrated model, and FILTER_COLLAPSED, the output of the option given to `filter` (and, for the inversion methods, to `smooth`) equals the output with the option set on the model: every boolean option, llf, scale, filtered states and covariances, forecasts, forecast errors and their covariances, standardized forecast errors and smoothed state covariances. `loglike` and `loglikeobs` with the concentrated cases equal the model-option values and the filter's `llf_obs`. All 14 new tests fail on main.
bashtage
force-pushed
the
wip-ss-filter-option-flags
branch
from
November 28, 2026 21:36
b8d6b78 to
cc4d42f
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.
Stacked on #11035, merge that first (this PR adds one commit). The stack was rebuilt on 2026-11-25 so that it merges without conflicts in this order; notes about conflicts with PRs of the same stack no longer apply.
Based on main; #11028 (the C9a coverage chunk) changes docstrings of the same file and appends to the same test files, so whichever merges second needs a rebase. With #11028: keep its block at the end of
test_options.py, then this one. Theversionchangedinfilter()'s Notes also conflicts with thefilter_timing/tolerancePR: keep both paragraphs under one directive.Options given for one call to
KalmanFilter.filter,loglike,loglikeobsorsmoothreach the compiled filter, but the results andthe concentrated-likelihood adjustment read the boolean options of the
model instead:
FilterResults.update_filtercopied the bitmasks (filter_method,inversion_method, ...) from the compiled filter, but kept the booleanflags (
filter_concentrated,invert_lu,filter_collapsed,memory_no_*, ...) thatupdate_representationhad read from themodel, and the output is built from those flags. So
filter(inversion_method=INVERT_LU).standardized_forecasts_errorwasall zeros (the compiled filter does not compute it for LU, and the
Python fallback was skipped),
filter(filter_method=FILTER_CONVENTIONAL | FILTER_CONCENTRATED)returned a loglikelihood without the scaleterms (-46.09 instead of -64.85 for an AR(1)) and scale 1,
the reverse (a concentrated model filtered with
filter_method= FILTER_CONVENTIONAL) returned nan, andFILTER_COLLAPSEDgiven as anargument returned forecasts of the collapsed (k_states) series.
loglikeandloglikeobsdecided whether to concentrate the scalefrom the model's
filter_method, sologlike(filter_method=... | FILTER_CONCENTRATED)was wrong in the same way.Changes:
update_filtersets the boolean options from the bitmasks of thecompiled filter (the same descriptors the model uses), right after
copying the bitmasks.
loglikeandloglikeobstest FILTER_CONCENTRATED on the compiledfilter's
filter_method;loglikeobspicks its defaultconserve_memoryfrom thefilter_methodit is given.versionchangednote inKalmanFilter.filter.Not changed: results of options set on the model (the flags of the model
and of the compiled filter agree then); the fixed-scale override of
filter_concentratedinupdate_filter;smooth(filter_method=...),which still raises TypeError in
KalmanSmoother._initialize_smoother(filter_method is passed twice; fixed separately).
Tests: for INVERT_LU, SOLVE_LU, FILTER_CONCENTRATED (known and exact
diffuse initialization), removing FILTER_CONCENTRATED from a concentrated
model, and FILTER_COLLAPSED, the output of the option given to
filter(and, for the inversion methods, to
smooth) equals the output with theoption set on the model: every boolean option, llf, scale, filtered
states and covariances, forecasts, forecast errors and their
covariances, standardized forecast errors and smoothed state
covariances.
loglikeandloglikeobswith the concentrated cases equalthe model-option values and the filter's
llf_obs. All 14 new testsfail on main.
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 contract audit, writing the fix and its tests, and checking them (tests failing on main, 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