◗ Reinforcement Learning LabControl TasksGame Play
Deep Reinforcement Learning · Portfolio

RL Agent Playground

DQN · PyTorch · Live WebSocket stream

Watch a neural network learn from scratch. The agent below starts knowing nothing — it controls a physics simulation by trial and error and, episode after episode, discovers a strategy on its own. No demonstrations, no labelled data, only reward.

Hover any ? icon for a plain definition. Press Start, then use the Agent View to replay any episode and watch a clumsy first try turn into a confident one.

Agent View — CartPole-v1

press Start to record a run
NO EPISODE TO REPLAY YET
Once an episode finishes, replay it here and watch the agent act step by step — exactly what it sees turned into motion.

Live Training — CartPole-v1

Ready
The agent knows nothing yet.Choose an environment and hyperparameters, then press Start. The neural network begins with random weights — its very first moves are pure guesswork.
EpisodeHow many full attempts the agent has completed in this run.
Best RewardThe highest score reached in any single episode — the agent's personal best so far.
Epsilon (ε)The probability the agent acts randomly instead of using what it learned. Starts at 1.0 (fully random) and decays toward 0.05.
1.000
LossHow wrong the network's reward predictions were this episode. It often rises before it falls — normal as the agent meets new situations.
AWAITING TRAINING DATA
Press Start — each completed episode plots one point here.
Reward — score per episodeEpsilon — random-action rate (0–1)Target — counts as solved

A healthy run shows the cyan reward line climbing toward the target as the amber epsilon line falls — the agent earns more while relying less on random luck.

How This Agent Learns

Deep Q-Network (DQN)

Deep Q-Networks were introduced by DeepMind in 2015 to play Atari games from raw pixels. This project applies the same algorithm to classic control tasks. Six ideas make it work:

01

The trial-and-error loop

At each step the agent observes the environment's state, chooses an action, and receives a reward plus the next state. RL is the search for an action-picking rule — a policy — that maximises total reward. There are no labelled answers, only this feedback.

02

Q-values — scoring each action

A neural network maps the current state to one number per action: the Q-value, its estimate of the total future reward that action leads to. The agent simply picks the action with the highest Q-value.

03

Exploration vs. exploitation

An agent that always picks its current best guess never discovers anything better. Epsilon (ε) is the chance of acting randomly — it starts at 1.0 (fully random) and decays to 0.05, so the agent explores early and exploits later.

04

Experience replay

Every transition (state, action, reward, next state) is saved to a 20,000-slot memory buffer. Training samples random batches from it, which breaks the correlation between consecutive steps and lets each experience teach the network many times.

05

Target network

Learning targets come from a frozen copy of the network, re-synced only every 10 episodes. Without it the network would chase a target that shifts every step — like aiming at your own reflection — and training would diverge.

06

The Bellman update

Each step nudges the prediction toward reward + γ × (best Q-value of the next state), where γ = 0.99 discounts future reward. Repeated across millions of steps, this temporal-difference update flows reward back onto the actions that earned it.

System architecture

metrics stream back the other way — Trainer → API → WebSocket → Browser
Browser
Next.js · React

Renders the controls and the live SVG chart, and opens one WebSocket per run.

API
FastAPI

Takes the run config, starts a training session, and streams every episode's metrics.

Trainer
PyTorch

A background thread runs the DQN training loop episode by episode.

Environment
Gymnasium

Simulates the physics and returns a reward + next state on every step.