Skip to main content

Thompson Sampling

Project description

thompson-sampling

Thompson Sampling Multi-Armed Bandit for Python

This project is an implementation of a Thompson Sampling approach to a Multi-Armed Bandit. The goal of this project is to easily create and maintain Thompson Sampling experiments.

Currently this project supports experiments where the response follows a Bernoulli or Poisson distribution. Further work will be done to allow for experiments that follow other distributions, with recommendations/collaboration welcome.

Usage

Setting up the experiment:

The following method will instantiate the experiment with default priors.

from thompson_sampling.bernoulli import BernoulliExperiment

experiment = BernoulliExperiment(arms=2)

If you want set your own priors using the Priors module:

from thompson_sampling.bernoulli import BernoulliExperiment
from thompson_sampling.priors import BetaPrior

pr = BetaPrior()
pr.add_one(mean=0.5, variance=0.2, effective_size=10, label="option1")
pr.add_one(mean=0.6, variance=0.3, effective_size=30, label="option2")
experiment = BernoulliExperiment(priors=pr)

Getting an action:

Randomly chooses which arm to "pull" in the multi-armed bandit:

experiment.choose_arm()

Updating reward:

Updating the information about the different arms by adding reward information:

rewards = [{"label":"option1", "reward":1}, {"label":"option2", "reward":0}]
experiment.add_rewards(rewards)

Installation

Pip

pip install thompson-sampling

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thompson-sampling-0.0.4.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thompson_sampling-0.0.4-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file thompson-sampling-0.0.4.tar.gz.

File metadata

  • Download URL: thompson-sampling-0.0.4.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/3.7.6

File hashes

Hashes for thompson-sampling-0.0.4.tar.gz
Algorithm Hash digest
SHA256 e9e648baa16141e4433f4809a7b749514f82998ff90aa501948a3a37de095854
MD5 8f72b77b3037ce722fe79df30804ceb6
BLAKE2b-256 4a21ca385106995756eb1c1c3aca4dcc6201d3ff63d3c16da973e9d37450e666

See more details on using hashes here.

File details

Details for the file thompson_sampling-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: thompson_sampling-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/3.7.6

File hashes

Hashes for thompson_sampling-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cdf7ec3eaab51d06c1853815ced2631a844a06a14a92415cac180fb8495b597b
MD5 8c699908f4eb8100bc822ee28baaeee5
BLAKE2b-256 934dbdbc301026fde57cafe2c970466795b6c5df4bec75b9c1a91e03afe576f2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page