Skip to content

DOC: Correct the initial_state description of KalmanFilter.simulate - #11159

Merged
bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-ss-simulate-initial-state-doc
Nov 24, 2026
Merged

bashtage merged 2 commits into
statsmodels:mainfrom
bashtage:wip-ss-simulate-initial-state-doc

Conversation

@bashtage

Copy link
Copy Markdown
Member

Documentation only. Merges cleanly with the open kalman_filter.py PRs #11035, #11037, #11116, #11117 and #11141 (#11036 conflicts with main by itself, in test_options.py).

The initial_state entry of KalmanFilter.simulate (which MLEModel and
the simulation smoother use) said that the initial state is not included
in the returned simulated states, and that a vector of zeros is used when
the model has not been initialized. Neither is true: the initial state is
the state of the first simulated period, so simulated_states[0] equals a
given initial_state (and the first simulated observation is computed
from it), and a model without an initialization raises "RuntimeError:
Statespace model not initialized.", also when initial_state is given.
Without initial_state, the initial state is drawn from the distribution
given by the initialization.

Changes

  • The initial_state entry describes this.

Not changed

  • The code.

  • 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 coverage audit of the state space code, writing the fix and its tests, and checking them (tests failing on the base, 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 `initial_state` entry of KalmanFilter.simulate (which MLEModel and
the simulation smoother use) said that the initial state is not included
in the returned simulated states, and that a vector of zeros is used when
the model has not been initialized. Neither is true: the initial state is
the state of the first simulated period, so `simulated_states[0]` equals a
given `initial_state` (and the first simulated observation is computed
from it), and a model without an initialization raises "RuntimeError:
Statespace model not initialized.", also when `initial_state` is given.
Without `initial_state`, the initial state is drawn from the distribution
given by the initialization.

Changes
- The `initial_state` entry describes this.

Not changed
- The code.
@bashtage
bashtage marked this pull request as ready for review November 24, 2026 14:51
@bashtage
bashtage merged commit 75a4172 into statsmodels:main Nov 24, 2026
10 of 11 checks passed
@bashtage
bashtage deleted the wip-ss-simulate-initial-state-doc branch November 24, 2026 18:28
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