• Stars
    star
    887
  • Rank 51,456 (Top 2 %)
  • Language
    R
  • License
    Other
  • Created about 12 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code for my book on Multi-Armed Bandit Algorithms

Code to Accompany the Book "Bandit Algorithms for Website Optimization"

This repo contains code in several languages that implements several standard algorithms for solving the Multi-Armed Bandits Problem, including:

  • epsilon-Greedy
  • Softmax (Boltzmann)
  • UCB1
  • UCB2
  • Hedge
  • Exp3

It also contains code that provides a testing framework for bandit algorithms based around simple Monte Carlo simulations.

Languages

This codebase is split up by language. In most languages, there are parallel implementations of the core algorithms and infrastructure for testing the algorithms:

  • Python
  • Julia
  • Ruby

In R, there is a body of code for visualizing the results of simulations and analyzing those results. The R code would benefit from some refactoring to make it DRYer.

If you're interested in seeing how some of these algorithms would be implemented in Javascript, you should try out Mark Reid's code: http://mark.reid.name/code/bandits/

If you're looking for Java code, try Dani Sola's work: https://github.com/danisola/bandit

If you're looking for Scala code, try everpeace(Shingo Omura)'s work: https://github.com/everpeace/banditsbook-scala

If you're looking for Go code, try Rany Keddo's work: https://github.com/purzelrakete/bandit

If you're looking for Clojure code, try Paul Ingles's work: https://github.com/pingles/clj-bandit

If you're looking for Swift code, see https://github.com/crenwick/Swiper

For a Flask implementation, see https://github.com/DeaconDesperado/flask_mab

Getting Started

To try out this code, you can go into the Python or Julia directories and then run the demo script.

In Python, that looks like:

python demo.py

In Julia, that looks like:

julia demo.jl

You should step through that code line-by-line to understand what the functions are doing. The book provides more in-depth explanations of how the algorithms work.

The Ruby code was contributed by Kashif Rasul. If you're interested in translating the code into another language, please submit a pull request. I will merge any new implementations as soon as I can.

Adding New Algorithms: API Expectations

As described in the book, a Bandit algorithm should implement two methods:

  • select_arm(): A method that returns the index of the Arm that the Bandit object selects on the current play. No arguments are required.
  • update(): A method that updates the internal state of the Bandit object in response to its most recently selected arm's reward. The index of the chosen arm and the amount of reward received must be passed as arguments.

As described in the book, an Arm simulator should implement:

  • draw(): A method that returns a single instance of reward from the arm that was pulled. No arguments are required.

In addition, the Bandit algorithms are designed to implement one additional method used in simulations:

  • initialize(): A method that returns nothing. Instead, this method resets all of the data-driven variables in a Bandit object. For most objects, this resets the counts and values field to their initial states. No arguments are required.

Beyond the testing framework described in the book, I am currently providing an additional system built around the concept of an Environment. Environment objects encapsulate not only a set of Arms, but also a mechanism for having those Arms change over time. This allows you to simulate complex scenarios that aren't well described by a constant set of arms.

If you would like to implement your own Environment, you will need to provide a very simple interface. The Environment interface requries you to implement two methods:

  • arms(): A method that returns the array of arms that exist at time T. You must pass T as an argument.
  • n_arms(): A method that returns the number of arms that the environment will return with each call to arms(). While the arms may change over time, the number of arms should not. No arguments are required.

More Repositories

1

ML_for_Hackers

Code accompanying the book "Machine Learning for Hackers"
R
3,650
star
2

MLNotes

Very concise notes on machine learning and statistics.
R
379
star
3

SimpleAintEasy

A compendium of the pitfalls and problems that arise when using standard statistical methods
R
243
star
4

julia_tutorials

Tutorials on Julia topics
Jupyter Notebook
197
star
5

JAGSExamples

Examples of statistical models implemented using JAGS
R
97
star
6

log4r

A log4j derivative for R.
R
92
star
7

Vega.jl

A Julia package for generating visualizations in Vega
Julia
84
star
8

r_recommendation_system

Data and code for the Dataists R recommendation system contest
R
75
star
9

