From Dynamic Programming to Reinforcement Learning

Comparing model-based planning and model-free learning on an underactuated control benchmark

Varun Rayamajhi1, Kamil Balinski1
1School of Informatics, University of Edinburgh
Q-learning curves comparing learning-rate and exploration schedules

The methods reached similar stabilization objectives in different ways: Q-learning achieved the strongest average return, MPC was the most consistent, and DP exposed the structure and limitations of the discretized control problem.

Project Overview

We used the underactuated cartpole system to compare model-based planning and model-free learning under a common stabilization task. Dynamic programming solves a discretized model globally, MPC repeatedly optimizes a continuous finite-horizon trajectory, iLQR supplies local feedback around a nominal trajectory, and Q-learning estimates action values directly from sampled interaction.

Our study follows the complete control pipeline: how the objective shapes a value function, how planning horizon affects closed-loop control, how learning schedules influence a tabular agent, and how the methods trade performance against computation and adaptability. The separate breathing sine-wave trajectory-tracking study is presented on the Cartpole MPC project page.

Dynamic Programming Reveals the Recovery Region

Dynamic programming value function at high grid resolution

With only a terminal penalty, the value function approximately measures discounted time to failure. Increasing the discount factor spreads the high-cost boundary inward because future failures matter more. Adding a dense quadratic cost creates smoother gradients, although excessively large weights discourage the cart motion needed to stabilize the pole.

$$V^*(s)=\min_{a\in\mathcal A}\left[C(s,a)+\gamma V^*\!\left(f(s,a)\right)\right].$$

Increasing the state-grid resolution sharpened the estimated recovery boundary. At the highest feasible resolutions, the zero-velocity slice suggested recovery from approximately $32^\circ\pm1^\circ$. This interpretability comes with a steep cost: a four-dimensional grid grows as $R^4$, and memory limited our experiments beyond $R=90$.

Figure 1. High-resolution DP value-function slice showing the estimated recoverable region for zero cart and angular velocity.

Planning Horizon Determines MPC Reliability

Short-horizon MPC is too short-sighted to build the cart motion needed for later recovery. Across 100 evaluation episodes, the first horizon with no terminations was $H=9$. A stricter performance target required more foresight: the mean return first fell below $0.01$ at $H=30$.

$$\mathbf u_{0:H-1}^{*}=\arg\min_{\mathbf u_{0:H-1}} \left[\Phi(\mathbf x_H)+\sum_{k=0}^{H-1}L(\mathbf x_k,\mathbf u_k)\right], \qquad \mathbf x_{k+1}=f(\mathbf x_k,\mathbf u_k).$$
MPC terminations versus horizon length
MPC mean return versus horizon length

Figure 2. Episode terminations and mean return as the MPC planning horizon increases.

$H=9$
first horizon with zero terminations
$H=30$
first horizon with mean return below 0.01
100
evaluation episodes per setting

MPC and iLQR Recover Differently

In our implementation, MPC maintained a 100% survival rate through disturbance level 5, whereas iLQR remained perfect through level 155. This result reflects the specific setup rather than a universal advantage: iLQR used a full-episode horizon and immediately applied its local feedback gains, while MPC used a shorter horizon and responded through re-optimization at the following timestep.

$$\mathbf u_k=\overline{\mathbf u}_k+\mathbf k_k+\mathbf K_k\left(\mathbf x_k-\overline{\mathbf x}_k\right).$$

For a caregiving robot, we would still prefer MPC as the starting point. It re-plans from the latest measured human state and can explicitly incorporate safety constraints and uncertainty. Standard iLQR remains local to a nominal trajectory and requires additional constraint handling for unpredictable human motion.

MPC survival rate under increasing disturbance
iLQR survival rate under increasing disturbance

Figure 3. Survival rate under increasing disturbances for MPC and iLQR in our experimental setup.

Scheduling Stabilizes Q-Learning

Q-learning returns did not improve monotonically because exploratory actions could still terminate an otherwise successful episode, while bootstrap targets continued to change as poorly visited parts of the large table were updated. A learning-rate schedule was especially important: it allowed large early updates and increasingly stable estimates later in training.

$$Q(s_t,a_t)\leftarrow Q(s_t,a_t)+\alpha_t\left[r_t+\gamma\max_{a'}Q(s_{t+1},a')-Q(s_t,a_t)\right].$$

We used a state-action visit-count schedule for the learning rate, so rarely visited pairs received larger updates while frequently updated values gradually stabilized:

$$\alpha_t(s,a)=\max\left(\alpha_{\min},\frac{c}{\left[c+(1-\gamma)N_t(s,a)\right]^\omega}\right),$$

where $N_t(s,a)$ is the number of updates to $(s,a)$. We used $c=1.0$, $\omega=0.85$, $\gamma=0.99$, and $\alpha_{\min}=10^{-4}$. Exploration followed an inverse-decay schedule:

$$\epsilon(t)=\max\left(\epsilon_{\min},\frac{\epsilon_0}{1+kt}\right), \qquad k=\frac{\epsilon_0/\epsilon_{\min}-1}{T_{\mathrm{total}}}.$$

Here, $\epsilon_0=0.05$, $\epsilon_{\min}=0.01$, and $T_{\mathrm{total}}=10$ million steps. The $\alpha$-schedule controls how strongly the Q-values change, whereas the $\epsilon$-schedule controls which actions are sampled.

Comparison of learning-rate and exploration schedules for Q-learning

Figure 4. Q-learning behavior under different learning-rate and exploration schedules.

Using constant learning and exploration rates produced a final return of $-0.0852\pm0.2455$. The learning-rate scheduler improved this to $-0.00268\pm0.00227$, while combining the learning-rate and exploration schedules gave the strongest stability at $-0.00236\pm0.00193$.

Performance, Computation, and Generalization

Q-learning achieved the best average return, $-0.0018$, while MPC achieved a mean cost of $0.0060$ and DP achieved $0.0160$. MPC was slightly more consistent and had the better worst case; Q-learning occasionally encountered failures caused by discretization and insufficient coverage of less-visited states.

The methods also place computation in different locations. DP performs expensive sweeps over the complete $R^4$ grid, and Q-learning shifts the cost to millions of sequential interactions. Both produce policies that are inexpensive to execute. MPC instead solves an optimization problem online at every timestep, trading computation for immediate reactivity.

Changing the pole length exposed the limitation of a fixed learned policy. The Q-learning agent was trained at $L_0=0.5$ m, and performance degraded as evaluation moved away from this value because the transition dynamics changed. MPC is theoretically better suited to adaptation when its model can be updated, since it uses the latest state and model to re-plan online.

$$Q_L^*(s,a)=\mathbb E_{s'\sim P_L}\!\left[r(s,a,s')+\gamma\max_{a'}Q_L^*(s',a')\right].$$
Q-learning generalization under changes in pole length

Figure 5. Q-learning return under pole-length perturbations after training at $L_0=0.5$ m.

Conclusion

No single approach dominated every criterion. DP offered interpretable grid-level optimality but suffered from the curse of dimensionality. Q-learning achieved strong average performance and inexpensive execution after substantial offline training, but was less reliable in rare states and under model mismatch. MPC required more online computation, yet its continuous re-planning made it the strongest basis for responding to disturbances and changes in the physical system.