Skip to content

Commit 61be769

Browse files
committed
Updated Readme and added dev dependencies and configs.
- Removed Seaborn requirement from example code in Readme - Added `dev-requirements.txt` for pip installation of dev tools - Added references to dev tool config files - Linted Readme
1 parent f300cba commit 61be769

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# slots
2-
### *A multi-armed bandit library for Python*
2+
3+
## *A multi-armed bandit library for Python*
34

45
Slots is intended to be a basic, very easy-to-use multi-armed bandit library for Python.
56

@@ -8,44 +9,48 @@ Slots is intended to be a basic, very easy-to-use multi-armed bandit library for
89
[![Downloads](https://pepy.tech/badge/slots)](https://pepy.tech/project/slots)
910

1011
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
11-
[![type hints with mypy](https://img.shields.io/badge/type%20hints-mypy-brightgreen)]()
12-
12+
[![type hints with mypy](https://img.shields.io/badge/type%20hints-mypy-brightgreen)](http://mypy-lang.org/)
1313

14+
### Author
1415

15-
#### Author
1616
[Roy Keyes](https://roycoding.github.io) -- roy.coding@gmail
1717

18-
#### License: MIT
19-
See [LICENSE.txt](https://github.com/roycoding/slots/blob/master/LICENSE.txt)
18+
### License: MIT
2019

20+
See [LICENSE.txt](https://github.com/roycoding/slots/blob/master/LICENSE.txt)
2121

2222
### Introduction
23+
2324
slots is a Python library designed to allow the user to explore and use simple multi-armed bandit (MAB) strategies. The basic concept behind the multi-armed bandit problem is that you are faced with *n* choices (e.g. slot machines, medicines, or UI/UX designs), each of which results in a "win" with some unknown probability. Multi-armed bandit strategies are designed to let you quickly determine which choice will yield the highest result over time, while reducing the number of tests (or arm pulls) needed to make this determination. Typically, MAB strategies attempt to strike a balance between "exploration", testing different arms in order to find the best, and "exploitation", using the best known choice. There are many variation of this problem, see [here](https://en.wikipedia.org/wiki/Multi-armed_bandit) for more background.
2425

2526
slots provides a hopefully simple API to allow you to explore, test, and use these strategies. Basic usage looks like this:
2627

2728
Using slots to determine the best of 3 variations on a live website.
29+
2830
```Python
2931
import slots
3032

3133
mab = slots.MAB(3, live=True)
3234
```
3335

3436
Make the first choice randomly, record responses, and input reward 2 was chosen. Run online trial (input most recent result) until test criteria is met.
37+
3538
```Python
3639
mab.online_trial(bandit=2,payout=1)
3740
```
3841

3942
The response of `mab.online_trial()` is a dict of the form:
43+
4044
```Python
4145
{'new_trial': boolean, 'choice': int, 'best': int}
4246
```
47+
4348
Where:
49+
4450
- If the criterion is met, `new_trial` = `False`.
4551
- `choice` is the current choice of arm to try.
4652
- `best` is the current best estimate of the highest payout arm.
4753

48-
4954
To test strategies on arms with pre-set probabilities:
5055

5156
```Python
@@ -55,6 +60,7 @@ b.run()
5560
```
5661

5762
To inspect the results and compare the estimated win probabilities versus the true win probabilities:
63+
5864
```Python
5965
# Current best guess
6066
b.best()
@@ -72,13 +78,13 @@ b.bandits.probs
7278
By default, slots uses the epsilon greedy strategy. Besides epsilon greedy, the softmax, upper confidence bound (UCB1), and Bayesian bandit strategies are also implemented.
7379

7480
#### Regret analysis
81+
7582
A common metric used to evaluate the relative success of a MAB strategy is "regret". This reflects that fraction of payouts (wins) that have been lost by using the sequence of pulls versus the currently best known arm. The current regret value can be calculated by calling the `mab.regret()` method.
7683

7784
For example, the regret curves for several different MAB strategies can be generated as follows:
78-
```Python
7985

86+
```Python
8087
import matplotlib.pyplot as plt
81-
import seaborn as sns
8288
import slots
8389

8490
# Test multiple strategies for the same bandit probabilities
@@ -104,8 +110,7 @@ for t in range(10000):
104110
s['regret'].append(s['mab'].regret())
105111

106112
# Pretty plotting
107-
sns.set_style('whitegrid')
108-
sns.set_context('poster')
113+
plt.style.use(['seaborn-poster','seaborn-whitegrid'])
109114

110115
plt.figure(figsize=(15,4))
111116

@@ -118,13 +123,15 @@ plt.ylabel('Regret')
118123
plt.title('Multi-armed bandit strategy performance (slots)')
119124
plt.ylim(0,0.2);
120125
```
121-
![](./misc/regret_plot.png)
126+
127+
![Regret plot](./misc/regret_plot.png)
122128

123129
### API documentation
124-
For documentation on the slots API, see [slots-docs.md](https://github.com/roycoding/slots/blob/master/docs/slots-docs.md).
125130

131+
For documentation on the slots API, see [slots-docs.md](https://github.com/roycoding/slots/blob/master/docs/slots-docs.md).
126132

127133
### Todo list:
134+
128135
- More MAB strategies
129136
- Argument to save regret values after each trial in an array.
130137
- TESTS!
@@ -138,3 +145,7 @@ The current development environment uses:
138145
- pytest >= 5.3 (5.3.2)
139146
- black >= 19.1 (19.10b0)
140147
- mypy = 0.761
148+
149+
You can pip install these easily by including `dev-requirements.txt`.
150+
151+
For mypy config, see `mypy.ini`. For black config, see `pyproject.toml`.

dev-requirement.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mypy>=0.761
2+
black>=19.10b0
3+
pytest>=5.3.2

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.black]
2+
line-length = 79

0 commit comments

Comments
 (0)