Tutorials › Econometrics (Graduate) › Numerical Derivatives and Optimization in Nested Fixed-Point Models

Dynamic Discrete Choice · Tutorial 752 of 952

Numerical Derivatives and Optimization in Nested Fixed-Point Models

Derive and check likelihood gradients in nested fixed-point estimation, while controlling numerical error from the inner value-function solver.

Advanced 11 min read

What You'll Learn

  • Write the conditional choice likelihood and identify the Bellman fixed point it depends on
  • Approximate likelihood gradients with central finite differences and understand the step-size tradeoff
  • Derive value-function and choice-probability derivatives by implicit differentiation
  • Use Bellman residuals to bound value-function error and assess its effect on likelihood calculations
  • Diagnose noisy gradients, misleading optimizer convergence, and poor parameter scaling

Why Numerical Accuracy Matters in Nested Fixed-Point Estimation

In nested fixed-point estimation, each proposed parameter vector requires solving a dynamic programming problem before the likelihood can be evaluated. Optimization then compares likelihoods at nearby parameter values. If the inner value-function calculation is inaccurate, those comparisons can be noisy: an optimizer may mistake numerical error for a meaningful improvement or a gradient direction. This tutorial develops two ways to calculate likelihood gradients and shows how to tell whether the inner solution is accurate enough to support them.

