Browse code

add cool 2D polygon plots for minute meeting

Bas Nijholt authored on 14/09/2017 12:42:00
Showing 1 changed files
... ...
@@ -102,7 +102,7 @@
102 102
    "source": [
103 103
     "# The end condition is when the \"loss\" is less than 0.1. In the context of the\n",
104 104
     "# 1D learner this means that we will resolve features in 'func' with width 0.1 or wider.\n",
105
-    "runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.1)"
105
+    "runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.01)"
106 106
    ]
107 107
   },
108 108
   {
... ...
@@ -177,6 +177,9 @@
177 177
    "source": [
178 178
     "def func(xy):\n",
179 179
     "    import numpy as np\n",
180
+    "    from time import sleep\n",
181
+    "    from random import random\n",
182
+    "    sleep(random())\n",
180 183
     "    x, y = xy\n",
181 184
     "    a = 0.2\n",
182 185
     "    return x + np.exp(-(x**2 + y**2 - 0.75**2)**2/a**4)\n",
... ...
@@ -190,7 +193,7 @@
190 193
    "metadata": {},
191 194
    "outputs": [],
192 195
    "source": [
193
-    "runner = adaptive.Runner(learner, goal=lambda l: l.loss() > 1500)"
196
+    "runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.01, log=True)"
194 197
    ]
195 198
   },
196 199
   {
... ...
@@ -199,7 +202,22 @@
199 202
    "metadata": {},
200 203
    "outputs": [],
201 204
    "source": [
202
-    "adaptive.live_plot(runner)"
205
+    "%%output size=100\n",
206
+    "%%opts Contours (alpha=0.3)\n",
207
+    "from adaptive.learner import *\n",
208
+    "\n",
209
+    "def plot(self):\n",
210
+    "    tri = self.ip.tri\n",
211
+    "    return hv.Contours([p for p in tri.points[tri.vertices]])\n",
212
+    "\n",
213
+    "def plot_poly(self):\n",
214
+    "    tri = self.ip.tri\n",
215
+    "    return hv.Polygons([p for p in tri.points[tri.vertices]])\n",
216
+    "\n",
217
+    "\n",
218
+    "(adaptive.live_plot(runner) +\n",
219
+    " adaptive.live_plot(runner, plotter=plot_poly) +\n",
220
+    " adaptive.live_plot(runner) * adaptive.live_plot(runner, plotter=plot))"
203 221
    ]
204 222
   },
205 223
   {