Style.jl

Style guideline for Julia
74
star
10

JuliaVsR

Comparisons between Julia and R
HTML
58
star
11

bayesian_nonparametrics

Slides and code for Bayesian nonparametrics in R and Julia
R
53
star
12

StreamStats.jl

Compute statistics over data streams in pure Julia
Julia
48
star
13

Benchmarks.jl

A new benchmarking library for Julia
Julia
45
star
14

ASCIIPlots.jl

Generate simple plots as ASCII art in Julia
Julia
38
star
15

TextRegression

An R package that automates text regression analysis.
R
31
star
16

BehavioralEconomics

R package for behavioral economics
R
31
star
17

MNIST.jl

Tools for working with the MNIST data set
Julia
25
star
18

Volcanito.jl

A backend agnostic for tabular data operations in Julia
Julia
25
star
19

kNN.jl

The k-nearest neighbors algorithm in Julia
Julia
22
star
20

r-ORM

An ORM library for R.
19
star
21

Benchmark.jl

A package for benchmarking code and packages
Julia
18
star
22

BloomFilters.jl

Bloom filters in Julia
Julia
18
star
23

room_temperatures

Dataset of temperatures in 6 rooms of my home recorded once per minute
R
16
star
24

StatsFunctionsNotes

Jupyter notebooks showing to implement statistical functions.
Jupyter Notebook
14
star
25

HopfieldNets.jl

Hopfield networks in Julia
Julia
14
star
26

r_squared

Code for blog post on r-squared
R
13
star
27

ContinuedFractions.jl

Types and functions for working with continued fractions in Julia
Julia
12
star
28

Ranking.jl

Tools for ranking in Julia
Julia
11
star
29

CorruptCSVs

Examples of corrupt CSV files and how they trick various parsers
R
10
star
30

julia-function-docs

Repo for materials for coordinating work on improving Julia's function documentation
10
star
31

cumplyr

An extension of plyr that uses inequality constraints.
R
9
star
32

titlecase-itunes-tracks

A utility to rename the tracks in an iTunes library so that the artist, album and track name are all in proper English title case.
9
star
33

MySQL.jl

MySQL DBI driver
Julia
9
star
34

sudoku.jl

A simple Sudoku solver in Julia
Julia
8
star
35

IntertemporalChoiceHeuristics

Analysis pipeline for Psychological Science paper called "Money Earlier or Later? Simple Heuristics Explain Intertemporal Choices Better than Delay Discounting"
R
8
star
36

DataFramesIO.jl

Advanced import/export tools for DataFrames: Stata, SPSS, Excel, JSON
Julia
8
star
37

DG2012Tutorial.jl

Simple examples of SGD-style computations in Julia
Julia
8
star
38

computer_music

R functions for generating computer music.
R
8
star
39

Brainfuck.jl

A Brainfuck interpreter written in Julia
Julia
7
star
40

Resampling.jl

Tools for resampling data in Julia
Julia
7
star
41

analytics_x_prize

Code and data used for submissions to the Analytics X Prize
Python
7
star
42

IsingModels.jl

The Ising model as a Julian distribution
Julia
7
star
43

PowerAnalysis.jl

Tools for power analysis in Julia
Julia
7
star
44

spatial_statistics_in_r

Slides and code on spatial statistics in R.
7
star
45

FFIExamples.jl

Simple examples of Julia's FFI as of v0.4
Julia
7
star
46

HackerSchoolTalk

A talk to the Summer 2013 batch of Hacker School students
Ruby
7
star
47

KLDivergence.jl

KL-divergence estimation in Julia
Julia
7
star
48

TicTacToe.jl

Use Reinforcement Learning to teach a computer to play Tic-Tac-Toe
Julia
6
star
49

projecteuler.jl

Solutions to Project Euler problems in Julia
Julia
6
star
50

bayesian_canabalt

A Bayesian exploratory analysis of Canabalt scores.
R
6
star
51

JAGSIntro

A short intro to probabilistic programming using JAGS
R
6
star
52

TypeTree.jl

An interactive visualization of the Julia type hierarchy
JavaScript
6
star
53

