Skip to content

Elsa-Health/bayesian-bandits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bayesian Bandits

References:

Quick Start:

In the root of your folder run yarn add bayesian-bandits to install the package.

Inside your JS/TS files:

// Example to help Megan choose what chocolate to buy for maximum enjoyment
// without making it completely impossible for tastes to change
import { chooseArm, rewardArm, bernoulli } from 'bayesian-bandits';

const candies = {
  arms: [
    {
      attempts: 20,
      sum: 10,
      name: 'Twix',
    },
    {
      attempts: 20,
      sum: 18,
      name: 'Recees',
    },
    {
      attempts: 20,
      sum: 14,
      name: 'Top Deck',
    },
    {
      attempts: 20,
      sum: 1,
      name: 'Mounds',
    },
  ],
};

// To choose the arm you want to pull
const armIndex = chooseArm(banditState.arms);

// Deremine the reward for the arm based on your application logic
const armReward = 1;

// Number of total attemts that resulted in the above reward
const attempts = 1;

const updatedBanditArms = rewardArm(
  candies.arms,
  armIndex,
  armReward,
  attempts
);

// Store the updated Bandit Arms in state ready for reuse later on.
// storeSomethingMethod(updatedBanditArms);
console.log(updatedBanditArms);

License

MIT