Skip to content

TST: Keep next states within the interpolation domain in test and benchmark models#97

Merged
oyamad merged 2 commits into
mainfrom
fix-santos-test
Jul 4, 2026
Merged

TST: Keep next states within the interpolation domain in test and benchmark models#97
oyamad merged 2 commits into
mainfrom
fix-santos-test

Conversation

@oyamad

@oyamad oyamad commented Jul 4, 2026

Copy link
Copy Markdown
Member

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 -> 0 gives k' ~ z*A*k^alpha, up to ~30 against k_max = 10; in the 1-D growth model s' 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: g clamps k' 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 spline policy_tol is written as 1.92e-4 * 100 and documented — Table 20's 1.92e-4 is for Santos's shape-preserving/cubic spline DP, while this collocation config (quadratic over both k and logz; cubic over logz is 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 that s' stays in the domain for all shocks (keeping the transition smooth), while the 2-D model clamps k' in g (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

  • Full test suite passes.
  • All six basis x method combinations of the Santos model converge with errors within the stated tolerances (measured: linear g_err = 0.136 vs. Table 16's 1.12e-1 bound scaled by mesh; spline g_err = 1.09e-2; Chebyshev g_err = 3.3e-4).
  • Benchmark suite smoke-runs cleanly (21 benchmarks).

🤖 Generated with Claude Code (Claude Fable 5)

…chmark models

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread benchmark/benchmarks.jl Outdated
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>
@oyamad oyamad merged commit 69e3e8d into main Jul 4, 2026
5 checks passed
@oyamad oyamad deleted the fix-santos-test branch July 4, 2026 14:29
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.

2 participants