Repository navigation
DOC: Follow up #10742 on the concentrated diffuse loglike, with tests - #10748
Merged
Merged
Conversation
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]>
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.
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 ofkalman_filter.pyis unchanged.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_kfascompares 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,logLikis -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 fourconserve_memorysettings of the existing tests. The R code is in the test.TST:test_concentrated_exact_diffuse_mlemodel(12 cases) uses a bivariate local levelMLEModelwhose 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_burn0, 1 and 3 and two parameter sets.loglike,llfandloglikeobs().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 thatSARIMAX(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:Theatol=1e-12of BUG: include finite exact-diffuse innovations in concentrated loglike (closes #10741) #10742's new tests is removed;rtol=1e-12holds alone on Python 3.13 and 3.10 (a reason for everyatolis whatAGENTS.mdasks).Mutation checks (
kalman_filtercode mutated, each restored afterwards; each of the seven fails at least one new test): quadratic term fromdinstead 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
0 < burn < nobs_diffuse(includingSARIMAX(0, 1, 1)with its default burn of 1), andFilterResults.update_filterwithconserve_memorystill has the defect of BUG: KalmanFilter.loglike() disagrees with loglikeobs().sum() and result.llf under exact diffuse initialization with concentrated scale #10741 for these models.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 andtest_kalman.py: 42 passed, 8 skipped on Python 3.13.ruff checkandgit diff --checkpass.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 Sonnet 5.5).
Used for: reviewing BUG: include finite exact-diffuse innovations in concentrated loglike (closes #10741) #10742, and writing and checking the follow-up changes.
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