TST: Keep next states within the interpolation domain in test and benchmark models#97
Merged
Conversation
…chmark models Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the test and benchmark model definitions to prevent candidate actions during inner maximization from mapping next-period states outside the interpolation domain, avoiding unstable extrapolation (especially for high-degree Chebyshev bases) and improving VFI robustness.
Changes:
- Clamp next-period capital/state in the Santos 2-D test model transition to stay within the interpolation domain.
- Clarify the spline basis-degree comment and document the rationale behind the spline policy tolerance value.
- Apply the same domain-clamping approach to both benchmark models and update benchmark model function signatures/call sites accordingly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/test_cdp_multidim.jl | Clamp next-state capital in the transition and clarify spline basis/tolerance rationale in the Santos 2-D test. |
| benchmark/benchmarks.jl | Clamp next-state variables in benchmark model transitions and update model constructors/call sites to pass domain bounds. |
Comment on lines
37
to
40
| g(s, x, e) = clamp(e * s^alpha - x, s_min, s_max) | ||
| shocks, weights = qnwlogn(9, 0.0, 0.01) | ||
| x_lb(s) = 1e-8 | ||
| x_ub(s) = s |
…enchmark model Tighten x_lb/x_ub using the quadrature shock extrema so that the next state stays within the interpolation domain for all shocks, keeping the transition law smooth (no kink from clamping). The 2-D Santos model keeps the clamp: its domain-respecting action bound has no closed form. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
The 2-D Santos (1999, Sec. 7.3) test model was verified against the paper: the model equations, the reduction to univariate maximization via the intratemporal FOC (Eq. (7.4)), all parameter values, the domain, and the analytical value/policy functions are correct. One genuine flaw was found in the numerical setup, shared by the benchmark models:
During the inner maximization, candidate actions can map the next state outside the interpolation domain (e.g. leisure
x -> 0givesk' ~ z*A*k^alpha, up to ~30 againstk_max = 10; in the 1-D growth models'can even go negative), where the fitted value function is extrapolated. For the linear and spline bases (the ones Santos actually uses) extrapolation is locally linear and benign, but for the Chebyshev cases a degree-40+ polynomial extrapolated that far is astronomically large, and correctness relied on the extrapolated values happening to repel the optimizer. Under VFI, the 1-D stochastic benchmark model in fact diverged silently (see #96 for the convergence-check bug that masked this).Changes:
test/test_cdp_multidim.jl:gclampsk'into[k_min, k_max], with a comment explaining why; the true optimal policy maps the domain well inside[0.51, 4.66], so the analytical checks are unaffected.test/test_cdp_multidim.jl: the splinepolicy_tolis written as1.92e-4 * 100and documented — Table 20's1.92e-4is for Santos's shape-preserving/cubic spline DP, while this collocation config (quadratic over bothkandlogz; cubic overlogzis infeasible with 3 nodes) attains ~1.1e-2. Also corrects the spline-degree comment ("linear over logz" -> quadratic).benchmark/benchmarks.jl: the 1-D model's action bounds are tightened using the quadrature shock extrema so thats'stays in the domain for all shocks (keeping the transition smooth), while the 2-D model clampsk'ing(its domain-respecting action bound has no closed form). With this, VFI on the 1-D Chebyshev model genuinely converges (365 iterations, agreeing with PFI to ~3e-7) instead of silently diverging. Note: this changes what the VFI benchmarks measure, so their timings are not comparable with runs before this PR.Verification
g_err = 0.136vs. Table 16's1.12e-1bound scaled by mesh; splineg_err = 1.09e-2; Chebyshevg_err = 3.3e-4).🤖 Generated with Claude Code (Claude Fable 5)