Policy gradients from scratch

Demo

CartPole-v1, running in your browser. The physics are the Gymnasium equations rewritten in TypeScript, and the action comes from the trained network replayed from its exported weights. Nothing is computed on a server.

No run has exported weights yet, so this is a random agent. The trained policy will appear here after the first run finishes and export_policy writes its policy.json.

0steps this episoden/alast episode0best0episodes
Agent

Actions are coin flips. Expect the pole to fall in roughly twenty steps.

Action probabilities

The random agent has no policy to read. Turn it off to watch the network decide.

cart position
0.000
cart velocity
0.000
pole angle
0.000
pole velocity
0.000

What you are looking at

The agent sees four numbers: the position and velocity of the cart, and the angle and angular velocity of the pole. It chooses to push left or right. The episode ends when the pole passes twelve degrees from vertical, when the cart reaches the edge of the track, or at 500 steps, which is the highest score the environment allows.