Bayesian bandit implementation for Node and the browser.

Overview

#bayesian-bandit.js

This is an adaptation of the Bayesian Bandit code from Probabilistic Programming and Bayesian Methods for Hackers, specifically d3bandits.js.

The code has been rewritten to be more idiomatic and also usable as a browser script or npm package. Additionally, unit tests are included.

#Quick Start

From node.js:

npm install bayesian-bandit
node

Then:

var Bandit = require('bayesian-bandit').Bandit

In the browser:

">

Sample JavaScript:

var bandit = new Bandit({ numberOfArms: 2 })

bandit.arms[0].reward(0) // Arm 0 loses once.
bandit.arms[0].reward(1) // Arm 0 wins once.

bandit.arms[1].reward(0) // Arm 1 loses once.
bandit.arms[1].reward(1) // Arm 1 wins once.
bandit.arms[1].reward(1) // Arm 1 wins twice.

bandit.selectArm() // Arm 1 is more likely, so this probably returns 1

If you have pre-existing data that you want to load, you can explicitly pass in data via constructor. The following creates a bandit with 3 arms

var bandit = new Bandit({
    arms: [{ count: 10, sum: 2 },
            { count: 20, sum: 10 },
            { count: 15: sum: 1}]
})

You can also take advantage of the rewardMultiple function on the arms:

var bandit = new Bandit({ numberOfArms: 3 })

bandit.arms[0].rewardMultiple(10, 2)  // Arm 0 wins 2 of 10 times
bandit.arms[1].rewardMultiple(20, 10) // Arm 1 wins 10 of 20 times 
bandit.arms[2].rewardMultiple(15, 1)  // Arm 2 wins 1 of 15 times

#Unit Tests

The unit tests use nodeunit, which should get installed with:

npm install

Then you can run unit tests with:

npm test
You might also like...

Run XGBoost model and make predictions in Node.js

XGBoost-Node eXtreme Gradient Boosting Package in Node.js XGBoost-Node is a Node.js interface of XGBoost. XGBoost is a library from DMLC. It is design

Nov 15, 2022

general natural language facilities for node

natural "Natural" is a general natural language facility for nodejs. It offers a broad range of functionalities for natural language processing. Docum

Jan 9, 2023

Machine-learning for Node.js

Limdu.js Limdu is a machine-learning framework for Node.js. It supports multi-label classification, online learning, and real-time classification. The

Dec 16, 2022

Machine Learning library for node.js

Machine Learning library for node.js

shaman Machine Learning library for node.js Linear Regression shaman supports both simple linear regression and multiple linear regression. It support

Feb 26, 2021

Powerful Neural Network for Node.js

NeuralN Powerful Neural Network for Node.js NeuralN is a C++ Neural Network library for Node.js with multiple advantages compared to existing solution

Dec 15, 2022

Latent Dirichlet allocation (LDA) topic modeling in javascript for node.js.

LDA Latent Dirichlet allocation (LDA) topic modeling in javascript for node.js. LDA is a machine learning algorithm that extracts topics and their rel

Nov 4, 2022

FANN (Fast Artificial Neural Network Library) bindings for Node.js

node-fann node-fann is a FANN bindings for Node.js. FANN (Fast Artificial Neural Network Library) is a free open source neural network library, which

Oct 31, 2022

A JavaScript deep learning and reinforcement learning library.

A JavaScript deep learning and reinforcement learning library.

neurojs is a JavaScript framework for deep learning in the browser. It mainly focuses on reinforcement learning, but can be used for any neural networ

Jan 4, 2023
Comments
  • Adding some additional functionality to make it easier to set up Bandit from pre-existing data

    Adding some additional functionality to make it easier to set up Bandit from pre-existing data

    Adding Arm.rewardMultiple to enable adding multiple counts / total reward to an arm

    Adding a new form of constructor so you don't even have to call reward, you can simply initialize all the arms by passing in an array of {count, sum} objects

    My specific use case: running a multi-armed bandit test online for ad CTR. I have views / clicks in the database and don't want to have to loop over reward(0)/reward(1) to get the bandit in the correct state.

    opened by jonathan-fulton 6
Owner
null
architecture-free neural network library for node.js and the browser

Synaptic Important: Synaptic 2.x is in stage of discussion now! Feel free to participate Synaptic is a javascript neural network library for node.js a

Juan Cazala 6.9k Dec 27, 2022
Clustering algorithms implemented in Javascript for Node.js and the browser

Clustering.js ####Clustering algorithms implemented in Javascript for Node.js and the browser Examples License Copyright (c) 2013 Emil Bay github@tixz

Emil Bay 29 Aug 19, 2022
JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js

face-api.js JavaScript face recognition API for the browser and nodejs implemented on top of tensorflow.js core (tensorflow/tfjs-core) Click me for Li

Vincent Mühler 14.6k Jan 2, 2023
Train and test machine learning models for your Arduino Nano 33 BLE Sense in the browser.

Tiny Motion Trainer Train and test IMU based TFLite models on the Web Overview Since 2009, coders have created thousands of experiments using Chrome,

Google Creative Lab 59 Nov 21, 2022
Deep Learning in Javascript. Train Convolutional Neural Networks (or ordinary ones) in your browser.

ConvNetJS ConvNetJS is a Javascript implementation of Neural networks, together with nice browser-based demos. It currently supports: Common Neural Ne

Andrej 10.4k Dec 31, 2022
Run Keras models in the browser, with GPU support using WebGL

**This project is no longer active. Please check out TensorFlow.js.** The Keras.js demos still work but is no longer updated. Run Keras models in the

Leon Chen 4.9k Dec 29, 2022
The Fastest DNN Running Framework on Web Browser

WebDNN: Fastest DNN Execution Framework on Web Browser WebDNN is an open source software framework for executing deep neural network (DNN) pre-trained

Machine Intelligence Laboratory (The University of Tokyo) 1.9k Jan 1, 2023
A library for prototyping realtime hand detection (bounding box), directly in the browser.

Handtrack.js View a live demo in your browser here. Handtrack.js is a library for prototyping realtime hand detection (bounding box), directly in the

Victor Dibia 2.7k Jan 3, 2023
A speech recognition library running in the browser thanks to a WebAssembly build of Vosk

A speech recognition library running in the browser thanks to a WebAssembly build of Vosk

Ciaran O'Reilly 207 Jan 3, 2023
This is a JS/TS library for accelerated tensor computation intended to be run in the browser.

TensorJS TensorJS How to use Tensors Tensor operations Reading values Data types Converting between backends Onnx model support Optimizations Running

Frithjof Winkelmann 32 Jun 26, 2022