PyMAB documentation
PyMAB provides reliable, reproducible multi-armed bandit experiments for Python 3.11+. Version 2 uses stable named random streams, validated immutable results, paired replicate-level inference, and support-aware environments.
Learn interactively: Launch PyMAB Arcade to explore all 27 concrete policies through guided, reproducible missions.
Quick start
import numpy as np
from pymab.environments import BanditEnvironment
from pymab.policies import EpsilonGreedyPolicy, UCBPolicy
from pymab.simulation import Experiment, ExperimentConfig
environment = BanditEnvironment(means=np.array([0.1, 0.4, 0.8]))
result = Experiment(
environment=environment,
policies={
"epsilon-greedy": EpsilonGreedyPolicy(n_arms=3, epsilon=0.1),
"ucb": UCBPolicy(n_arms=3),
},
config=ExperimentConfig(horizon=20, n_replicates=3, seed=42),
).run()
assert result.average_reward_by_step.shape == (20, 2)
assert result.cumulative_regret.shape == (20, 2)
Contents:
- Simulation
- Reliability contracts
- Shared types
- Statistical inference
- Benchmarking and inference
- PyMAB Arcade
- Decision Guide
- Real-World Examples
- Policy assumptions
- Environments
- Policies
- Offline evaluation
- Reward models and arm priors
- Migrating from v1 to v2
- Migrating to the Rust backend
- Native backend performance