API Reference#

Agent API#

The Agent API is the most ergonomic way to use this library in production. It is designed to maximize your IDE’s ability to autocomplete and type-check your code. Additionally, it is designed to make it easy to modify the arms and the policies of your bandit as your needs change.

bayesianbandits.Agent(arms, policy[, ...])

Agent for a non-contextual (classic) multi-armed bandit problem.

bayesianbandits.ContextualAgent(arms, policy)

Agent for a contextual multi-armed bandit problem.

bayesianbandits.LipschitzContextualAgent(...)

Contextual agent with a shared learner and a configurable design matrix.

bayesianbandits.Arm(action_token[, ...])

Single arm of a multi-armed bandit.

Policy Functions#

bayesianbandits.EpsilonGreedy([epsilon, samples])

Policy object for \(\varepsilon\)-greedy selection.

bayesianbandits.ThompsonSampling()

Policy object for Thompson sampling.

bayesianbandits.UpperConfidenceBound([...])

Policy object for Bayesian upper confidence bound.

bayesianbandits.EXP3A([gamma, eta, ...])

EXP3.A: Average-based anytime variant of EXP3 for adversarial bandits.

Pipelines#

Pipelines enable the use of sklearn transformers with Bayesian bandits, providing preprocessing capabilities at different levels.

bayesianbandits.AgentPipeline()

Create a Pipeline that wraps an Agent or ContextualAgent.

bayesianbandits.LearnerPipeline(steps, learner)

Pipeline that implements the Learner protocol with generic input type.

Arm Featurizers#

Arm featurizers enable shared model bandits by transforming context features based on action tokens. They support vectorized operations for efficient multi-arm processing.

bayesianbandits.ArmFeaturizer()

Abstract base class for vectorized arm feature transformation.

bayesianbandits.ArmColumnFeaturizer([...])

Appends arm tokens as a column to context features.

bayesianbandits.FunctionArmFeaturizer(func)

Create ArmFeaturizer from a user-provided function.

Estimators#

These estimators are the underlying models for the arms in a bandit. They should be passed to the learner argument of the bandit decorator. Each of these Bayesian estimators can be converted to a recursive estimator by passing a learning_rate argument to the constructor that is less than 1. Each of them implement a decay method that uses the learning_rate to increase the variance of the prior. This is a type of state-space model that is useful for restless bandits.

bayesianbandits.BayesianGLM([alpha, link, ...])

Bayesian Generalized Linear Model with Laplace approximation.

bayesianbandits.DirichletClassifier(alphas, *)

Intercept-only Dirichlet-Multinomial classifier.

bayesianbandits.GammaRegressor(alpha, beta, *)

Intercept-only Gamma-Poisson conjugate regression model.

bayesianbandits.NormalRegressor(alpha, beta, *)

Bayesian linear regression with known noise variance.

bayesianbandits.NormalInverseGammaRegressor(*)

Bayesian linear regression with unknown noise variance.

Empirical Bayes Estimators#

These estimators automatically tune their hyperparameters via evidence maximization (MacKay’s update rules). They are drop-in replacements for their base estimators and are especially useful when hyperparameters are unknown or when the environment may be non-stationary (pair with learning_rate < 1 for decay as a defensive default).

bayesianbandits.EmpiricalBayesDirichletClassifier(...)

Dirichlet-Multinomial classifier with empirical Bayes prior tuning.

bayesianbandits.EmpiricalBayesGammaRegressor(...)

Gamma-Poisson regressor with empirical Bayes prior tuning.

bayesianbandits.EmpiricalBayesNormalRegressor([...])

Bayesian linear regression with empirical Bayes hyperparameter tuning.

Utilities#

bayesianbandits.LaplaceApproximator([...])

Laplace approximation via iteratively reweighted least squares (IRLS).