Browse code

add BalancingLearner in the notebook

Bas Nijholt authored on 31/08/2017 16:13:57
Showing 1 changed files
... ...
@@ -54,7 +54,7 @@
54 54
    "metadata": {},
55 55
    "outputs": [],
56 56
    "source": [
57
-    "import functools\n",
57
+    "from functools import partial\n",
58 58
     "from random import random\n",
59 59
     "\n",
60 60
     "offset = random() - 0.5\n",
... ...
@@ -150,7 +150,7 @@
150 150
     "learner2 = adaptive.learner.Learner1D(f, bounds=(-1.01, 1.0))\n",
151 151
     "\n",
152 152
     "xs = np.linspace(-1.0, 1.0, len(learner.data))\n",
153
-    "learner2.add_data(xs, map(functools.partial(f, wait=False), xs))\n",
153
+    "learner2.add_data(xs, map(partial(f, wait=False), xs))\n",
154 154
     "\n",
155 155
     "learner2.plot()"
156 156
    ]
... ...
@@ -196,11 +196,50 @@
196 196
    "metadata": {},
197 197
    "outputs": [],
198 198
    "source": [
199
-    "learner = adaptive.AverageLearner(g, None, 0.03)\n",
199
+    "learner = adaptive.AverageLearner(g, None, 0.01)\n",
200 200
     "runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 1)\n",
201 201
     "adaptive.live_plot(runner)"
202 202
    ]
203 203
   },
204
+  {
205
+   "cell_type": "markdown",
206
+   "metadata": {},
207
+   "source": [
208
+    "# Balancing learner"
209
+   ]
210
+  },
211
+  {
212
+   "cell_type": "markdown",
213
+   "metadata": {},
214
+   "source": [
215
+    "The balancing learner is a \"meta-learner\" that takes a list of multiple leaners. The runner wil find find out which points of which child learner will improve the loss the most and send those to the executor.\n",
216
+    "\n",
217
+    "The balancing learner can for example be used to implement a poor-man's 2D learner by using the `Learner1D`."
218
+   ]
219
+  },
220
+  {
221
+   "cell_type": "code",
222
+   "execution_count": null,
223
+   "metadata": {},
224
+   "outputs": [],
225
+   "source": [
226
+    "from adaptive.learner import Learner1D, BalancingLearner\n",
227
+    "\n",
228
+    "learners = [Learner1D(partial(f, offset=2*random()-1, wait=False), bounds=(-1.0, 1.0)) for i in range(10)]\n",
229
+    "learner = BalancingLearner(learners)\n",
230
+    "runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.02)"
231
+   ]
232
+  },
233
+  {
234
+   "cell_type": "code",
235
+   "execution_count": null,
236
+   "metadata": {},
237
+   "outputs": [],
238
+   "source": [
239
+    "import holoviews as hv\n",
240
+    "adaptive.live_plot(runner, plotter=lambda learner: hv.Overlay([L.plot() for L in learner.learners]))"
241
+   ]
242
+  },
204 243
   {
205 244
    "cell_type": "markdown",
206 245
    "metadata": {