Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

reinforcement-learning

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reinforcement-learning

Reinforcement learning in javascript

latest
npmnpm
Version
1.0.20
Version published
Weekly downloads
37
117.65%
Maintainers
1
Weekly downloads
 
Created
Source

reinforcement-learning

Easy reinforcement learning using tensorflow.js

  • Deep Q Network (DQN)

  • Genetic Algorithim (GA)

  • Examples

  • Training Dashboard (Tensorboard)

Require


const  rl = require('reinforcement-learning');

DQN

Parameters

  • arch - Architechture of the neural network

  • epsilon - % of actions that should be taken randomly for exploration

  • epsilonDecay - Epsilon will be multiplied by this amount every episode

  • replayMemorySize - Amount of previous steps left in memory to train on

  • miniBatchSize - Batch size to fit on

  • actionSpaceSize - Amount of possible actions the agent can take

  • minReplaySize - Minimum amount of memories allowed for fitting

  • updateTargetEvery How many episodes to wait to update the predictions network

  • accuracyLookbackSize How many previous steps should be used to calculate accuracy

const  rl = require('reinforcement-learning');
let  step = 0;


let  arch = [
{inputShape:  1, units:  14, activation:  'relu'},
{units:  2, activation:  'softmax'}
];
  
function  getState(){return [0];}

function  calcReward(state, action){
// Every 100 steps end the episode
step++;
let  episodeDone = false;
if(step === 100){episodeDone = true; step = 0;}

// Two armed bandit. Agent has to learn to always pick 1
if(action === 1)return {reward:  1, newState:[0], done:  true, episodeDone};
else{ return {reward:  0, newState:[0], done:  true, episodeDone}}
}


(async()=>{
let  agent = rl.DQN({
arch,
epsilon:  0,
epsilonDecay:  0,
replayMemorySize:  1000,
miniBatchSize:  64,
actionSpaceSize:  2,
minReplaySize:  100,
updateTargetEvery:  1,
accuracyLookbackSize:  500
});

  
await  agent.learn({accuracy:  95, getState, calcReward});

  
})();

License

MIT

Keywords

reinforcement learning

FAQs

Package last updated on 22 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts