Skip to content

FIX: step LQMarkov.compute_sequence with the current regime - #992

Open
cristianchiriac wants to merge 1 commit into
QuantEcon:mainfrom
cristianchiriac:fix-lqmarkov-compute-sequence-regime
Open

cristianchiriac wants to merge 1 commit into
QuantEcon:mainfrom
cristianchiriac:fix-lqmarkov-compute-sequence-regime

Conversation

@cristianchiriac

Copy link
Copy Markdown

Fixes #985.

LQMarkov.compute_sequence moved x_t to x_{t+1} with A(s_{t+1}), B(s_{t+1}) and C(s_{t+1}), while u_t = -F(s_t) x_t was chosen for s_t. On paths that switch between regimes with different A, B or C, the simulated path did not follow the documented law of motion and its realised cost did not match x0' P(s_0) x0.

This uses the single forward loop suggested in the issue: each step uses the regime that is current at its start, and Cw_path goes away. The random draws are unchanged (states first, then w), so state and w_path are the same for a given seed, and paths whose regimes share A, B and C are unchanged. The existing seeded tests (test_scalar_sequences_with_seed, test_mat_sequences) pass as before.

Test: test_compute_sequence_switching_regimes, the regression test from the issue (alternating regimes with different A and B). It checks x_{t+1} = A(s_t) x_t + B(s_t) u_t and that the realised discounted cost equals P(s_0). It fails on main and passes with this change. With the issue's reproducer, the realised cost is now 1.7903655699 vs P(s_0) = 1.7903655698 for seed 0 and 1.351812536 for both with seed 1.

  • pytest quantecon/tests/test_lqcontrol.py: 19 passed
  • pytest quantecon -m "not slow": 697 passed (test_filter.py and test_quad.py were not collected because pandas isn't installed in my environment)
  • flake8 --select=F401,F405,E231 is clean on both files

I left the u_0, ..., u_T wording in the LQ and LQMarkov docstrings, which the issue also mentions, for a separate change.

The simulation moved x_t to x_{t+1} with A(s_{t+1}), B(s_{t+1}) and
C(s_{t+1}) while u_t = -F(s_t) x_t was chosen for regime s_t, so paths
that switch between regimes with different A, B or C did not follow the
documented law of motion x_{t+1} = A(s_t) x_t + B(s_t) u_t + C(s_t) w_{t+1}.

Step each period with the regime that is current at its start.

Fixes QuantEcon#985
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @cristianchiriac!

QuantEcon welcomes AI-assisted contributions under its Code of AI Use. Every pull request carries one Assisted-by: line, and this one does not yet, so two quick things, please:

  1. Add one line to the description above: Assisted-by: <tool> (<model>) if AI tools meaningfully contributed (for example Assisted-by: Claude Code (Claude Fable 5.1)), or Assisted-by: none if they did not.
  2. Reply here to confirm that a human chose the task, read the result, and will answer review on it.

This comment is posted on every external pull request that arrives without the line, so it is not a flag on yours. Nothing is blocked; a maintainer reads the reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author-response Waiting on author response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: LQMarkov.compute_sequence uses next period's A, B and C in the law of motion

2 participants