{ "cells": [ { "cell_type": "markdown", "metadata": { "toc": "true" }, "source": [ "# Table of Contents\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "# Visualizing detection of change points for nonstationary problems\n", "First, be sure to be in the main folder, or to have installed [`SMPyBandits`](https://github.com/SMPyBandits/SMPyBandits), and import `MAB` from `Environment` package:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "!pip install SMPyBandits watermark" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "import sys\n", "sys.path.append(\"..\")" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The watermark extension is already loaded. To reload it, use:\n", " %reload_ext watermark\n", "Lilian Besson \n", "\n", "CPython 3.6.7\n", "IPython 7.4.0\n", "\n", "compiler : GCC 8.2.0\n", "system : Linux\n", "release : 4.15.0-48-generic\n", "machine : x86_64\n", "processor : x86_64\n", "CPU cores : 4\n", "interpreter: 64bit\n" ] } ], "source": [ "%load_ext watermark\n", "%watermark -v -m -a \"Lilian Besson\"" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "from SMPyBandits.Environment.MAB import PieceWiseStationaryMAB, MAB" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "%matplotlib notebook\n", "import matplotlib as mpl\n", "mpl.rcParams['figure.dpi'] = 120\n", "mpl.rcParams['figure.figsize'] = (10, 5.6)\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "import seaborn as sns" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "sns.set(context=\"talk\", style=\"whitegrid\", palette=\"hls\", font=\"sans-serif\", font_scale=0.9)" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "from SMPyBandits.Environment.plotsettings import nrows_ncols" ] }, { "cell_type": "code", "execution_count": 65, "metadata": {}, "outputs": [], "source": [ "def palette(nb):\n", " return sns.hls_palette(nb + 1)[:nb]\n", "\n", "def makemarkers(nb):\n", " allmarkers = ['o', 'D', '^', '<', 'v', 'p', 's', '*', 'h', '>']\n", " longlist = allmarkers * (1 + int(nb / float(len(allmarkers)))) # Cycle the good number of time\n", " return longlist[:nb] # Truncate" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating the MAB problems" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [], "source": [ "from SMPyBandits.configuration_nonstationary import *" ] }, { "cell_type": "code", "execution_count": 67, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'arm_type': SMPyBandits.Arms.Bernoulli.Bernoulli,\n", " 'params': {'listOfMeans': [[0.3, 0.5, 0.9],\n", " [0.3, 0.2, 0.9],\n", " [0.3, 0.2, 0.1],\n", " [0.7, 0.2, 0.1],\n", " [0.7, 0.5, 0.1]],\n", " 'changePoints': [0, 1000, 2000, 3000, 4000]}},\n", " {'arm_type': SMPyBandits.Arms.Bernoulli.Bernoulli,\n", " 'params': {'listOfMeans': [[0.4, 0.5, 0.9],\n", " [0.5, 0.4, 0.7],\n", " [0.6, 0.3, 0.5],\n", " [0.7, 0.2, 0.3],\n", " [0.8, 0.1, 0.1]],\n", " 'changePoints': [0, 1000, 2000, 3000, 4000]}}]" ] }, "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ "envs = configuration['environment']\n", "envs" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "env1 = envs[0]\n", "env2 = envs[1]" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Special MAB problem, with arm (possibly) changing at every time step, read from a dictionnary 'configuration' = {'arm_type':