The DQN model uses a fixed architecture and baseline hyperparameter set drawn directly from the original Python notebook. These values are reflected in the browser demo’s DQN MODEL PROFILE panel and define the behavior of both the Keras implementation and its JavaScript recreation.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/apursley2012/cartpole/llms.txt
Use this file to discover all available pages before exploring further.
Network Architecture
The network is a three-layer fully connected (dense) model. Four input neurons correspond to the four state observations provided by CartPole-v1: cart position, cart velocity, pole angle, and pole angular velocity. Two hidden layers of 24 neurons each use ReLU activation. The output layer produces one Q-value per action — left or right — using a linear activation so the values are unbounded.| Layer | Neurons | Activation |
|---|---|---|
| Input | 4 | — (state observations) |
| Hidden Layer 1 | 24 | ReLU |
| Hidden Layer 2 | 24 | ReLU |
| Output | 2 | Linear (Q-values) |
- Loss: Mean Squared Error (MSE)
- Optimizer: Adam (
lr = 0.001)
Cartpole.ipynb
Configuration Values
The full set of baseline constants used inCartpole.ipynb. All nine values are reproduced exactly in the browser demo’s DQN MODEL PROFILE panel.
| Parameter | Value | Description |
|---|---|---|
| ENV_NAME | CartPole-v1 | OpenAI Gym environment |
| GAMMA | 0.95 | Discount factor for future rewards |
| LEARNING_RATE | 0.001 | Adam optimizer learning rate |
| MEMORY_SIZE | 1,000,000 | Maximum replay memory capacity |
| BATCH_SIZE | 20 | Experiences sampled per replay |
| EXPLORATION_MAX | 1.0 | Starting exploration rate (fully random) |
| EXPLORATION_MIN | 0.01 | Minimum exploration rate (1% random) |
| EXPLORATION_DECAY | 0.995 | Multiplicative decay per replay |
| Network shape | 24 → 24 → 2 | Three dense layers |
Python Dependencies
The notebook relies on the following imports.gym provides the CartPole-v1 environment, keras provides the sequential dense network and Adam optimizer, and ScoreLogger is a local utility that tracks per-run scores against the solve threshold.
Cartpole.ipynb
JavaScript Equivalents
The browser demo maps every Python constant to a matching property on theDQNAgent constructor. The network weights are initialized as plain JavaScript arrays and the forward pass is handled by a manual dense() method that applies ReLU or linear activation per layer.
The JavaScript version uses manual gradient descent instead of the Adam optimizer. Each weight is updated directly with
weight += learningRate * error * activation, and only the output layer and second hidden layer receive gradient updates per sample. This is a browser-only simplification — the original Python notebook uses Keras’s full Adam implementation with momentum and adaptive learning rates.