Socket
Socket
Sign inDemoInstall

egreedy

Package Overview
Dependencies
4
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

18

package.json
{
"name": "egreedy",
"description": "An epsilon-greedy multi-armed bandit algorithm",
"version": "0.4.0",
"version": "0.5.0",
"license": "ISC",

@@ -34,13 +34,13 @@ "main": "index.js",

"dependencies": {
"bluebird": "3.0.5",
"bluebird": "3.3.0",
"debug": "2.2.0",
"lodash": "3.10.1"
"lodash": "4.3.0"
},
"devDependencies": {
"chai": "3.4.0",
"eslint": "1.9.0",
"eslint-config-airbnb": "1.0.0",
"istanbul": "0.4.0",
"mocha": "2.3.3",
"sinon": "1.17.2"
"chai": "3.5.0",
"eslint": "1.10.3",
"eslint-config-airbnb": "5.0.0",
"istanbul": "0.4.2",
"mocha": "2.4.5",
"sinon": "1.17.3"
},

@@ -47,0 +47,0 @@ "scripts": {

@@ -26,8 +26,8 @@ egreedy

1. Create a bandit with 3 arms and epsilon 0.25:
1. Create an optimizer with 3 arms and epsilon 0.25:
```js
var Bandit = require('egreedy');
var Algorithm = require('egreedy');
var bandit = new Bandit({
var algorithm = new Algorithm({
arms: 3,

@@ -41,3 +41,3 @@ epsilon: 0.25

```js
bandit.select().then(function (arm) {
algorithm.select().then(function (arm) {
...

@@ -50,3 +50,3 @@ });

```js
bandit.reward(armId, value).then(function (n) {
algorithm.reward(armId, value).then(function (n) {
...

@@ -59,3 +59,3 @@ });

#### `Bandit([config])`
#### `Algorithm([config])`

@@ -80,6 +80,6 @@ Create a new optimization algorithm.

```js
> var Bandit = require('egreedy');
> var bandit = new Bandit();
> assert.equal(bandit.arms, 3);
> assert.equal(bandit.epsilon, 0.5);
> var Algorithm = require('egreedy');
> var algorithm = new Algorithm();
> assert.equal(algorithm.arms, 3);
> assert.equal(algorithm.epsilon, 0.5);
```

@@ -90,9 +90,9 @@

```js
> var Bandit = require('egreedy');
> var bandit = new Bandit({arms: 4, epsilon: 0.75});
> assert.equal(bandit.arms, 4);
> assert.equal(bandit.epsilon, 0.75);
> var Algorithm = require('egreedy');
> var algorithm = new Algorithm({arms: 4, epsilon: 0.75});
> assert.equal(algorithm.arms, 4);
> assert.equal(algorithm.epsilon, 0.75);
```
#### `Bandit#select()`
#### `Algorithm#select()`

@@ -112,5 +112,5 @@ Choose an arm to play, according to the specified bandit algorithm.

```js
> var Bandit = require('egreedy');
> var bandit = new Bandit();
> bandit.select().then(function (arm) { console.log(arm); });
> var Algorithm = require('egreedy');
> var algorithm = new Algorithm();
> algorithm.select().then(function (arm) { console.log(arm); });

@@ -120,3 +120,3 @@ 0

#### `Bandit#reward(arm, reward)`
#### `Algorithm#reward(arm, reward)`

@@ -127,3 +127,3 @@ Inform the algorithm about the payoff from a given arm.

- `arm` (Integer): the arm index (provided from `bandit.select()`)
- `arm` (Integer): the arm index (provided from `algorithm.select()`)
- `reward` (Number): the observed reward value (which can be 0, to indicate no reward)

@@ -138,5 +138,5 @@

```js
> var Bandit = require('egreedy');
> var bandit = new Bandit();
> bandit.reward(0, 1).then(function (n) { console.log(n); });
> var Algorithm = require('egreedy');
> var algorithm = new Algorithm();
> algorithm.reward(0, 1).then(function (n) { console.log(n); });

@@ -146,3 +146,3 @@ 1

#### `Bandit#serialize()`
#### `Algorithm#serialize()`

@@ -162,5 +162,5 @@ Obtain a plain object representing the internal state of the algorithm.

```js
> var Bandit = require('egreedy');
> var bandit = new Bandit();
> bandit.serialize().then(function (state) { console.log(state); });
> var Algorithm = require('egreedy');
> var algorithm = new Algorithm();
> algorithm.serialize().then(function (state) { console.log(state); });

@@ -175,9 +175,9 @@ {

#### `Bandit#load(state)`
#### `Algorithm#load(state)`
Restore an instance of a bandit to a previously serialized algorithm state. This method overrides any options parameters passed at instantiation.
Restore an instance of an algorithm to a previously serialized state. This method overrides any options parameters passed at instantiation.
**Arguments**
- `state` (Object): a serialized algorithm state (provided from `bandit.serialize()`)
- `state` (Object): a serialized algorithm state (provided from `algorithm.serialize()`)

@@ -192,5 +192,5 @@ **Returns**

> var state = {arms: 2, epsilon: 0.5, counts: [1, 2], values: [1, 0.5]};
> var Bandit = require('egreedy');
> var bandit = new Bandit();
> bandit.load(state).then(function (n) { console.log(n); });
> var Algorithm = require('egreedy');
> var algorithm = new Algorithm();
> algorithm.load(state).then(function (n) { console.log(n); });

@@ -215,3 +215,3 @@ 3

**Note:** tests against stochastic methods (e.g. `bandit.select()`) are inherently tricky to test with deterministic assertions. The approach here is to iterate across a semi-random set of conditions to verify that each run produces valid output. So, strictly speaking, each call to `npm test` is executing a slightly different test suite. At some point, the test suite may be expanded to include a more robust test of the distribution's properties – though because of the number of runs required, would be triggered with an optional flag.
**Note:** tests against stochastic methods (e.g. `algorithm.select()`) are inherently tricky to test with deterministic assertions. The approach here is to iterate across a semi-random set of conditions to verify that each run produces valid output. So, strictly speaking, each call to `npm test` is executing a slightly different test suite. At some point, the test suite may be expanded to include a more robust test of the distribution's properties – though because of the number of runs required, would be triggered with an optional flag.

@@ -218,0 +218,0 @@

@@ -8,3 +8,3 @@ /* global describe, it */

describe('Algorithm#load', function() {
describe('#load(state)', function() {
var Algorithm = require('../../index');

@@ -11,0 +11,0 @@ var arms = _.random(1, 10);

@@ -8,3 +8,3 @@ /* global describe, it */

describe('Algorithm#reward', function() {
describe('#reward(arm, reward)', function() {
var Algorithm = require('../../index');

@@ -11,0 +11,0 @@ var arms = _.random(1, 10);

@@ -9,3 +9,3 @@ /* global describe, it */

describe('Algorithm#select', function() {
describe('#select', function() {
var Algorithm = require('../../index');

@@ -12,0 +12,0 @@ var arms = _.random(1, 10);

@@ -8,3 +8,3 @@ /* global describe, it */

describe('Algorithm#serialize', function() {
describe('#serialize()', function() {
var Algorithm = require('../../index');

@@ -11,0 +11,0 @@ var arms = _.random(1, 10);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc