# reinforcement-learning

> Reinforcement learning in javascript

Latest version **1.0.20** (published 2019-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install reinforcement-learning
pnpm add reinforcement-learning
yarn add reinforcement-learning
bun add reinforcement-learning
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.20 |
| Published | 2019-11-22 |
| First published | 2019-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | samfulton |
| Keywords | reinforcement learning, tensorflow.js, tf.js, DQN, Q learning, Genetic algorithim, Deep learning, Neural network |

## Links

- npm: https://www.npmjs.com/package/reinforcement-learning
- npm.io page: https://npm.io/package/reinforcement-learning

## Dependencies (1)

- [@tensorflow/tfjs](https://npm.io/package/@tensorflow/tfjs.md) ^1.3.2

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.20 (latest) — 2019-11-22
- 1.0.19 — 2019-11-21
- 1.0.18 — 2019-11-21
- 1.0.17 — 2019-11-20
- 1.0.16 — 2019-11-20
- 1.0.15 — 2019-11-20
- 1.0.14 — 2019-11-20
- 1.0.13 — 2019-11-20
- 1.0.12 — 2019-11-20
- 1.0.0-1.1 — 2019-11-20
- 1.0.241 — 2019-11-20
- 1.0.24 — 2019-11-20
- 1.0.23 — 2019-11-20
- 1.0.22 — 2019-11-20
- 1.0.21 — 2019-11-20
- … 3 more at https://npm.io/package/reinforcement-learning/versions

## README

# reinforcement-learning

  

Easy reinforcement learning using tensorflow.js

  
  

*  [X] Deep Q Network (DQN)

* [ ] Genetic Algorithim (GA)

* [ ] Examples

* [ ] Training Dashboard (Tensorboard)

  

## Require

  

```javascript

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

  

```javascript
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](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/reinforcement-learning · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