Consider a finite-state choice model with states \(s\), actions \(a\), discount factor \(\beta\), and parameter vector \(\theta\). Let \(u_a(s;\theta)\) be the deterministic current payoff and \(P_a(s,s')\) the probability of moving to state \(s'\) after choosing \(a\) in state \(s\). Assume \(0\leq\beta<1\), known transitions that do not depend on \(\theta\), and independent Type I extreme-value choice shocks with the location normalized so that their integrated value is the log-sum-exp. The observed states and choices are treated as given when forming the conditional choice likelihood.

Definition: The choice-specific value is \(Q_a(s;\theta)=u_a(s;\theta)+\beta\sum_{s'}P_a(s,s')V(s';\theta)\). The integrated value function solves \(V(s;\theta)=\log\sum_a\exp(Q_a(s;\theta))\). The implied choice probability is \(\pi_a(s;\theta)=\exp(Q_a(s;\theta))/\sum_b\exp(Q_b(s;\theta))\). For observations \((s_i,y_i)\), the conditional log likelihood is \(\ell(\theta)=\sum_{i=1}^n\log\pi_{y_i}(s_i;\theta)\).

The value function is “nested” inside the likelihood: evaluating \(\ell(\theta)\) requires first solving its fixed-point equation. The definitions above assume the transition probabilities are fixed with respect to \(\theta\). If a particular model estimates transition parameters, derivatives of \(P_a\) and any transition likelihood contributions must also be included; they are not part of the formulas developed here.

Finite-Difference Gradients

The direct numerical approach evaluates the solved likelihood at small perturbations of each parameter. For parameter \(\theta_j\), a central finite difference is

$$ \frac{\partial\ell(\theta)}{\partial\theta_j} \approx \frac{\ell(\theta+h e_j)-\ell(\theta-h e_j)}{2h}, $$

where \(e_j\) is a vector with a one in coordinate \(j\) and zeros elsewhere, and \(h>0\) is the step size. Each likelihood in the numerator must be computed using a value function solved at that perturbed parameter vector. Reusing the unperturbed value function without updating it generally does not calculate the derivative of the nested likelihood.

With an exact, sufficiently smooth likelihood, central differences have truncation error of order \(h^2\). But each likelihood evaluation is computed numerically. If its absolute error is at most \(\eta\), the resulting error in the difference quotient can be as large as \(\eta/h\): the two likelihood errors are subtracted and divided by \(2h\). Thus a very small step reduces truncation error but magnifies inner-solver error and floating-point error. A large step suppresses that noise but can make the finite difference a poor approximation to a local derivative.

Worked Example: A Central Difference for a Choice Likelihood

Consider a one-state, two-action model with \(u_1(\theta)=\theta\), \(u_0(\theta)=0\), and identical transitions for the two actions. Let \(\beta=0.9\), and suppose one action-1 choice is observed. Because the continuation value is common to both actions, it cancels in their choice probabilities. The probability of action 1 is \(p_1(\theta)=\exp(\theta)/(1+\exp(\theta))\), and the log likelihood is \(\ell(\theta)=\theta-\log(1+\exp(\theta))\).

At \(\theta=0.4\), the exact derivative is \(1-p_1(0.4)\). Since \(\exp(0.4)=1.4918\), \(p_1(0.4)=1.4918/2.4918=0.5987\), so the derivative is \(0.4013\).

For a central difference with \(h=0.01\), the two log likelihoods are approximately \(\ell(0.41)=-0.5090\) and \(\ell(0.39)=-0.5170\). Therefore,

$$ \frac{\ell(0.41)-\ell(0.39)}{0.02} \approx \frac{-0.5090-(-0.5170)}{0.02} =0.4000. $$

The approximation is close to the exact value \(0.4013\). In this example the value solution is not needed to distinguish the choice probabilities, but the same procedure in a general model requires solving the inner fixed point separately at \(0.39\) and \(0.41\).

Implicit Differentiation of the Fixed Point

Rather than perturbing and resolving the model for every parameter, one can differentiate the Bellman fixed-point equation. This gives a derivative that accounts directly for how a parameter changes both current payoffs and future values. Write \(V_\theta\) for the vector of derivatives of \(V\) with respect to one scalar parameter \(\theta_j\), and write \(u_{a,\theta}\) for the corresponding derivative of \(u_a\), holding \(V\) fixed.

Result: With fixed transition probabilities, the derivative of the integrated value satisfies \(V_\theta=g+\beta\bar P V_\theta\), where \(g(s)=\sum_a\pi_a(s)u_{a,\theta}(s)\) and \(\bar P(s,s')=\sum_a\pi_a(s)P_a(s,s')\). Equivalently, \(V_\theta=(I-\beta\bar P)^{-1}g\). The derivative of a choice-specific value is \(Q_{a,\theta}(s)=u_{a,\theta}(s)+\beta\sum_{s'}P_a(s,s')V_\theta(s')\).

To justify the result, differentiate \(V(s)=\log\sum_a\exp(Q_a(s))\). The derivative of log-sum-exp is a probability-weighted average, so

$$ V_\theta(s)=\sum_a\pi_a(s)Q_{a,\theta}(s) =\sum_a\pi_a(s)u_{a,\theta}(s) +\beta\sum_{s'}\left(\sum_a\pi_a(s)P_a(s,s')\right)V_\theta(s'). $$

The first term is \(g(s)\), and the transition-weighted term is \(\beta\bar P V_\theta\), which gives the stated linear system. Since each row of \(\bar P\) sums to one, its maximum absolute row sum is one. Thus the maximum absolute row sum of \(\beta\bar P\) is \(\beta<1\); the inverse exists and is given by the convergent series \(I+\beta\bar P+(\beta\bar P)^2+\cdots\). This also shows why a parameter's effect on current payoffs propagates through future values.

Finally, differentiating the log choice probability gives the score contribution for observing action \(y\) in state \(s\):

$$ \frac{\partial\log\pi_y(s)}{\partial\theta_j} = Q_{y,\theta}(s)-\sum_a\pi_a(s)Q_{a,\theta}(s). $$

Summing this expression over observations gives the likelihood gradient. For a vector of parameters, solve the corresponding system for each parameter coordinate, or solve for several right-hand sides together.

Worked Example: Solving the Implicit Derivative System

There are two states and two actions, with \(\beta=0.8\). Both actions have the same transition matrix, \(P=\begin{pmatrix}0.75&0.25\\0.20&0.80\end{pmatrix}\). At \(\theta=0\), both actions have equal current payoffs, so \(\pi_1(s)=\pi_0(s)=0.5\) in each state. Suppose \(u_{1,\theta}(1)=1\), \(u_{1,\theta}(2)=0\), and \(u_{0,\theta}(s)=0\) in both states.

The vector \(g\) is the probability-weighted payoff derivative, so \(g=(0.5,0)^\mathsf{T}\). Since the transitions do not differ by action, \(\bar P=P\), and the value derivative solves

$$ \begin{pmatrix} 0.4&-0.2\\ -0.16&0.36 \end{pmatrix} \begin{pmatrix}V_\theta(1)\\V_\theta(2)\end{pmatrix} = \begin{pmatrix}0.5\\0\end{pmatrix}. $$

The determinant is \(0.4(0.36)-(-0.2)(-0.16)=0.112\). Solving gives \(V_\theta(1)=0.18/0.112=1.6071\) and \(V_\theta(2)=0.08/0.112=0.7143\). In state 1, the transition-weighted derivative is \(0.75(1.6071)+0.25(0.7143)=1.3839\). Therefore \(Q_{1,\theta}(1)=1+0.8(1.3839)=2.1071\) and \(Q_{0,\theta}(1)=0.8(1.3839)=1.1071\). The score for an action-1 observation in state 1 is

$$ 2.1071-\left[0.5(2.1071)+0.5(1.1071)\right]=0.5000. $$

This is the derivative of the log choice probability at that observation. The continuation value affects both choice-specific derivatives, but their difference is one here because the actions share the same transitions; the score is consequently \(1-0.5=0.5\).

Diagnosing the Inner Solver

A stopping rule based only on the change between successive value iterates can be misleading. A more interpretable diagnostic is the Bellman residual. For an approximate value vector \(\widetilde V\), define \(r=\|T_\theta(\widetilde V)-\widetilde V\|_\infty\), where \(T_\theta\) is the Bellman operator and \(\|\cdot\|_\infty\) is the largest absolute state-specific error.

Bound: If \(T_\theta\) is a contraction with modulus \(\beta\), then the distance from the approximate solution to the true fixed point satisfies \(\|\widetilde V-V\|_\infty\leq r/(1-\beta)\).

Indeed, using \(V=T_\theta(V)\) and the contraction property,

$$ \|\widetilde V-V\|_\infty \leq \|\widetilde V-T_\theta(\widetilde V)\|_\infty +\|T_\theta(\widetilde V)-T_\theta(V)\|_\infty \leq r+\beta\|\widetilde V-V\|_\infty. $$

Rearranging gives the bound. When \(\beta\) is near one, even a small residual can permit a noticeably larger value error. That error can affect the likelihood and, more sharply, a finite-difference gradient that divides the difference of two likelihoods by a small \(h\).

Worked Example: Residual Error and a Noisy Gradient

Suppose \(\beta=0.95\), and the value solver stops at a vector with Bellman residual \(r=0.00002\). The contraction bound gives

$$ \|\widetilde V-V\|_\infty \leq \frac{0.00002}{1-0.95} =0.0004. $$

With fixed transitions, an error of at most \(0.0004\) in the value vector changes each continuation component of \(Q_a\) by at most \(0.95(0.0004)=0.00038\). For any one observation, the log choice probability is \(Q_y-\log\sum_a\exp(Q_a)\). Changing every \(Q_a\) by at most \(0.00038\) changes this log probability by at most \(0.00076\): the chosen \(Q_y\) changes by at most \(0.00038\), and log-sum-exp changes by at most the largest absolute \(Q\) change.

For \(n=1000\) observations, this yields a conservative log-likelihood error bound of \(1000(0.00076)=0.76\) at a single parameter vector. If each of two likelihood evaluations in a central difference has error at most \(0.76\), the induced gradient error is bounded by \(2(0.76)/(2h)=0.76/h\). At \(h=0.01\), that bound is \(76\), which is too loose to certify a useful gradient. The bound is conservative, but it illustrates why residual tolerances should be assessed relative to sample size and finite-difference step, not chosen in isolation. Tighter inner solves and checking stability across reasonable step sizes are practical safeguards.

Optimization Checks and Common Pitfalls

A numerical optimizer sees only the objective values and gradients it is given. It cannot distinguish a genuine likelihood improvement from a change caused by an inner solver stopping inconsistently. In practice, solve the Bellman equation to a controlled residual at every trial parameter vector, and make that tolerance sufficiently stringent near the optimizer's solution. If parameters have very different scales, rescale them so that a common numerical step does not represent a negligible perturbation in one coordinate and an enormous perturbation in another.

1
Set up the nested calculation.
For each trial \(\theta\), solve the Bellman equation and evaluate the conditional choice log likelihood using the resulting probabilities.
2
Compute and check derivatives.
Use implicit differentiation when its linear system is available. Compare with central differences at more than one step size, solving the inner problem afresh at each perturbed parameter.
3
Assess numerical convergence.
Inspect Bellman residuals and confirm that the objective and gradient are stable as inner tolerances are tightened. A small optimizer step alone does not establish that the likelihood is maximized.

Common mistake: “The optimizer stopped, so the estimated parameters maximize the likelihood.” This reasoning treats the optimizer's stopping rule as proof that its inputs were accurate. In a nested model, small parameter steps or a small reported gradient can instead reflect noisy likelihood evaluations, inaccurate finite differences, or a poorly scaled parameterization. The correction is to verify the inner residual, tighten it and rerun, check gradient stability over sensible step sizes, and confirm that the likelihood and parameter estimates are stable. These checks support a numerical convergence claim; they do not by themselves establish identification or model validity.

Key takeaway: A nested fixed-point gradient must account for the parameter's effect on the solved value function. Finite differences can do so by resolving the model at perturbed parameters, while implicit differentiation propagates the effect through a linear system. Either method is only as reliable as the inner value-function accuracy and the checks used to diagnose numerical error.

Check Your Understanding

Answer these questions using the definitions and calculations in the tutorial.

  1. Why must the value function generally be re-solved at each perturbed parameter vector when calculating a finite-difference likelihood gradient?
  2. What competing numerical errors arise when the central-difference step \(h\) is made very small?
  3. State the linear system that determines \(V_\theta\), and explain what \(g(s)\) represents.
  4. For \(\beta=0.9\) and Bellman residual \(r=0.0001\), what upper bound does the contraction result give for \(\|\widetilde V-V\|_\infty\)?
  5. Why is optimizer termination alone insufficient evidence that a nested fixed-point likelihood has been maximized accurately?
Clinical Biostats