Skip to content

DOC: Follow up #10742 on the concentrated diffuse loglike, with tests - #10748

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-kalman-diffuse-followup
Nov 16, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-kalman-diffuse-followup

Conversation

@bashtage

Copy link
Copy Markdown
Member

Follow up to #10742 (the finite innovations of the exact diffuse periods in the concentrated loglike, closes #10741). Its review left the points below. The code of kalman_filter.py is unchanged.

  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message. See
    NumPy's guide.

Changes

  • DOC: Release note: moved from the start to the end of the 'Time series analysis' bug-fix list (the lists are in merge order), :pr:10742`` added, and rewritten to say what a user sees. loglike() of a model with exact diffuse initialization and a concentrated scale now equals `loglikeobs().sum()`, `llf` and the value with `fixed_scale`, and no longer depends on `conserve_memory`. The fitted parameters change for models whose diffuse periods contain finite innovations, and the note says which models do and which do not. Compared on the code before BUG: include finite exact-diffuse innovations in concentrated loglike (closes #10741) #10742 and now: a single series with a local level or a local linear trend (also with missing values, 60 random patterns each), and `SARIMAX(0, 1, 1, concentrate_scale=True)` with `initialize_diffuse()` give identical values (`loglike` -184.18628527768678, same fitted parameters). A bivariate model with one common diffuse level changes in the default call (-97.9235 to -97.9024), a time-varying design with a state observed only from t = 3 changes by 0.958, and the fitted parameters of a bivariate `MLEModel` change from (0.669, 0.848) to (0.736, 0.899). With `MEMORY_NO_LIKELIHOOD` or `MEMORY_CONSERVE` and `loglikelihood_burn = 1`, the local level was -51.4393 and is -50.5204, the value of the default call. The note says nothing about the size of the changes. The release note stays under 'Bug Fixes' next to BUG: Preserve seasonal and sparse lags in ARIMA GLS whitening #10713 (ARIMA GLS, also changed results), although `AGENTS.md` puts changed results under 'Behavior changes'; move it if you prefer.
  • TST: test_concentrated_exact_diffuse_kfas compares with R KFAS 1.6.0 (R 4.6.1): for the model of the closed-form test with the scale fixed at its estimate 29 / 89, logLik is -3.08527474008954 and the log-likelihood here is that value minus 0.5 log(2 pi), the constant that KFAS leaves out for a diffuse innovation (one in this model), rtol=1e-10, for the four conserve_memory settings of the existing tests. The R code is in the test.
  • TST: test_concentrated_exact_diffuse_mlemodel (12 cases) uses a bivariate local level MLEModel whose diffuse period has finite innovations (a single series has none, so the existing SARIMAX tests cannot guard them), with complete and missing data (including leading missing values, so that the diffuse period has two periods), loglikelihood_burn 0, 1 and 3 and two parameter sets. loglike, llf and loglikeobs().sum() equal the non-concentrated model with the scale fixed at the estimate (rtol=1e-12), and the complex-step score agrees with the centered finite difference (rtol=1e-6; a consistency check, not a mutation check).
  • TST: test_concentrated_exact_diffuse_sarimax (3 cases: default burn, 0, 2) pins that SARIMAX(0, 1, 1) is unchanged by BUG: include finite exact-diffuse innovations in concentrated loglike (closes #10741) #10742. It passes before and after, because a single series has no finite diffuse innovations.
  • TST: The atol=1e-12 of BUG: include finite exact-diffuse innovations in concentrated loglike (closes #10741) #10742's new tests is removed; rtol=1e-12 holds alone on Python 3.13 and 3.10 (a reason for every atol is what AGENTS.md asks).

Mutation checks (kalman_filter code mutated, each restored afterwards; each of the seven fails at least one new test): quadratic term from d instead of the burn (MLEModel 6 of 12, KFAS 1 of 1), quadratic term over all periods (6 of 12), burn ignored in the diffuse log-likelihood (6 of 12, SARIMAX 2 of 3), d = loglikelihood_burn (KFAS 4 of 4, 6 of 12), no finite diffuse count at burn 0 (4 of 12), no partial-burn count (2 of 12), no re-filter (KFAS 2 of 4). Two more mutations (no forecast-covariance requirement on a partial burn, counting all periods when the burn is positive) survive the new tests and are caught by the existing grid and the KFAS test.

Not changed

Tests

  • statsmodels/tsa/statespace/tests/test_concentrated.py: 98 passed (79 before, plus 19) on Python 3.13 and on Python 3.10 (NumPy 1.23.5, SciPy 1.8.1); test_exact_diffuse_filtering.py: 289 passed, 11 skipped, 34 xfailed and test_kalman.py: 42 passed, 8 skipped on Python 3.13.
  • ruff check and git diff --check pass.

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.

🤖 Generated with Claude Code

bashtage and others added 2 commits November 15, 2026 18:43
Move the bullet of statsmodels#10742 to the end of the "Time series analysis" bug
fix list, add its :pr: role, and say what users see: loglike now equals
loglikeobs().sum(), llf and the fixed_scale value, also for
conserve_memory settings; values and fitted parameters change when the
diffuse periods contain finite innovations (several observed series with
one diffuse state, a diffuse state observed only later), and single
series models without such innovations (local level, local linear
trend, SARIMAX with concentrate_scale) are unchanged. The bullet stays
under Bug Fixes, as the neighbouring merged statsmodels#10713 bullet.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Follow-up to statsmodels#10742. Drop atol from the new tests (values are of order 1
to 5, rtol=1e-12 holds on Python 3.13 and 3.10). Add a test against R
KFAS 1.6.0 for the issue model (KFAS logLik less 0.5 * log(2 * pi) of the
diffuse innovation, which KFAS omits), for every conserve_memory setting,
and tests through MLEModel: a bivariate local level with finite diffuse
innovations (complete and with missing data, loglikelihood_burn 0, 1, 3,
compared with the non-concentrated model at the estimated scale, plus
complex step against finite difference scores) and SARIMAX(0, 1, 1) with
concentrate_scale and exact diffuse initialization (default and explicit
loglikelihood_burn).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@bashtage
bashtage marked this pull request as ready for review November 15, 2026 22:55
@bashtage
bashtage merged commit ca9a8b6 into statsmodels:main Nov 16, 2026
14 checks passed
@bashtage
bashtage deleted the wip-kalman-diffuse-followup branch November 20, 2026 10:57
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.

BUG: KalmanFilter.loglike() disagrees with loglikeobs().sum() and result.llf under exact diffuse initialization with concentrated scale

1 participant