Skip to content

A golang library for solving multi armed bandit problem which can optimize your business choice on the fly without A/B testing

Notifications You must be signed in to change notification settings

rueian/gobandit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gobandit

CircleCI codecov

A golang library for solving multi armed bandit problem which can optimize your business choice on the fly without A/B testing.

Thompson Sampling

package main

import (
	"time"
	
	"github.com/rueian/gobandit/thompson"
)

func init() {
	thompson.Seed(time.Now().Unix())
}

func main() {
    // load your candidate statistics, for example:
    candidates := [][2]float64{
        {1000, 500}, // candidate 0 => likeCount: 1000, dislikeCount: 500
        {500, 1000}, // candidate 1 => likeCount: 500, dislikeCount: 1000
    }
    
    for {
        // let Thompson Sampling choose a candidate based on the statistics
        elected, _ := thompson.Choose(candidates)
        
        // use the elected one, and collect feedback to update the statistic for next choose
        if peopleLike(elected) {
            candidates[elected][0]++
        } else {
            candidates[elected][1]++
        }
        
        if done() {
            break
        }
    }
}

About

A golang library for solving multi armed bandit problem which can optimize your business choice on the fly without A/B testing

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages