Skip to main content

Markovian Bandits

This repository contains a python library to compute whittle indices or test indexability of finite-state Markovian bandit problems.

Installation

To install, just run:

pip install markovianbandit-pkg

Example

To test with a few randomly generated examples:

import markovianbandit as bandit
model = bandit.random_restless(dim=4, seed=42)
print(model.whittle_indices()) # should print array([ 0.87536099, -0.08765819, -0.15279431, -0.51905682])
print(model.get_P0P1R0R1())
model = bandit.random_restless(4, seed=2791)
print(model.is_indexable()) # should print False

model = bandit.random_rested(dim=4)
print(model.gittins_indices(discount=.8)) # computes gittins index

To compute the Whittle or Gittins index from P0 and P1:

P0 = [[.5, .5], [.25, .75]]
P1 = [[1, 0], [0.5, 0.5]]
R0 = [0.5, 0.5]
R1 = [2, 1]
model = bandit.restless_bandit_from_P0P1_R0R1(P0, P1, R0, R1)
print(model.whittle_indices())

model = bandit.rested_bandit_from_P1_R1(P1, R1)
print(model.gittins_indices(discount=0.5))

Note that the algorithm complexity to compute Whittle index is $O(n^3)$. It can compute indices of bandits in less than one seconds to bandits of up to $1000$ states (i.e. $1000\times 1000$ matrices). The loop below should take less than one second.

import time
for dim in [10, 100, 1000]:
    ts = time.time()
    model = bandit.random_restless(dim=dim, seed=42)
    model.whittle_indices()
    print("Model of size", dim, "computed in", time.time() - ts, "seconds")

Authors

Nicolas Gast and Kimang Khun.

History version

  • 0.4 (July 0, 2024):

    • fixed implementation in find_mu_min() (fix a bug triggered when some indices where equal)
  • 0.3 (July 10, 2023):

    • handle multichain case by testing when matrix inversion fails
    • correct treatment of possibly infinite indices
    • correction of a bug when dividing by 0.
    • addition of an absolute tolerance to be more robust
  • 0.2 (Nov 21, 2022)

    • simplification of how the discount is treated
    • function to avoid recomputation of indices
    • new indexability test
  • 0.1 (Jan 11, 2021)

    • Many small optimization (code about 50% faster)
  • 0.0.5 (Nov 19, 2021). First public release.

Reference

"Testing Indexability and Computing Whittle and Gittins Index in Subcubic Time" by Nicolas Gast, Kimang Khun and Bruno Gaujal. https://arxiv.org/abs/2203.05207

Metadata

Release files for markovianbandit-pkg 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 markovianbandit-pkg 0.4
File Size Uploaded Provenance Actions
markovianbandit_pkg-0.4.tar.gz 10.2 kB Without provenance Details for markovianbandit_pkg-0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for markovianbandit-pkg 0.4
File Interpreter ABI Platform Actions
markovianbandit_pkg-0.4-py3-none-any.whl Python 3 none any Details for markovianbandit_pkg-0.4-py3-none-any.whl

Total release size: 18.9 kB

Release files / markovianbandit_pkg-0.4.tar.gz

Download URL markovianbandit_pkg-0.4.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c56dc029c6878bc6ee150e80da70cafd935eed40575eb1099d2907930c729fbb
BLAKE2b-256 checksum
How to use checksums
c581b6b49ce9314704571a5d2e467ee99d99800e50204d1e98ede9ea8d7e7101
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Release files / markovianbandit_pkg-0.4-py3-none-any.whl

Download URL markovianbandit_pkg-0.4-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea0ce5a5dec8b376befa85977098964437c048ee37924bb72e5ac971341e646d
BLAKE2b-256 checksum
How to use checksums
a31092138421e325f8aaef69934dca33b2dff28adb08931af929cf78d7a4122c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.7

Security for markovianbandit-pkg 0.4

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.

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