Reinforcement Learning for Engineers
Learning outcomes
- Relate the Bellman equation to the MPC problem and explain MPC as the same problem solved online with a model and a finite horizon.
- Compare reinforcement learning and MPC by what each needs, how each handles constraints and how each is verified.
- Explain why the LQR is a case where the value function is known exactly.
Book chapter: Nonlinear Dynamics, Oscillations, and Stabilization (Volume 7), Chapter 7, Inverted Pendulum Simulator for Balancing a Pole Without Losing the Cart (PDF).
Practice in 15 minutes: 11 · LQR Against MPC on a Finite Rail, 14 · Dynamic Programming and the Four Driving Regimes
Model: Model-free RL needs only a simulator or the plant to try actions on; model-based RL and MPC use an explicit model.
Decision: Both choose an action for the current state; RL looks it up in a learned policy, MPC computes it by optimization.
Learning: RL learns the policy or value function from experience; MPC learns only through the model and its estimator.
Reinforcement Learning (RL) is a paradigm of machine learning and optimal control where an agent learns to make decisions by interacting with an environment to maximize a cumulative reward. Unlike supervised learning, the agent isn’t given correct actions but instead experiments with actions, learning through feedback (rewards). The agent observes the current state of the environment, takes an action, and receives a reward (scalar feedback signal), then the environment transitions to a new state. This loop continues over time (see Figure 1). The agent seeks a policy (mapping states to actions) that maximizes expected cumulative rewards. Key concepts:
- States: Observations of the environment.
- Actions: Decisions made by the agent.
- Rewards: Immediate feedback signals.
- Policy: Strategy to select actions.
Agents face the exploration vs. exploitation dilemma: exploring new actions to find higher rewards vs. exploiting known rewarding actions.
Markov Decision Processes (MDPs):
RL problems often use Markov Decision Processes (MDPs), a mathematical framework for sequential decision-making under uncertainty. An MDP is defined by a tuple:
$$ \mathcal{M} = (\mathcal{S}, \mathcal{A}, P, R, \gamma) $$
where:
- `\mathcal{S}` = Set of states.
- `\mathcal{A}` = Set of actions.
- `P(s'|s,a)` = Transition probability to state `s'` given state `s` and action `a`.
- `R(s,a,s')` = Reward from transitioning state `s` to `s'` via action `a`.
- `\gamma \in [0,1)` = Discount factor, weighing future vs. immediate rewards.
MDPs satisfy the Markov property: future states depend only on current state and action. The optimal policy `\pi^*(s)` maximizes expected long-term rewards. MDP solutions involve computing value functions `V(s)` or action-value functions `Q(s,a)`. The Bellman optimality equation for value functions:
$$ V^*(s) = \max_{a \in \mathcal{A}} \sum_{s'} P(s'|s,a)\left[ R(s,a,s') + \gamma V^*(s') \right] $$
Similarly, the optimal Q-value:
$$ Q^*(s,a) = \sum_{s'}P(s'|s,a)\left[R(s,a,s') + \gamma \max_{a'}Q^*(s',a')\right] $$
Model-Free vs. Model-Based RL:
A key distinction:
- Model-based RL: Uses or learns a model `P(s'|s,a)` and reward function, enabling planning and simulation (e.g., AlphaZero).
- Model-free RL: Learns directly from trial-and-error interaction, without explicit models. Common and simpler, but typically requires more environment interactions.
Hybrid approaches like Dyna-Q use learned models to simulate additional experiences.
The Same Problem as MPC
For a deterministic model `x_{k+1} = f(x_k, u_k)`, the Bellman equation and MPC use the same stage cost, the negative of the reward:
$$\ell(x, u) = -R$$
Bellman equation
$$V^*(x) = \min_{u \in \mathcal{U}} \Big[ \ell(x, u) + \gamma\, V^*\big(f(x, u)\big) \Big]$$
MPC problem
$$\min_{u_0, \ldots, u_{N-1}} \left[\sum_{j=0}^{N-1} \ell(x_j, u_j) + V_f(x_N)\right]$$
subject to the model and initial state
$$x_{j+1} = f(x_j, u_j), \qquad x_0 = \hat x_k,$$
and the state and input limits
$$x_j \in \mathcal{X}, \qquad u_j \in \mathcal{U}.$$
RL learns `V^*` or the policy `\pi^*(x)` for every state, offline, from trials. MPC solves only for the current state, online, by looking `N` steps ahead with a model, and stands in for everything after the horizon with a terminal cost `V_f`. If `V_f` were the true `V^*` of the undiscounted problem (`\gamma = 1`, as in MPC), a horizon of one step would already be optimal. For a linear model with quadratic cost and no constraints, `V^*(x) = x^T P x` with `P` from the Riccati equation, and the optimal policy is the LQR gain.
| Reinforcement learning | Model predictive control | |
|---|---|---|
| Needs | many trials on a simulator or the plant, and a reward | a model, an estimator and a solver that finishes within the control period |
| Constraints | through penalties in the reward; met on average, not guaranteed | stated directly and enforced on the predicted trajectory |
| Online cost | one forward pass of a network | one optimization per sample |
| Verified by | testing the policy on many episodes | the model, the constraint set and closed-loop tests; stability results exist |
| Adapts by | retraining | updating the model and its parameters |
Applications of RL in Engineering Optimization:
RL applies broadly to engineering tasks involving sequential decision-making or control:
- Chemical Engineering: Process control and reaction optimization (e.g., reactor settings, energy minimization, yield improvement).
- Mechanical Engineering: Robotic control, autonomous systems (e.g., robotic arms, drones, inverted pendulum).
- Automotive: Autonomous driving (lane-keeping, cruise control, collision avoidance).
- Industrial Energy Management: HVAC optimization (e.g., DeepMind reduced Google data center cooling energy by ~40%).
These applications demonstrate RL’s effectiveness in engineering optimization, addressing complex, uncertain, and dynamic conditions.
Generative AI Learning
Check the answer: Check it on a linear model you have: run an MPC with horizon 1 and terminal cost x'Px from the Riccati equation, and compare its first move with the LQR move -Kx at several states with no constraint active. They must match. Then set the terminal cost to zero and see how long the horizon must be before the moves agree.