Commit 4c40e2a
Repair state-conditioned shocks per the PR #405 code review
pro-math-code-review (5.5-Pro, 2026-07-17) returned serious_gap on the built
primitive. All six findings reproduced against the real source and repaired.
The design was sound; the implementation had two independent law mismatches
that the entire 37-test suite passed over.
F1 (serious) — solve gathered the conditioned sigma, simulate did not. The
continuous next-state wrappers copied dict(grid.params) and called draw_shock,
so every category simulated at the scalar common-grid sigma. Measured on the
pre-fix code: the low regime drew std=0.3009 where its law says 0.05, a
variance 36x too large. This moves simulated states, moments and every later
decision, not just value levels. Both wrappers now take the conditioning state
and override sigma via gather_sigma, reusing sigma_array_by_code so the solve
and simulate orderings cannot drift apart.
F2 (serious) — both row builders dropped a fixed non-zero mu. Stock pylcm
builds Tauchen rows in demeaned coordinates, where the intercept vanishes; the
conditioned branch is handed physical nodes (centred on mu/(1-rho)) and a
physical from-value, so the conditional mean is mu + rho*y and the intercept
must appear. Threaded mu through conditioned_row and tauchen_row.
F3 — the conditioned branch is selected before the runtime-parameter
mechanism, so a grid parameter left for runtime is never bound: get_gridpoints
returns all-NaN and the closure captures it forever. Now require
is_fully_specified, finite nodes, finite positive sigmas and exact category
keys.
F4 — sigma is ordered by the target regime's grid but indexed by the source
state's code. Require one shared category-to-code map across every regime
carrying the conditioning state.
F5 — the tests guarded nothing: every reduction test used mu=0 and every model
test solved but never simulated. Adds 13 regressions, each verified to fail on
the pre-fix code.
F6 — the GH rejection was documented as blanket but implemented for IID only.
Now rejects Tauchen GH too, matching the stated v1 scope.
50 tests pass (37 before). Lint clean; ty skipped locally (the worktree has no
type-checking env) and left to CI.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DW9D1WhLN8JhhiEPCScbaw1 parent 3dd6ef9 commit 4c40e2a
6 files changed
Lines changed: 396 additions & 37 deletions
File tree
- src/_lcm
- processes
- regime_building
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
| 79 | + | |
71 | 80 | | |
72 | 81 | | |
73 | 82 | | |
74 | 83 | | |
75 | 84 | | |
76 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
77 | 88 | | |
78 | 89 | | |
79 | | - | |
| 90 | + | |
80 | 91 | | |
81 | 92 | | |
82 | 93 | | |
83 | 94 | | |
84 | | - | |
| 95 | + | |
85 | 96 | | |
86 | 97 | | |
87 | 98 | | |
| |||
118 | 129 | | |
119 | 130 | | |
120 | 131 | | |
| 132 | + | |
121 | 133 | | |
122 | | - | |
| 134 | + | |
123 | 135 | | |
124 | 136 | | |
125 | 137 | | |
126 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
127 | 145 | | |
128 | 146 | | |
129 | | - | |
| 147 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
15 | 21 | | |
16 | 22 | | |
17 | 23 | | |
| |||
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
27 | | - | |
| 33 | + | |
| 34 | + | |
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
| |||
273 | 280 | | |
274 | 281 | | |
275 | 282 | | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
276 | 290 | | |
277 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
278 | 294 | | |
279 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
280 | 298 | | |
281 | 299 | | |
282 | 300 | | |
283 | 301 | | |
284 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
285 | 326 | | |
286 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
287 | 332 | | |
288 | 333 | | |
289 | 334 | | |
| |||
294 | 339 | | |
295 | 340 | | |
296 | 341 | | |
| 342 | + | |
| 343 | + | |
297 | 344 | | |
298 | 345 | | |
299 | 346 | | |
| |||
302 | 349 | | |
303 | 350 | | |
304 | 351 | | |
| 352 | + | |
305 | 353 | | |
306 | 354 | | |
307 | 355 | | |
| |||
314 | 362 | | |
315 | 363 | | |
316 | 364 | | |
317 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
318 | 370 | | |
319 | 371 | | |
320 | 372 | | |
| |||
324 | 376 | | |
325 | 377 | | |
326 | 378 | | |
| 379 | + | |
| 380 | + | |
327 | 381 | | |
328 | 382 | | |
329 | 383 | | |
| |||
332 | 386 | | |
333 | 387 | | |
334 | 388 | | |
| 389 | + | |
335 | 390 | | |
336 | 391 | | |
337 | 392 | | |
| |||
340 | 395 | | |
341 | 396 | | |
342 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
0 commit comments