How to run the code ?

This short page explains quickly how to install the requirements for this project, and then how to use the code to run simulations.

Required modules

Virtualenv

First, install the requirements, globally (or with a virtualenv, see below):

pip install -r requirements.txt
Some requirements are only needed for one policy (mostly the experimental ones), and for the documentation.

Nix

A pinned Nix environment is available:

nix-shell

Running some simulations

Then, it should be very straight forward to run some experiment. This will run the simulation, average them (by repetitions) and plot the results.

Single player

Single player

python main.py
# or
make main

Single player, aggregating algorithms

python main.py configuration_comparing_aggregation_algorithms
# or
make comparing_aggregation_algorithms
See these explainations: Aggregation.md

Single player, doubling-trick algorithms

python main.py configuration_comparing_doubling_algorithms
# or
make comparing_doubling_algorithms
See these explainations: DoublingTrick.md

Single player, with Sparse Stochastic Bandit

python main.py configuration_sparse
# or
make sparse
See these explainations: SparseBandits.md

Single player, with Markovian problem

python main.py configuration_markovian
# or
make markovian

Single player, with non-stationary problem

python main.py configuration_nonstationary
# or
make nonstationary
See these explainations: NonStationaryBandits.md

Multi-Player

Multi-Player, one algorithm

python main_multiplayers.py
# or
make multi

Multi-Player, comparing different algorithms

python main_multiplayers_more.py
# or
make moremulti
See these explainations: MultiPlayers.md

Using env variables ?

For all simulations, I recently added the support for environment variable, to ease the customization of the main parameters of every simulations.

For instance, if the configuration_multiplayers_more.py file is correct, then you can customize to use N=4 repetitions, for horizon T=1000 and M=3 players, parallelized with N_JOBS=4 jobs (use the number of cores of your CPU for optimal performance):

N=4 T=1000 M=3 DEBUG=True SAVEALL=False N_JOBS=4 make moremulti

In a virtualenv ?

If you prefer to not install the requirements globally on your system-wide Python setup, you can (and should) use virtualenv.

$ virtualenv .
Using base prefix '/usr'
New python executable in /your/path/to/SMPyBandits/bin/python3
Also creating executable in /your/path/to/SMPyBandits/bin/python
Installing setuptools, pip, wheel...done.
$ source bin/activate  # in bash, use activate.csh or activate.fish if needed
$ type pip  # just to check
pip is /your/path/to/SMPyBandits/bin/pip
$ pip install -r requirements.txt
Collecting numpy (from -r requirements.txt (line 5))
...
Installing collected packages: numpy, scipy, cycler, pytz, python-dateutil, matplotlib, joblib, pandas, seaborn, tqdm, sphinx-rtd-theme, commonmark, docutils, recommonmark
Successfully installed commonmark-0.5.4 cycler-0.10.0 docutils-0.13.1 joblib-0.11 matplotlib-2.0.0 numpy-1.12.1 pandas-0.19.2 python-dateutil-2.6.0 pytz-2016.10 recommonmark-0.4.0 scipy-0.19.0 seaborn-0.7.1 sphinx-rtd-theme-0.2.4 tqdm-4.11.2

And then be sure to use the virtualenv binary for Python, bin/python, instead of the system-wide one, to launch the experiments (the Makefile should use it by default, if source bin/activate was executed).


Or with a Makefile ?

You can also use the provided Makefile file to do this simply:

make install       # install the requirements
make multiplayers  # run and log the main.py script

It can be used to check the quality of the code with pylint:

make lint lint3  # check the code with pylint

It is also used to clean the code, build the doc, send the doc, etc. (This should not be used by others)


Or within a Jupyter notebook ?

I am writing some Jupyter notebooks, in this folder (notebooks/), so if you want to do the same for your small experiments, you can be inspired by the few notebooks already written.