Skip to main content

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

Release files for thompson-sampling 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for thompson-sampling 0.0.4
File Size Uploaded
thompson-sampling-0.0.4.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for thompson-sampling 0.0.4
File Interpreter ABI Platform
thompson_sampling-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / thompson-sampling-0.0.4.tar.gz

Download URL thompson-sampling-0.0.4.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e9e648baa16141e4433f4809a7b749514f82998ff90aa501948a3a37de095854
BLAKE2b-256 checksum
How to use checksums
4a21ca385106995756eb1c1c3aca4dcc6201d3ff63d3c16da973e9d37450e666
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / thompson_sampling-0.0.4-py3-none-any.whl

Download URL thompson_sampling-0.0.4-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cdf7ec3eaab51d06c1853815ced2631a844a06a14a92415cac180fb8495b597b
BLAKE2b-256 checksum
How to use checksums
934dbdbc301026fde57cafe2c970466795b6c5df4bec75b9c1a91e03afe576f2
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page