regularization_slides

An introduction to statistical regularization
6
star
54

NaiveBayes.jl

Naive Bayes models in Julia
Julia
5
star
55

NearestNeighbors.jl

Data structures for nearest neighbor search
Julia
5
star
56

Proximal.jl

Translation of Parikh and Boyd code for proximal algorithms
Julia
5
star
57

SortableHTMLTables

A package for writing data frames as sortable HTML tables.
JavaScript
4
star
58

Loss.jl

Loss functions
Julia
4
star
59

senate_analyses

Statistical Analyses of the U.S. Senate
R
4
star
60

webcast_examples

Examples for O'Reilly webcast
R
4
star
61

utils.jl

Utility functions for Julia + R compatibility wrapper
Julia
4
star
62

bayesian-decryption

An example R program that decrypts text encrypted using a substitution cipher.
R
4
star
63

IntertemporalChoice

An R package for modeling intertemporal choice data.
4
star
64

stringops

An R library for manipulating strings.
4
star
65

DCStats.jl

IJulia Notebooks that provide a brief introduction to Julia for statistical programming
4
star
66

cran-function-usage-analysis

Code to spider CRAN, tokenize package source code and analyze function usage both within and across packages.
3
star
67

fastR

Examples of writing faster R code.
R
3
star
68

CSVReaders.jl

A CSV parsing toolkit for Julia
Julia
3
star
69

julia_nyhackr

Slides about Optimization in Julia for NY R Meetup
R
3
star
70

GiltTalk

Slides for course at Gilt
R
3
star
71

julia_package_system

A package system for Julia.
Julia
3
star
72

UCSD2014Talk

Talk to Bradley Voytek's Data Science class at UCSD
R
3
star
73

FourierDescriptors

Generate images using Fourier descriptors.
R
3
star
74

NYCMarathon

Statistical Analyses of the NYC Marathon
R
3
star
75

DataGotham.jl

IJulia Notebook with material for DataGotham tutorial on using Julia for data analysis
3
star
76

cran_analysis

Analyses of CRAN packages
R
3
star
77

SimpleML.jl

Textbook implementations of ML algorithms in Julia using Optim.jl
Julia
3
star
78

CategoricalData.jl

Tools for working with categorical/ordinal data
Julia
3
star
79

DataFrameDemo

A demo of DataFrame's in Julia.
3
star
80

Ridge.jl

Ridge regression and classification
Julia
3
star
81

Wordle.jl

A Julia library for solving Wordle puzzles.
Jupyter Notebook
3
star
82

fmri_utilities

A set of basic utility methods for analyzing fMRI data in R.
3
star
83

ProbabilisticModeling.jl

A BUGS-like language for describing probabilistic models in Julia
Julia
2
star
84

Roxygen.jl

A Roxygen-like documentation package
Julia
2
star
85

FiniteDiff.jl

A replacement for the finite-differencing code in Calculus.jl
Julia
2
star
86

abbReviations

Functions for dealing with common abbreviations.
R
2
star
87

winsorization_simulation_study

A simulation study of winsorization
R
2
star
88

NHSTExamples

Examples of how NHST really works
R
2
star
89

PackageTesting.jl

A standard for testing Julia packages
Julia
2
star
90

DesignSpace.jl

Show part of the design space for NullableArrays
Julia
2
star
91

r_social_dynamics

Quantitative data on the social dynamics of the R community.
R
2
star
92

ggplots

A wrapper library that provides functions for common plots using ggplot2.
R
2
star
93

HyperLogLog.jl

HyperLogLog in Julia
Julia
2
star
94

Calculus2.jl

A draft of a new interface for the Calculus package
Julia
2
star
95

sf_politics

Endorsement data for SF politics
R
2
star
96

ML4H.jl

Machine Learning for Hackers in Julia
Julia
2
star
97

clean

A utility to recursively purge directories of all files identified by a naming convention.
2
star
98

ncclab

Rails code for the NCC Lab's website.
JavaScript
2
star
99

stroop

The classic Stroop task in R.
R
2
star
100

FileFind.jl

File::Find implementation in Julia
Julia
2
star