HomeAI & Machine LearningCartPole REINFORCE: Policy Field in Phase Space (2D)

CartPole REINFORCE: Policy Field in Phase Space (2D)

A flat 2D counterpart of the CartPole REINFORCE simulator: instead of rendering the cart and pole mechanically, it draws the agent's learned decision field over the pole's angle/angular-velocity plane — a live heatmap of push-left vs push-right probability, redrawn after every REINFORCE update, with the current episode's trajectory tracing through it.

AI & Machine Learning2DAdvanced60 FPS📱 Mobile-adapted⇄ 3D version
2d-reinforcement-learning-policy-gradient-cartpole ↗ Open standalone

This is the flat, native-2D counterpart of the 3D CartPole REINFORCE simulator. It runs the identical Barto–Sutton–Anderson cart-pole physics and the identical Monte-Carlo policy-gradient training loop — a linear softmax policy updated after every episode by the true REINFORCE rule, ∇log π(a|s) times the discounted return minus an optional baseline — but instead of animating a 3D cart and pole, it renders the thing the algorithm actually learns: a live heatmap of push-left vs push-right probability over the pole's angle/angular-velocity plane, with the running episode's real state trajectory traced through that same field. Watch the decision boundary sharpen and curl around θ=0 as training proceeds, while the episode-length graph and live stats confirm the agent is actually getting better at balancing.

⚙ Under the hood

The flat 2D counterpart of the CartPole REINFORCE simulator: the identical Barto-Sutton-Anderson physics and Monte-Carlo policy-gradient training run independently here, but rendered as a live heatmap of push-left vs push-right probability over the pole's angle/angular-velocity plane, with the current episode's real trajectory traced through that same decision field.

reinforcement-learningpolicy-gradientREINFORCEcartpolephase-spaceneural-network

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)