Skip to content

BUG: Pass filter_timing and tolerance to the Kalman filter as given - #11035

Draft
bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-ss-filter-timing-tolerance
Draft

bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-ss-filter-timing-tolerance

Conversation

@bashtage

Copy link
Copy Markdown
Member

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.

  • 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.

  • No AI tools were used to develop this pull request.
  • AI tools were 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

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
bashtage force-pushed the wip-ss-filter-timing-tolerance branch from 4e4792c to 87fb2c6 Compare November 25, 2026 12:12
@bashtage

Copy link
Copy Markdown
Member Author

Merge order. These open PRs build on this one (their branches contain its commits), so please merge this PR first:

Once this PR is merged, their diffs shrink to their own changes. Each of them also says "Stacked on #..." at the top of its description.

Merge-order note generated with Claude Code (updated 2026-11-25).

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.
@bashtage
bashtage force-pushed the wip-ss-filter-timing-tolerance branch from 87fb2c6 to 25729ab Compare November 28, 2026 21:36
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