-
Notifications
You must be signed in to change notification settings - Fork 0
/
API.html
465 lines (336 loc) · 40.6 KB
/
API.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-38514290-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Short documentation of the API — SMPyBandits 0.9.6 documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="About parallel computations" href="About_parallel_computations.html" />
<link rel="prev" title="Non-Stationary Stochastic Multi-Armed Bandits" href="NonStationaryBandits.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> SMPyBandits
<img src="_static/logo.png" class="logo" alt="Logo"/>
</a>
<div class="version">
0.9
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="README.html"><em>SMPyBandits</em></a></li>
<li class="toctree-l1"><a class="reference internal" href="docs/modules.html">SMPyBandits modules</a></li>
<li class="toctree-l1"><a class="reference internal" href="How_to_run_the_code.html">How to run the code ?</a></li>
<li class="toctree-l1"><a class="reference internal" href="PublicationsWithSMPyBandits.html">List of research publications using Lilian Besson’s SMPyBandits project</a></li>
<li class="toctree-l1"><a class="reference internal" href="Aggregation.html"><strong>Policy aggregation algorithms</strong></a></li>
<li class="toctree-l1"><a class="reference internal" href="MultiPlayers.html"><strong>Multi-players simulation environment</strong></a></li>
<li class="toctree-l1"><a class="reference internal" href="DoublingTrick.html"><strong>Doubling Trick for Multi-Armed Bandits</strong></a></li>
<li class="toctree-l1"><a class="reference internal" href="SparseBandits.html"><strong>Structure and Sparsity of Stochastic Multi-Armed Bandits</strong></a></li>
<li class="toctree-l1"><a class="reference internal" href="NonStationaryBandits.html"><strong>Non-Stationary Stochastic Multi-Armed Bandits</strong></a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Short documentation of the API</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#code-organization">Code organization</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#layout-of-the-code">Layout of the code:</a></li>
<li class="toctree-l3"><a class="reference internal" href="#uml-diagrams">UML diagrams</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#question-how-to-change-the-simulations">Question: <em>How to change the simulations</em>?</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#to-customize-the-plots">To customize the plots</a></li>
<li class="toctree-l3"><a class="reference internal" href="#to-change-the-configuration-of-the-simulations">To change the configuration of the simulations</a></li>
<li class="toctree-l3"><a class="reference internal" href="#to-change-how-to-results-are-exploited">To change how to results are exploited</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#question-how-to-add-something-to-this-project">Question: <em>How to add something to this project?</em></a><ul>
<li class="toctree-l3"><a class="reference internal" href="#for-a-new-arm">For a <strong>new arm</strong></a></li>
<li class="toctree-l3"><a class="reference internal" href="#for-a-new-single-user-policy">For a <strong>new (single-user) policy</strong></a></li>
<li class="toctree-l3"><a class="reference internal" href="#for-a-new-multi-users-policy">For a <strong>new multi-users policy</strong></a></li>
<li class="toctree-l3"><a class="reference internal" href="#scroll-license-github-license">📜 License ? </a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="About_parallel_computations.html">About parallel computations</a></li>
<li class="toctree-l1"><a class="reference internal" href="TODO.html">💥 TODO</a></li>
<li class="toctree-l1"><a class="reference internal" href="plots/README.html">Some illustrations for this project</a></li>
<li class="toctree-l1"><a class="reference internal" href="notebooks/README.html">Jupyter Notebooks 📓 by Naereen @ GitHub</a></li>
<li class="toctree-l1"><a class="reference internal" href="notebooks/list.html">List of notebooks for SMPyBandits</a></li>
<li class="toctree-l1"><a class="reference internal" href="Profiling.html">A note on execution times, speed and profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="uml_diagrams/README.html">UML diagrams</a></li>
<li class="toctree-l1"><a class="reference internal" href="logs/README.html"><code class="docutils literal notranslate"><span class="pre">logs</span></code> files</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">SMPyBandits</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Short documentation of the API</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/API.md.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<style>
/* CSS overrides for sphinx_rtd_theme */
/* 24px margin */
.nbinput.nblast,
.nboutput.nblast {
margin-bottom: 19px; /* padding has already 5px */
}
/* ... except between code cells! */
.nblast + .nbinput {
margin-top: -19px;
}
.admonition > p:before {
margin-right: 4px; /* make room for the exclamation icon */
}
/* Fix math alignment, see https://github.com/rtfd/sphinx_rtd_theme/pull/686 */
.math {
text-align: unset;
}
</style>
<div class="section" id="short-documentation-of-the-api">
<h1>Short documentation of the API<a class="headerlink" href="#short-documentation-of-the-api" title="Permalink to this headline">¶</a></h1>
<blockquote>
<div><p>This short document aim at documenting the API used in <a class="reference external" href="https://github.com/SMPyBandits/SMPyBandits/">my SMPyBandits environment</a>, and closing <a class="reference external" href="https://github.com/SMPyBandits/SMPyBandits/issues/3">this issue #3</a>.</p>
</div></blockquote>
<hr class="docutils" />
<div class="section" id="code-organization">
<h2>Code organization<a class="headerlink" href="#code-organization" title="Permalink to this headline">¶</a></h2>
<div class="section" id="layout-of-the-code">
<h3>Layout of the code:<a class="headerlink" href="#layout-of-the-code" title="Permalink to this headline">¶</a></h3>
<ul class="simple">
<li><p>Arms are defined in <a class="reference external" href="Arms/">this folder (<code class="docutils literal notranslate"><span class="pre">Arms/</span></code>)</a>, see for example <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Bernoulli.html"><code class="docutils literal notranslate"><span class="pre">Arms.Bernoulli</span></code></a></p></li>
<li><p>MAB algorithms (also called policies) are defined in <a class="reference external" href="Policies/">this folder (<code class="docutils literal notranslate"><span class="pre">Policies/</span></code>)</a>, see for example <a class="reference external" href="https://smpybandits.github.io/docs/Policies.Dummy.html"><code class="docutils literal notranslate"><span class="pre">Policies.Dummy</span></code></a> for a fully random policy, <a class="reference external" href="https://smpybandits.github.io/docs/Policies.EpsilonGreedy.html"><code class="docutils literal notranslate"><span class="pre">Policies.EpsilonGreedy</span></code></a> for the epsilon-greedy random policy, <a class="reference external" href="https://smpybandits.github.io/docs/Policies.UCB.html"><code class="docutils literal notranslate"><span class="pre">Policies.UCB</span></code></a> for the “simple” UCB algorithm, or also <a class="reference external" href="https://smpybandits.github.io/docs/Policies.BayesUCB.html"><code class="docutils literal notranslate"><span class="pre">Policies.BayesUCB</span></code></a>, <a class="reference external" href="https://smpybandits.github.io/docs/Policies.klUCB.html"><code class="docutils literal notranslate"><span class="pre">Policies.klUCB</span></code></a> for two UCB-like algorithms, <a class="reference external" href="https://smpybandits.github.io/docs/Policies.AdBandits.html"><code class="docutils literal notranslate"><span class="pre">Policies.AdBandits</span></code></a> for the <a class="reference external" href="https://github.com/flaviotruzzi/AdBandits/">AdBandits</a> algorithm, and <a class="reference external" href="https://smpybandits.github.io/docs/Policies.Aggregator.html"><code class="docutils literal notranslate"><span class="pre">Policies.Aggregator</span></code></a> for my <em>aggregated bandits</em> algorithms.</p></li>
<li><p>Environments to encapsulate date are defined in <a class="reference external" href="Environment/">this folder (<code class="docutils literal notranslate"><span class="pre">Environment/</span></code>)</a>: MAB problem use the class <a class="reference external" href="https://smpybandits.github.io/docs/Environment.MAB.html"><code class="docutils literal notranslate"><span class="pre">Environment.MAB</span></code></a>, simulation results are stored in a <a class="reference external" href="https://smpybandits.github.io/docs/Environment.Result.html"><code class="docutils literal notranslate"><span class="pre">Environment.Result</span></code></a>, and the class to evaluate multi-policy single-player multi-env is <a class="reference external" href="https://smpybandits.github.io/docs/Environment.Evaluator.html"><code class="docutils literal notranslate"><span class="pre">Environment.Evaluator</span></code></a>.</p></li>
<li><p><a class="reference external" href="https://smpybandits.github.io/docs/configuration.html">very_simple_configuration.py`</a> imports all the classes, and define the simulation parameters as a dictionary (JSON-like).</p></li>
<li><p><a class="reference external" href="https://smpybandits.github.io/docs/main.html"><code class="docutils literal notranslate"><span class="pre">main.py</span></code></a> runs the simulations, then display the final ranking of the different policies and plots the results (saved to <a class="reference external" href="plots/">this folder (<code class="docutils literal notranslate"><span class="pre">plots/</span></code>)</a>).</p></li>
</ul>
</div>
<hr class="docutils" />
<div class="section" id="uml-diagrams">
<h3>UML diagrams<a class="headerlink" href="#uml-diagrams" title="Permalink to this headline">¶</a></h3>
<blockquote>
<div><p>For more details, see <a class="reference external" href="uml_diagrams/">these UML diagrams</a>.</p>
</div></blockquote>
</div>
</div>
<hr class="docutils" />
<div class="section" id="question-how-to-change-the-simulations">
<h2>Question: <em>How to change the simulations</em>?<a class="headerlink" href="#question-how-to-change-the-simulations" title="Permalink to this headline">¶</a></h2>
<div class="section" id="to-customize-the-plots">
<h3>To customize the plots<a class="headerlink" href="#to-customize-the-plots" title="Permalink to this headline">¶</a></h3>
<ol class="simple">
<li><p>Change the default settings defined in <a class="reference external" href="https://smpybandits.github.io/docs/Environment.plotsettings.html"><code class="docutils literal notranslate"><span class="pre">Environment/plotsettings.py</span></code></a>.</p></li>
</ol>
</div>
<div class="section" id="to-change-the-configuration-of-the-simulations">
<h3>To change the configuration of the simulations<a class="headerlink" href="#to-change-the-configuration-of-the-simulations" title="Permalink to this headline">¶</a></h3>
<ol class="simple">
<li><p>Change the config file, i.e., <a class="reference external" href="https://smpybandits.github.io/docs/configuration.html"><code class="docutils literal notranslate"><span class="pre">configuration.py</span></code></a> for single-player simulations, or <a class="reference external" href="https://smpybandits.github.io/docs/configuration_multiplayers.html"><code class="docutils literal notranslate"><span class="pre">configuration_multiplayers.py</span></code></a> for multi-players simulations.</p></li>
<li><p>A good example of a very simple configuration file is given in <a class="reference external" href="https://smpybandits.github.io/docs/very_simple_configuration.html">very_simple_configuration.py`</a></p></li>
</ol>
</div>
<div class="section" id="to-change-how-to-results-are-exploited">
<h3>To change how to results are exploited<a class="headerlink" href="#to-change-how-to-results-are-exploited" title="Permalink to this headline">¶</a></h3>
<ol class="simple">
<li><p>Change the main script, i.e., <a class="reference external" href="https://smpybandits.github.io/docs/main.html"><code class="docutils literal notranslate"><span class="pre">main.py</span></code></a> for single-player simulations, <a class="reference external" href="https://smpybandits.github.io/docs/main_multiplayers.html"><code class="docutils literal notranslate"><span class="pre">main_multiplayers.py</span></code></a> for multi-players simulations. Some plots can be disabled or enabled by commenting a few lines, and some options are given as flags (constants in the beginning of the file).</p></li>
<li><p>If needed, change, improve or add some methods to the simulation environment class, i.e., <a class="reference external" href="https://smpybandits.github.io/docs/Environment.Evaluator.html"><code class="docutils literal notranslate"><span class="pre">Environment.Evaluator</span></code></a> for single-player simulations, and <a class="reference external" href="https://smpybandits.github.io/docs/Environment.EvaluatorMultiPlayers.html"><code class="docutils literal notranslate"><span class="pre">Environment.EvaluatorMultiPlayers</span></code></a> for multi-players simulations. They use a class to store their simulation result, <a class="reference external" href="https://smpybandits.github.io/docs/Environment.Result.html"><code class="docutils literal notranslate"><span class="pre">Environment.Result</span></code></a> and <a class="reference external" href="https://smpybandits.github.io/docs/Environment.ResultMultiPlayers.html"><code class="docutils literal notranslate"><span class="pre">Environment.ResultMultiPlayers</span></code></a>.</p></li>
</ol>
</div>
</div>
<hr class="docutils" />
<div class="section" id="question-how-to-add-something-to-this-project">
<h2>Question: <em>How to add something to this project?</em><a class="headerlink" href="#question-how-to-add-something-to-this-project" title="Permalink to this headline">¶</a></h2>
<blockquote>
<div><p>In other words, <em>what’s the API of this project</em>?</p>
</div></blockquote>
<div class="section" id="for-a-new-arm">
<h3>For a <strong>new arm</strong><a class="headerlink" href="#for-a-new-arm" title="Permalink to this headline">¶</a></h3>
<ol class="simple">
<li><p>Make a new file, e.g., <code class="docutils literal notranslate"><span class="pre">MyArm.py</span></code></p></li>
<li><p>Save it in <a class="reference external" href="Arms/"><code class="docutils literal notranslate"><span class="pre">Arms/</span></code></a></p></li>
<li><p>The file should contain a class of the same name, inheriting from <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Arm.html"><code class="docutils literal notranslate"><span class="pre">Arms/Arm</span></code></a>, e.g., like this <code class="docutils literal notranslate"><span class="pre">class</span> <span class="pre">MyArm(Arm):</span> <span class="pre">...</span></code> (no need for any <a class="reference external" href="https://stackoverflow.com/questions/576169/ddg#576183"><code class="docutils literal notranslate"><span class="pre">super</span></code></a> call)</p></li>
<li><p>This class <code class="docutils literal notranslate"><span class="pre">MyArm</span></code> has to <strong>have at least</strong> an <code class="docutils literal notranslate"><span class="pre">__init__(...)</span></code> method to create the arm object (with or without arguments - named or not); a <code class="docutils literal notranslate"><span class="pre">__str__</span></code> method to print it as a string; a <code class="docutils literal notranslate"><span class="pre">draw(t)</span></code> method to draw a reward from this arm (<code class="docutils literal notranslate"><span class="pre">t</span></code> is the time, which can be used or not); and <strong>should have</strong> a <code class="docutils literal notranslate"><span class="pre">mean()</span></code> method that gives/computes the mean of the arm</p></li>
<li><p>Finally, add it to the <a class="reference external" href="https://smpybandits.github.io/docs/Arms.__init__.html"><code class="docutils literal notranslate"><span class="pre">Arms/__init__.py</span></code></a> file: <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">.MyArm</span> <span class="pre">import</span> <span class="pre">MyArm</span></code></p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>For examples, see <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Bernoulli.html"><code class="docutils literal notranslate"><span class="pre">Arms.Bernoulli</span></code></a>, <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Gaussian.html"><code class="docutils literal notranslate"><span class="pre">Arms.Gaussian</span></code></a>, <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Exponential.html"><code class="docutils literal notranslate"><span class="pre">Arms.Exponential</span></code></a>, <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Poisson.html"><code class="docutils literal notranslate"><span class="pre">Arms.Poisson</span></code></a>.</p></li>
</ul>
</div></blockquote>
<blockquote>
<div><ul class="simple">
<li><p>For example, use this template:</p></li>
</ul>
</div></blockquote>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">.Arm</span> <span class="kn">import</span> <span class="n">Arm</span>
<span class="k">class</span> <span class="nc">MyArm</span><span class="p">(</span><span class="n">Arm</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="c1"># TODO Finish this method that initialize the arm MyArm</span>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">"MyArm(...)"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">'...'</span><span class="p">)</span> <span class="c1"># TODO</span>
<span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="c1"># TODO Simulates a pull of this arm. t might be used, but not necessarily</span>
<span class="k">def</span> <span class="nf">mean</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c1"># TODO Returns the mean of this arm</span>
</pre></div>
</div>
</div>
<hr class="docutils" />
<div class="section" id="for-a-new-single-user-policy">
<h3>For a <strong>new (single-user) policy</strong><a class="headerlink" href="#for-a-new-single-user-policy" title="Permalink to this headline">¶</a></h3>
<ol class="simple">
<li><p>Make a new file, e.g., <code class="docutils literal notranslate"><span class="pre">MyPolicy.py</span></code></p></li>
<li><p>Save it in <a class="reference external" href="Policies/"><code class="docutils literal notranslate"><span class="pre">Policies/</span></code></a></p></li>
<li><p>The file should contain a class of the same name, it can inherit from <a class="reference external" href="https://smpybandits.github.io/docs/Policies.IndexPolicy.html"><code class="docutils literal notranslate"><span class="pre">Policies/IndexPolicy</span></code></a> if it is a simple <a class="reference external" href="https://smpybandits.github.io/docs/Policies.IndexPolicy.html">index policy</a>, e.g., like this, <code class="docutils literal notranslate"><span class="pre">class</span> <span class="pre">MyPolicy(IndexPolicy):</span> <span class="pre">...</span></code> (no need for any <a class="reference external" href="https://stackoverflow.com/questions/576169/ddg#576183"><code class="docutils literal notranslate"><span class="pre">super</span></code></a> call), or simply like <code class="docutils literal notranslate"><span class="pre">class</span> <span class="pre">MyPolicy(object):</span> <span class="pre">...</span></code></p></li>
<li><p>This class <code class="docutils literal notranslate"><span class="pre">MyPolicy</span></code> has to <strong>have at least</strong> an <code class="docutils literal notranslate"><span class="pre">__init__(nbArms,</span> <span class="pre">...)</span></code> method to create the policy object (with or without arguments - named or not), with <strong>at least</strong> the parameter <code class="docutils literal notranslate"><span class="pre">nbArms</span></code> (number of arms); a <code class="docutils literal notranslate"><span class="pre">__str__</span></code> method to print it as a string; a <code class="docutils literal notranslate"><span class="pre">choice()</span></code> method to choose an arm (index among <code class="docutils literal notranslate"><span class="pre">0,</span> <span class="pre">...,</span> <span class="pre">nbArms</span> <span class="pre">-</span> <span class="pre">1</span></code>, e.g., at random, or based on a maximum index if it is an <a class="reference external" href="https://smpybandits.github.io/docs/Policies.IndexPolicy.html">index policy</a>); and a <code class="docutils literal notranslate"><span class="pre">getReward(arm,</span> <span class="pre">reward)</span></code> method called when the arm <code class="docutils literal notranslate"><span class="pre">arm</span></code> gave the reward <code class="docutils literal notranslate"><span class="pre">reward</span></code>, and finally a <code class="docutils literal notranslate"><span class="pre">startGame()</span></code> method (possibly empty) which is called when a new simulation is ran.</p></li>
<li><p>Optionally, a policy class can have a <code class="docutils literal notranslate"><span class="pre">handleCollision(arm)</span></code> method to handle a collision after choosing the arm <code class="docutils literal notranslate"><span class="pre">arm</span></code> (eg. update an internal index, change a fixed offset etc).</p></li>
<li><p>Finally, add it to the <a class="reference external" href="https://smpybandits.github.io/docs/Policies.__init__.html"><code class="docutils literal notranslate"><span class="pre">Policies/__init__.py</span></code></a> file: <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">.MyPolicy</span> <span class="pre">import</span> <span class="pre">MyPolicy</span></code></p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>For examples, see <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Uniform.html"><code class="docutils literal notranslate"><span class="pre">Arms.Uniform</span></code></a> for a fully randomized policy, <a class="reference external" href="https://smpybandits.github.io/docs/Arms.EpsilonGreedy.html"><code class="docutils literal notranslate"><span class="pre">Arms.EpsilonGreedy</span></code></a> for a simple exploratory policy, <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Softmax.html"><code class="docutils literal notranslate"><span class="pre">Arms.Softmax</span></code></a> for another simple approach, <a class="reference external" href="https://smpybandits.github.io/docs/Arms.UCB.html"><code class="docutils literal notranslate"><span class="pre">Arms.UCB</span></code></a> for the class Upper Confidence-Bounds policy based on indexes, so inheriting from <a class="reference external" href="https://smpybandits.github.io/docs/Policies.IndexPolicy.html"><code class="docutils literal notranslate"><span class="pre">Policies/IndexPolicy</span></code></a>). There is also <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Thompson.html"><code class="docutils literal notranslate"><span class="pre">Arms.Thompson</span></code></a> and <a class="reference external" href="https://smpybandits.github.io/docs/Arms.BayesUCB.html"><code class="docutils literal notranslate"><span class="pre">Arms.BayesUCB</span></code></a> for Bayesian policies (using a posterior, e.g., like <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Beta.html"><code class="docutils literal notranslate"><span class="pre">Arms.Beta</span></code></a>), <a class="reference external" href="https://smpybandits.github.io/docs/Arms.klUCB.html"><code class="docutils literal notranslate"><span class="pre">Arms.klUCB</span></code></a> for a policy based on the <a class="reference external" href="https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence">Kullback-Leibler divergence</a>.</p></li>
<li><p>For less classical <a class="reference external" href="https://smpybandits.github.io/docs/Arms.AdBandit.html"><code class="docutils literal notranslate"><span class="pre">Arms.AdBandit</span></code></a> is an approach combining Bayesian and frequentist point of view, and <a class="reference external" href="https://smpybandits.github.io/docs/Arms.Aggregator.html"><code class="docutils literal notranslate"><span class="pre">Arms.Aggregator</span></code></a> is <a class="reference internal" href="Aggregation.html"><span class="doc">my aggregating policy</span></a>.</p></li>
</ul>
</div></blockquote>
<blockquote>
<div><ul class="simple">
<li><p>For example, use this template:</p></li>
</ul>
</div></blockquote>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyPolicy</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nbArms</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">nbArms</span> <span class="o">=</span> <span class="n">nbArms</span>
<span class="c1"># TODO Finish this method that initialize the arm MyArm</span>
<span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">"MyArm(...)"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s1">'...'</span><span class="p">)</span> <span class="c1"># TODO</span>
<span class="k">def</span> <span class="nf">startGame</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">pass</span> <span class="c1"># Can be non-trivial, TODO if needed</span>
<span class="k">def</span> <span class="nf">getReward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">arm</span><span class="p">,</span> <span class="n">reward</span><span class="p">):</span>
<span class="c1"># TODO After the arm 'arm' has been pulled, it gave the reward 'reward'</span>
<span class="k">pass</span> <span class="c1"># Can be non-trivial, TODO if needed</span>
<span class="k">def</span> <span class="nf">choice</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c1"># TODO Do a smart choice of arm</span>
<span class="k">return</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nbArms</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">handleCollision</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">arm</span><span class="p">):</span>
<span class="k">pass</span> <span class="c1"># Can be non-trivial, TODO if needed</span>
</pre></div>
</div>
<blockquote>
<div><p>Other <code class="docutils literal notranslate"><span class="pre">choice...()</span></code> methods can be added, if this policy <code class="docutils literal notranslate"><span class="pre">MyPolicy</span></code> has to be used for multiple play, ranked play, etc.</p>
</div></blockquote>
</div>
<hr class="docutils" />
<div class="section" id="for-a-new-multi-users-policy">
<h3>For a <strong>new multi-users policy</strong><a class="headerlink" href="#for-a-new-multi-users-policy" title="Permalink to this headline">¶</a></h3>
<ol class="simple">
<li><p>Make a new file, e.g., <code class="docutils literal notranslate"><span class="pre">MyPoliciesMultiPlayers.py</span></code></p></li>
<li><p>Save it in <a class="reference external" href="PoliciesMultiPlayers/"><code class="docutils literal notranslate"><span class="pre">PoliciesMultiPlayers/</span></code></a></p></li>
<li><p>The file should contain a class, of the same name, e.g., like this, <code class="docutils literal notranslate"><span class="pre">class</span> <span class="pre">MyPoliciesMultiPlayers(object):</span></code></p></li>
<li><p>This class <code class="docutils literal notranslate"><span class="pre">MyPoliciesMultiPlayers</span></code> has to <strong>have at least</strong> an <code class="docutils literal notranslate"><span class="pre">__init__</span></code> method to create the arm; a <code class="docutils literal notranslate"><span class="pre">__str__</span></code> method to print it as a string; and a <code class="docutils literal notranslate"><span class="pre">children</span></code> <strong>attribute</strong> that gives a list of <em>players</em> (<a class="reference external" href="#for-a-new-single-user-policy">single-player policies</a>).</p></li>
<li><p>Finally, add it to the <a class="reference external" href="https://smpybandits.github.io/docs/PoliciesMultiPlayers.__init__.html"><code class="docutils literal notranslate"><span class="pre">PoliciesMultiPlayers/__init__.py</span></code></a> file: <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">.MyPoliciesMultiPlayers</span> <span class="pre">import</span> <span class="pre">MyPoliciesMultiPlayers</span></code></p></li>
</ol>
<blockquote>
<div><p>For examples, see <a class="reference external" href="https://smpybandits.github.io/docs/PoliciesMultiPlayers.OracleNotFair.html"><code class="docutils literal notranslate"><span class="pre">PoliciesMultiPlayers.OracleNotFair</span></code></a> and <a class="reference external" href="https://smpybandits.github.io/docs/PoliciesMultiPlayers.OracleFair.html"><code class="docutils literal notranslate"><span class="pre">PoliciesMultiPlayers.OracleFair</span></code></a> for full-knowledge centralized policies (fair or not), <a class="reference external" href="https://smpybandits.github.io/docs/PoliciesMultiPlayers.CentralizedFixed.html"><code class="docutils literal notranslate"><span class="pre">PoliciesMultiPlayers.CentralizedFixed</span></code></a> and <a class="reference external" href="https://smpybandits.github.io/docs/PoliciesMultiPlayers.CentralizedCycling.html"><code class="docutils literal notranslate"><span class="pre">PoliciesMultiPlayers.CentralizedCycling</span></code></a> for non-full-knowledge centralized policies (fair or not). There is also the <a class="reference external" href="https://smpybandits.github.io/docs/PoliciesMultiPlayers.Selfish.html"><code class="docutils literal notranslate"><span class="pre">PoliciesMultiPlayers.Selfish</span></code></a> decentralized policy, where all players runs in without any knowledge on the number of players, and no communication (decentralized).</p>
</div></blockquote>
<blockquote>
<div><p><a class="reference external" href="https://smpybandits.github.io/docs/PoliciesMultiPlayers.Selfish.html"><code class="docutils literal notranslate"><span class="pre">PoliciesMultiPlayers.Selfish</span></code></a> is the simplest possible example I could give as a template.</p>
</div></blockquote>
</div>
<hr class="docutils" />
<div class="section" id="scroll-license-github-license">
<h3>📜 License ? <a class="reference external" href="https://github.com/SMPyBandits/SMPyBandits/blob/master/LICENSE"><img alt="GitHub license" src="https://img.shields.io/github/license/SMPyBandits/SMPyBandits.svg" /></a><a class="headerlink" href="#scroll-license-github-license" title="Permalink to this headline">¶</a></h3>
<p><a class="reference external" href="https://lbesson.mit-license.org/">MIT Licensed</a> (file <a class="reference external" href="LICENSE">LICENSE</a>).</p>
<p>© 2016-2018 <a class="reference external" href="https://GitHub.com/Naereen">Lilian Besson</a>.</p>
<p><a class="reference external" href="https://github.com/SMPyBandits/SMPyBandits/"><img alt="Open Source? Yes!" src="https://badgen.net/badge/Open%20Source%20%3F/Yes%21/blue?icon=github" /></a>
<a class="reference external" href="https://GitHub.com/SMPyBandits/SMPyBandits/graphs/commit-activity"><img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" /></a>
<a class="reference external" href="https://GitHub.com/Naereen/ama"><img alt="Ask Me Anything !" src="https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg" /></a>
<a class="reference external" href="https://GitHub.com/SMPyBandits/SMPyBandits/"><img alt="Analytics" src="https://ga-beacon.appspot.com/UA-38514290-17/github.com/SMPyBandits/SMPyBandits/README.md?pixel" /></a>
<img alt="https://pypi.org/project/SMPyBandits" src="https://pypi.org/project/SMPyBandits" /><img alt="PyPI version" src="https://img.shields.io/pypi/v/smpybandits.svg" />
<img alt="https://pypi.org/project/SMPyBandits" src="https://pypi.org/project/SMPyBandits" /><img alt="PyPI implementation" src="https://img.shields.io/pypi/implementation/smpybandits.svg" />
<a class="reference external" href="https://pypi.org/project/SMPyBandits"><img alt="https://pypi.org/project/SMPyBandits" src="https://pypi.org/project/SMPyBandits" /><img alt="PyPI pyversions" src="https://img.shields.io/pypi/pyversions/smpybandits.svg?logo=python" />
</a>
<a class="reference external" href="https://pypi.org/project/SMPyBandits"><img alt="https://pypi.org/project/SMPyBandits" src="https://pypi.org/project/SMPyBandits" /><img alt="PyPI download" src="https://img.shields.io/pypi/dm/smpybandits.svg" /></a>
<a class="reference external" href="https://pypi.org/project/SMPyBandits"><img alt="https://pypi.org/project/SMPyBandits" src="https://pypi.org/project/SMPyBandits" /><img alt="PyPI status" src="https://img.shields.io/pypi/status/smpybandits.svg" /></a>
<a class="reference external" href="https://SMPyBandits.ReadTheDocs.io/en/latest/?badge=latest"><img alt="Documentation Status" src="https://readthedocs.org/projects/smpybandits/badge/?version=latest" /></a>
<a class="reference external" href="https://travis-ci.org/SMPyBandits/SMPyBandits"><img alt="Build Status" src="https://travis-ci.org/SMPyBandits/SMPyBandits.svg?branch=master" /></a>
<a class="reference external" href="https://GitHub.com/SMPyBandits/SMPyBandits/stargazers"><img alt="Stars of https://github.com/SMPyBandits/SMPyBandits/" src="https://badgen.net/github/stars/SMPyBandits/SMPyBandits" /></a>
<a class="reference external" href="https://github.com/SMPyBandits/SMPyBandits/releases"><img alt="Releases of https://github.com/SMPyBandits/SMPyBandits/" src="https://badgen.net/github/release/SMPyBandits/SMPyBandits" /></a></p>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="About_parallel_computations.html" class="btn btn-neutral float-right" title="About parallel computations" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="NonStationaryBandits.html" class="btn btn-neutral float-left" title="Non-Stationary Stochastic Multi-Armed Bandits" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2016-2018, Lilian Besson (Naereen)
<span class="lastupdated">
Last updated on 25 Feb 2020, 14h.
</span>
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>