vrishank

← Blog

Lecture 18: Continuous State MDPs and Model Simulation

Stanford CS229 lecture 18 notes: Continuous State MDPs and Model Simulation.

· 2 min read

  • cs229
  • machine-learning
  • course-notes
On this page

The problem with continuous states#

Real systems have continuous states. A car has position and velocity, and a helicopter has position, orientation (3 angles), and velocities, which is a 12 dimensional continuous state. We can't keep a table with one value per state.

Option 1: Discretization#

Chop the continuous space into a grid, and treat each cell as a discrete state.

It works for 1 or 2 dimensions. But it has two big problems:

  1. Piecewise constant representation: the value function is flat within each cell, so you need very fine grids for smooth functions.
  2. Curse of dimensionality: if each dimension has kk values, then an nn-dimensional state has knk^n cells. With k=100k=100 and n=4n=4, that's 10810^8 states. With 12 dimensions, it's hopeless.

Discretization is fine for problems up to around 4D, and sometimes up to 6D with care.

Option 2: Fitted Value Iteration#

Approximate the value function with a parametric function, such as a linear function of some features:

V(s)=θTϕ(s)V(s) = \theta^T\phi(s)

where ϕ(s)\phi(s) is a feature vector (e.g., [1,s1,s2,s1s2,s12,...][1, s_1, s_2, s_1s_2, s_1^2, ...]).

Needing a model#

To compute the value iteration update, we need to compute an expectation over next states. We usually don't have a closed form, so we need a simulator (model) that, given (s,a)(s, a), produces a next state s′s'.

The algorithm#

Sample mm states s(1),...,s(m)s^{(1)}, ..., s^{(m)} at random. Then repeat:

For each sample state s(i)s^{(i)} and each action aa:

  1. Sample kk next states s1′,...,sk′∼Ps(i)as'_1, ..., s'_k \sim P_{s^{(i)}a} from the simulator.
  2. Compute q(a)=1k∑j=1k[R(s(i))+γV(sj′)]q(a) = \frac{1}{k}\sum_{j=1}^{k}\left[R(s^{(i)}) + \gamma V(s'_j)\right].

Set the target: y(i)=max⁡aq(a)y^{(i)} = \max_a q(a).

Then fit θ\theta with linear regression, so that θTϕ(s(i))≈y(i)\theta^T\phi(s^{(i)}) \approx y^{(i)}:

θ:=arg⁡min⁡θ12∑i=1m(θTϕ(s(i))−y(i))2\theta := \arg\min_\theta \frac{1}{2}\sum_{i=1}^{m}\left(\theta^T\phi(s^{(i)}) - y^{(i)}\right)^2

So fitted value iteration is just value iteration, where the "assignment" step is replaced by a regression. It's not guaranteed to converge in general, but works well in practice.

Where does the simulator come from?#

Physics-based simulators#

Built from the equations of motion. Used in robotics, games, etc.

Learning a model from data#

Have a human (or a random policy) control the system, record the transitions (st,at,st+1)(s_t, a_t, s_{t+1}), and fit a model. A simple choice is a linear model:

st+1=Ast+Bats_{t+1} = As_t + Ba_t

fit by least squares:

arg⁡min⁡A,B∑i∑t∥st+1(i)−(Ast(i)+Bat(i))∥2\arg\min_{A,B}\sum_{i}\sum_{t}\left\|s_{t+1}^{(i)} - \left(As_t^{(i)} + Ba_t^{(i)}\right)\right\|^2

You can add features to make it non-linear, like using [st,st2,...][s_t, s_t^2, ...] as inputs.

Making it stochastic#

Real systems are noisy, so we add noise: st+1=Ast+Bat+ϵts_{t+1} = As_t + Ba_t + \epsilon_t, with ϵt∼N(0,σ2I)\epsilon_t \sim \mathcal{N}(0, \sigma^2 I). This is a stochastic simulator, and it lets the algorithm account for uncertainty.