Skip to content

BUG: Compute the dependencies of the smoother output and report it - #11045

Draft
bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-ss-smoother-output-flags
Draft

bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-ss-smoother-output-flags

Conversation

@bashtage

Copy link
Copy Markdown
Member

Based on main; #11025 (the C9b coverage chunk) changes docstrings of the same files and appends to the same test files, so whichever merges second needs a rebase. With #11025: only test_smoothing.py, keep both blocks (the names differ from #11025's test_smoother_output_subset, and the presample estimators stay unset when they are not computed, as that test checks). The other C9F-B PRs that append to test_smoothing.py (smooth arguments, smoother output, autocovariance cache, smoother unreachable code) conflict there too: keep every appended block and the union of the imports.

The smoother output can be limited with smooth(smoother_output=...) or the
smoother_output option of the model, but:

  • Some output is computed from other output that the Cython smoother only
    computes when it is requested too. Without it the values were wrong:
    the state autocovariances need N_t, which is only computed with the
    state covariances (or disturbance covariances); the disturbance
    covariances are only computed with the disturbances; and the classical
    smoother computes r_t (N_t) from the smoothed state (state covariance)
    of the next period, so its disturbances need the smoothed state and its
    disturbance covariances the state covariances. For example,
    SMOOTHER_STATE_AUTOCOV alone gave autocovariances off by 0.23.
  • SmootherResults took the output flags from the options of the model, not
    from the smoother. smooth(smoother_output=SMOOTHER_STATE) on a model with
    the default output reported all output, with stale values from an
    earlier run (or uninitialized memory) for the output that was not
    computed.
  • SmootherResults.smoother_output was always None.

Changes:

  • _initialize_smoother adds the output that the requested output depends
    on before it is passed to the smoother (for the classical smoother when
    SMOOTH_CLASSICAL is set).
  • update_smoother sets smoother_output and the smoother_* flags from the
    smoother, so the results contain the computed output and None for the
    rest. The presample scaled smoothed estimators are set only if the
    scaled smoothed estimator (covariance) is computed, as before.
  • With a concentrated scale, only the computed output is rescaled (it
    raised a TypeError for output that is now None).

Not changed: the default output (SMOOTHER_ALL) and its values, and the
smoother_output option of the model (the dependencies are added only to
what is passed to the smoother).

Tests (appended to test_smoothing.py):

  • For the conventional, alternative, classical and univariate smoothers,
    with a known and an exact diffuse initialization and missing data,
    every subset of the smoother output (including none), set by the
    argument and by the option, agrees with the full run; the results report
    the requested output and its dependencies in smoother_output and the
    flags, and have None for the other output (the presample estimators are
    not set).

  • With a concentrated scale, every subset agrees with the model with that
    scale (not concentrated), including the rescaled covariances, scaled
    smoothed estimators and smoothing error.

  • 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

The smoother output can be limited with smooth(smoother_output=...) or the
smoother_output option of the model, but:

- Some output is computed from other output that the Cython smoother only
  computes when it is requested too. Without it the values were wrong:
  the state autocovariances need N_t, which is only computed with the
  state covariances (or disturbance covariances); the disturbance
  covariances are only computed with the disturbances; and the classical
  smoother computes r_t (N_t) from the smoothed state (state covariance)
  of the next period, so its disturbances need the smoothed state and its
  disturbance covariances the state covariances. For example,
  SMOOTHER_STATE_AUTOCOV alone gave autocovariances off by 0.23.
- SmootherResults took the output flags from the options of the model, not
  from the smoother. smooth(smoother_output=SMOOTHER_STATE) on a model with
  the default output reported all output, with stale values from an
  earlier run (or uninitialized memory) for the output that was not
  computed.
- SmootherResults.smoother_output was always None.

Changes:
- _initialize_smoother adds the output that the requested output depends
  on before it is passed to the smoother (for the classical smoother when
  SMOOTH_CLASSICAL is set).
- update_smoother sets smoother_output and the smoother_* flags from the
  smoother, so the results contain the computed output and None for the
  rest. The presample scaled smoothed estimators are set only if the
  scaled smoothed estimator (covariance) is computed, as before.
- With a concentrated scale, only the computed output is rescaled (it
  raised a TypeError for output that is now None).

Not changed: the default output (SMOOTHER_ALL) and its values, and the
smoother_output option of the model (the dependencies are added only to
what is passed to the smoother).

Tests (appended to test_smoothing.py):
- For the conventional, alternative, classical and univariate smoothers,
  with a known and an exact diffuse initialization and missing data,
  every subset of the smoother output (including none), set by the
  argument and by the option, agrees with the full run; the results report
  the requested output and its dependencies in smoother_output and the
  flags, and have None for the other output (the presample estimators are
  not set).
- With a concentrated scale, every subset agrees with the model with that
  scale (not concentrated), including the rescaled covariances, scaled
  smoothed estimators and smoothing error.
@bashtage
bashtage force-pushed the wip-ss-smoother-output-flags branch from a2dbce9 to e9ffa18 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