Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


Reinforcement Learning Agents in Javascript (Dynamic Programming, Temporal Difference, Deep Q-Learning, Stochastic/Deterministic Policy Gradients)

Subscribe to updates I use reinforcejs

Statistics on reinforcejs

Number of watchers on Github 718
Number of open issues 17
Average time to close an issue about 1 month
Main language HTML
Average time to merge a PR 1 day
Open pull requests 5+
Closed pull requests 1+
Last commit almost 4 years ago
Repo Created over 4 years ago
Repo Last Updated over 1 year ago
Size 588 KB
Organization / Authorkarpathy
Page Updated
Do you use reinforcejs? Leave a review!
View open issues (17)
View reinforcejs activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating reinforcejs for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


REINFORCEjs is a Reinforcement Learning library that implements several common RL algorithms, all with web demos. In particular, the library currently includes:

  • Dynamic Programming methods
  • (Tabular) Temporal Difference Learning (SARSA/Q-Learning)
  • Deep Q-Learning for Q-Learning with function approximation with Neural Networks
  • Stochastic/Deterministic Policy Gradients and Actor Critic architectures for dealing with continuous action spaces. (very alpha, likely buggy or at the very least finicky and inconsistent)

See the main webpage for many more details, documentation and demos.

Code Sketch

The library exports two global variables: R, and RL. The former contains various kinds of utilities for building expression graphs (e.g. LSTMs) and performing automatic backpropagation, and is a fork of my other project recurrentjs. The RL object contains the current implementations:

  • RL.DPAgent for finite state/action spaces with environment dynamics
  • RL.TDAgent for finite state/action spaces
  • RL.DQNAgent for continuous state features but discrete actions

A typical usage might look something like:

// create an environment object
var env = {};
env.getNumStates = function() { return 8; }
env.getMaxNumActions = function() { return 4; }

// create the DQN agent
var spec = { alpha: 0.01 } // see full options on DQN page
agent = new RL.DQNAgent(env, spec); 

setInterval(function(){ // start the learning loop
  var action = agent.act(s); // s is an array of length 8
  //... execute action in environment and get the reward
  agent.learn(reward); // the agent improves its Q,policy,model, etc. reward is a float
}, 0);

The full documentation and demos are on the main webpage.



reinforcejs open issues Ask a question     (View All Issues)
  • about 3 years Math.tanh failures in node.js
  • over 3 years Breakout Example
  • almost 4 years Continuous control with deep reinforcement learning
  • almost 4 years Reinforcejs VS ConvNetjs
  • almost 4 years act and learn input ranges
  • almost 4 years Question about strategy
  • about 4 years Globals and exports
reinforcejs open pull requests (View All Pulls)
  • Adding Node.js support
  • fixing sign on update clipping
  • possible optimization to backprop; instead of creating functions, re-…
  • Add error handling for unused agents.
  • fix mathjax
reinforcejs list of languages used
Other projects in HTML