Registry / ai-ml / mabwiser

mabwiser

JSON →
library2.7.4pypypi✓ verified 91d ago

MABWiser is a Python library for parallelizable, contextual multi-armed bandits. It supports a wide range of bandit learning policies (e.g., epsilon-greedy, Thompson Sampling, LinUCB) and neighborhood policies for contextual bandits. Version 2.7.4 is the latest release, with active development.

pip install mabwiser
INSTALL
IMPORT
SIG · MABWISER
M
mabwiser
ai-mlpythonv2.7.4
Install
18.0s avg
Import
4280ms
Disk
445MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.7.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
build_error
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 18.0s · import 4.280s · 427MB
445MB installed
● package 445MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MAB
✓ from mabwiser.mab import MAB
✗ from mabwiser import MAB
MAB is not exposed at the package level; it's in the mab submodule.
LearningPolicy
✓ from mabwiser.mab import LearningPolicy
Commonly used to specify learning policies like LearningPolicy.EpsilonGreedy.
NeighborhoodPolicy
✓ from mabwiser.mab import NeighborhoodPolicy
Used for contextual bandits with nearest neighbor policies.

Minimal example: non-contextual epsilon-greedy bandit with partial_fit, and contextual bandit with Cluster neighborhood.

import numpy as np from mabwiser.mab import MAB, LearningPolicy, NeighborhoodPolicy # Non-contextual bandit arms = ['arm1', 'arm2'] mab = MAB(arms, LearningPolicy.EpsilonGreedy(epsilon=0.1)) # Simulate fitting: use dummy rewards for _ in range(100): arm = mab.predict() reward = np.random.binomial(1, 0.7 if arm == 'arm1' else 0.3) mab.partial_fit(arm, reward) # Contextual bandit with nearest neighbor contexts = np.array([[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]]) mab_ctx = MAB(arms, LearningPolicy.EpsilonGreedy(epsilon=0.1), NeighborhoodPolicy.Cluster()) mab_ctx.fit(contexts, np.array(['arm1', 'arm2', 'arm1']), np.array([1, 0, 1])) print(mab_ctx.predict(contexts[-1:]))
Debug
Known issues
breakingIn version 2.4.0, the scaler argument changed from a pre-trained scaler dict to a boolean `scale` flag. Code using `arm_to_scaler` will break.
fix
Replace `arm_to_scaler` argument with `scale=True` and let MABWiser fit scalers internally.
affects: >=2.4.0
breakingnp.Inf removed in 2.7.4. Code referencing `np.Inf` will raise AttributeError.
fix
Replace `np.Inf` with `np.inf`.
affects: >=2.7.4
deprecatedDirect use of `LearningPolicy` strings (e.g., `LearningPolicy('epsilon_greedy')`) is deprecated in favor of the enum-like `LearningPolicy.EpsilonGreedy` objects.
fix
Use `LearningPolicy.EpsilonGreedy(epsilon=0.1)` instead of `LearningPolicy('epsilon_greedy')`.
affects: >=2.7.1
gotchaMAB.predict() for non-contextual policies expects an empty or None context array when using recent versions (>=2.4.0). Providing a non-empty context will raise an error.
fix
Call `mab.predict()` without arguments or pass an empty array like `np.array([[]])` for batch predictions.
affects: >=2.4.0
Errors
Common errors & fixes
AttributeError: module 'mabwiser' has no attribute 'MAB'
Importing MAB from the top-level package instead of the mab submodule.
fix
Use: from mabwiser.mab import MAB
TypeError: 'LearningPolicy' object is not callable
Using LearningPolicy as a function with a string argument instead of using the enum attribute directly.
fix
Use: LearningPolicy.EpsilonGreedy(epsilon=0.1)
ValueError: The truth value of an array with more than one element is ambiguous
Passing a full context matrix to predict() for a non-contextual bandit.
fix
For non-contextual, call predict() with no arguments or an empty array.
Upgrade
Version history
2.7.4latest on PyPI · released Aug 30, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources