A simple Epsilon-Greedy multi-armed bandit implementation
Project description
Epsilon-Greedy Multi-Armed Bandit
A simple Python implementation of the Epsilon-Greedy algorithm for the multi-armed bandit problem. This package provides classes for creating bandit environments and an agent that learns to select the best action. It also includes a command-line interface for running simulations.
Features
- EpsilonGreedyAgent: A configurable agent with parameters for exploration rate (
epsilon), epsilon decay, and optimistic initial values. - MultiArmedBandit Environment: Supports arms with different reward distributions:
- Bernoulli: For modeling binary outcomes (e.g., click/no-click).
- Normal (Gaussian): For modeling continuous outcomes.
- Simulation Runner: A function to run experiments and collect results like average reward and optimal action rate.
- Command-Line Interface: A convenient CLI for running simulations without writing Python code.
Project Structure
.
├── EpsilonGreedy/
│ ├── __init__.py
│ └── main.py
└── README.md
EpsilonGreedy/main.py: Contains all the core logic for theArm,MultiArmedBandit, andEpsilonGreedyAgentclasses, as well as the CLI entry point.EpsilonGreedy/__init__.py: Makes the directory a Python package and exposes the main classes for easy import.
Usage
You can use this project either as a Python library or as a command-line tool.
As a Library
Import the necessary classes from the EpsilonGreedy package to build and run your own bandit simulations.
from EpsilonGreedy import Arm, MultiArmedBandit, EpsilonGreedyAgent, run_bandit
# 1. Define the arms for the bandit problem
arms = [
Arm(name="arm_1", distribution="bernoulli", p=0.1),
Arm(name="arm_2", distribution="bernoulli", p=0.5),
Arm(name="arm_3", distribution="bernoulli", p=0.9),
]
# 2. Create the bandit environment
bandit_env = MultiArmedBandit(arms=arms, seed=42)
# 3. Create the Epsilon-Greedy agent
agent = EpsilonGreedyAgent(
n_actions=bandit_env.k,
epsilon=0.1,
seed=123
)
# 4. Run the simulation
results = run_bandit(env=bandit_env, agent=agent, steps=1000)
# 5. Print the results
print(f"Average reward: {results['avg_reward']:.4f}")
print(f"Optimal action selection rate: {results['optimal_action_rate']:.4f}")
print(f"Final Q-value estimates: {results['final_estimates']}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file epsilongreedy-0.1.0.tar.gz.
File metadata
- Download URL: epsilongreedy-0.1.0.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9a296edd184e00b356d13e212c35b42b7c3fbb04b88129a8246766fa66c89cc
|
|
| MD5 |
c35d2aa7109963dd077c7547cc2f0fb9
|
|
| BLAKE2b-256 |
071f0a95550c36335acaba8560228052981219f17c5514ebb9d5b6d996fc589e
|
File details
Details for the file epsilongreedy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: epsilongreedy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5df04e3899f586c5b1304d23ee5b2067783f6f169933e6a49dcc832fd960d5b
|
|
| MD5 |
0289fcfad2b52ccf85218122a3c8e3ca
|
|
| BLAKE2b-256 |
bbe1b6f29a4b900983460b59e61207fbf9187f47979db4724dc8493c56c4fa55
|