tsampling
Thompson Sampling Multi-Armed Bandit for Python
A package that implements the Thompson Sampling approach for a Multi-Armed Bandit. The purpose of this project is to help people simply create and maintain Thompson Sampling experiments that have Bernoulli and Poisson distributions.
Usage
Setting up the experiment:
The following method will instantiate the experiment with the default priors.
from tsampling.bernoulli import BernoulliExperiment
experiment = BernoulliExperiment(arms=2)
You can also set your custom priors by using the Priors module:
from tsampling.bernoulli import BernoulliExperiment
from tsampling.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)
Performing an action:
You can randomly choos which arm to "pull" in the multi-armed bandit:
experiment.choose_arm()
Updating reward:
You can update the different arms information by adding reward information:
rewards = [{"label":"option1", "reward":1}, {"label":"option2", "reward":0}]
experiment.add_rewards(rewards)
Plotting Posterior Distribution:
You can plot the posterior distribution
experiment.plot_posterior()
Installation
Pip
pip install tsampling
License
Free software: MIT license
Credits
This package was created with Cookiecutter_ and the audreyr/cookiecutter-pypackage_ project template.
_Cookiecutter: https://github.com/audreyr/cookiecutter
audreyr/cookiecutter-pypackage: https://github.com/audreyr/cookiecutter-pypackage
Metadata
Release files for tsampling 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tsampling-0.0.1.tar.gz | 8.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tsampling-0.0.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 16.6 kB
Release files / tsampling-0.0.1.tar.gz
| Download URL | tsampling-0.0.1.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e77343d03b858760dd77503470d17614b8228fd6f8495e2ccdcd0508caeeb83e
|
|
BLAKE2b-256 checksum How to use checksums |
5061c1eb27aa96fa58a20589b081bc09b75b2b07b1a8da94d7f8d5c4e2d3c649
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Release files / tsampling-0.0.1-py2.py3-none-any.whl
| Download URL | tsampling-0.0.1-py2.py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d7c5ddbaaa4af7dad311f5cb2f4aa80fce5665c5fa5a4f3c457936c095a584b4
|
|
BLAKE2b-256 checksum How to use checksums |
bc9c815b55f46330763ea71f7922ef329e48d93b8b975377eafd69cc0a985a51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Security for tsampling 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.