Self-Driving Policy Training (Q-learning)

A car learns a route through a city grid by trial and error. Other vehicles block cells and wet roads make steering slip.

Controls

Live readouts

Numerical checks

What to try
  • Press Train and watch the heat map (best value per cell) spread backwards from the goal flag.
  • Raise the slip probability: the best route now keeps a margin from blocked cells, because a slip can push the car into a vehicle.
  • Set epsilon to 0: learning stalls on a poor route. Too high: the car keeps wandering. The policy gap curve shows it.
The science

The city is a Markov decision process: states are grid cells, actions are N/E/S/W. Each step costs -1, reaching the goal gives +20, driving into another vehicle gives -20 and ends the episode, hitting the map edge keeps the car in place. With probability p (weather) the chosen action is replaced by a random one. Discount gamma = 0.95.

Q(s,a) <- Q(s,a) + alpha [ r + gamma max_a' Q(s',a') - Q(s,a) ]

The page also solves the same MDP exactly by value iteration (Bellman optimality, a contraction, so it converges) and shows the policy gap = V*(start) - V_pi(start), where V_pi is the exact expected return of the greedy learned policy. A gap near 0 means the learner found an optimal policy.

V*(s) = max_a sum_s' P(s'|s,a) [ r + gamma V*(s') ]

Honest simplifications: a toy grid, not real driving. Real autonomous systems use perception, continuous control, simulation at scale and far stricter validation; the numbers here say nothing about any real vehicle. Reward values and gamma are illustrative choices.