PyBandits
PyBandits is a Python library for Multi-Armed Bandit. It provides an implementation of stochastic Multi-Armed Bandit (sMAB) and contextual Multi-Armed Bandit (cMAB) based on Thompson Sampling.
For the sMAB, we implemented a Bernoulli multi-armed bandit based on Thompson Sampling algorithm Agrawal and Goyal, 2012. If context information is available we provide a generalisation of Thompson Sampling for cMAB Agrawal and Goyal, 2014 implemented with PyMC, an open source probabilistic programming framework for automatic Bayesian inference on user-defined probabilistic models.
Installation
This library is distributed on PyPI and can be installed with pip.
pip install pybandits
Based on the guidelines of pymc authors, it is highly recommended to install the library in a conda environment via the following.
conda install -c conda-forge pymc
pip install pybandits
The command above will automatically install all the dependencies listed in pyproject.toml. Please visit the
installation
page for more details.
Getting started
A short example, illustrating it use. Use the sMAB model to predict actions and update the model based on rewards from the environment.
import numpy as np
from pybandits.model import Beta
from pybandits.smab import SmabBernoulli
n_samples=100
# define action model
actions = {
"a1": Beta(),
"a2": Beta(),
}
# init stochastic Multi-Armed Bandit model
smab = SmabBernoulli(actions=actions)
# predict actions
pred_actions, _ = smab.predict(n_samples=n_samples)
simulated_rewards = np.random.randint(2, size=n_samples)
# update model
smab.update(actions=pred_actions, rewards=simulated_rewards)
Documentation
For more information please read the full documentation and tutorials.
You can also observe on DeepWiki.
Info for developers
The source code of the project is available on GitHub.
git clone https://github.com/playtikaoss/pybandits.git
You can install the library and the dependencies from the source code with one of the following commands:
poetry install # install library + dependencies
poetry install --without dev # install library + dependencies, excluding developer-dependencies
To create the HTML documentation run the following commands:
cd docs/src
make html
Run tests
Tests can be executed with pytest running the following commands. Make sure to have the library installed before to
run any tests.
cd tests
pytest -vv # run all tests
pytest -vv test_testmodule.py # run all tests within a module
pytest -vv test_testmodule.py -k test_testname # run only 1 test
pytest -vv -k 'not time' # run all tests but not exec time
License
Metadata
Release files for pybandits 8.4.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 | Actions |
|---|---|---|---|---|
| pybandits-8.4.1.tar.gz | 170.5 kB | Without provenance | Details for pybandits-8.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pybandits-8.4.1-py3-none-any.whl | Python 3 | none | any | Details for pybandits-8.4.1-py3-none-any.whl |
Total release size: 384.9 kB
Release files / pybandits-8.4.1.tar.gz
| Download URL | pybandits-8.4.1.tar.gz |
|---|---|
| Size | 170.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e73857a4db2f60c79fc482c272a846114501eb5ccef9cb32eb214f926ab4093
|
|
BLAKE2b-256 checksum How to use checksums |
c9666afbb8ca535fe9ea9602b5bdbdcfcf02b3e0eff5144cf73245a20d80044a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.10.22 Linux/6.17.0-1022-azure
|
Release files / pybandits-8.4.1-py3-none-any.whl
| Download URL | pybandits-8.4.1-py3-none-any.whl |
|---|---|
| Size | 214.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cbd4f4ab3011af14edc00b47224d8afa15f78b54eaf8764cf002aba639bd1688
|
|
BLAKE2b-256 checksum How to use checksums |
589a6dc5ece161f912c5600bed43207e8d58a9d52d5e85821a814db455fe4144
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.10.22 Linux/6.17.0-1022-azure
|
Security for pybandits 8.4.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.