Skip to content

Commit

Permalink
update plots in example-notebook.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Sep 23, 2021
1 parent 7fdf365 commit f959566
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions example-notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts EdgePaths (color='w')\n",
"\n",
"import itertools\n",
"\n",
"# Create a learner and add data on homogeneous grid, so that we can plot it\n",
Expand All @@ -232,7 +230,7 @@
" + learner.plot().relabel(\"With adaptive\")\n",
" + learner2.plot(n, tri_alpha=0.4)\n",
" + learner.plot(tri_alpha=0.4)\n",
").cols(2)"
").cols(2).opts({\"EdgePaths\": dict(color=\"w\")})"
]
},
{
Expand Down Expand Up @@ -287,7 +285,7 @@
"metadata": {},
"outputs": [],
"source": [
"runner.live_plot(update_interval=0.1)"
"runner.live_plot(update_interval=0.3)"
]
},
{
Expand Down Expand Up @@ -392,7 +390,7 @@
"metadata": {},
"outputs": [],
"source": [
"runner.live_plot(update_interval=0.1)"
"runner.live_plot(update_interval=1)"
]
},
{
Expand Down Expand Up @@ -538,7 +536,7 @@
"metadata": {},
"outputs": [],
"source": [
"runner.live_plot(update_interval=0.1)"
"runner.live_plot(update_interval=0.3)"
]
},
{
Expand Down Expand Up @@ -602,15 +600,17 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Path {+framewise}\n",
"def plot_cut(x1, x2, directions, learner=learner):\n",
" cut_mapping = {'xyz'.index(d): x for d, x in zip(directions, [x1, x2])}\n",
" return learner.plot_slice(cut_mapping)\n",
" cut_mapping = {\"xyz\".index(d): x for d, x in zip(directions, [x1, x2])}\n",
" return learner.plot_slice(cut_mapping).opts({\"Path\": dict(framewise=True)})\n",
"\n",
"dm = hv.DynamicMap(plot_cut, kdims=['v1', 'v2', 'directions'])\n",
"dm.redim.values(v1=np.linspace(-1, 1),\n",
" v2=np.linspace(-1, 1),\n",
" directions=['xy', 'xz', 'yz'])"
"\n",
"dm = hv.DynamicMap(plot_cut, kdims=[\"v1\", \"v2\", \"directions\"])\n",
"dm.redim.values(\n",
" v1=np.linspace(-1, 1),\n",
" v2=np.linspace(-1, 1),\n",
" directions=[\"xy\", \"xz\", \"yz\"],\n",
")"
]
},
{
Expand Down Expand Up @@ -676,26 +676,36 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts EdgePaths (color='w') Image [logz=True]\n",
"\n",
"from adaptive.runner import SequentialExecutor\n",
"\n",
"\n",
"def uniform_sampling_2d(ip):\n",
" from adaptive.learner.learner2D import areas\n",
"\n",
" A = areas(ip)\n",
" return np.sqrt(A)\n",
"\n",
"\n",
"def f_divergent_2d(xy):\n",
" x, y = xy\n",
" return 1 / (x**2 + y**2)\n",
" return 1 / (x ** 2 + y ** 2)\n",
"\n",
"\n",
"learner = adaptive.Learner2D(f_divergent_2d, [(-1, 1), (-1, 1)], loss_per_triangle=uniform_sampling_2d)\n",
"def plot_logz(learner):\n",
" p = learner.plot(tri_alpha=0.3).relabel(\"1 / (x^2 + y^2) in log scale\")\n",
" return p.opts({\"Image\": dict(logz=True), \"EdgePaths\": dict(color=\"w\")})\n",
"\n",
"\n",
"learner = adaptive.Learner2D(\n",
" f_divergent_2d,\n",
" bounds=[(-1, 1), (-1, 1)],\n",
" loss_per_triangle=uniform_sampling_2d,\n",
")\n",
"\n",
"# this takes a while, so use the async Runner so we know *something* is happening\n",
"runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.02)\n",
"runner.live_info()\n",
"runner.live_plot(update_interval=0.2,\n",
" plotter=lambda l: l.plot(tri_alpha=0.3).relabel('1 / (x^2 + y^2) in log scale'))"
"runner.live_plot(update_interval=0.2, plotter=plot_logz)"
]
},
{
Expand Down Expand Up @@ -724,8 +734,6 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts EdgePaths (color='w') Image [logz=True]\n",
"\n",
"def resolution_loss(ip, min_distance=0, max_distance=1):\n",
" \"\"\"min_distance and max_distance should be in between 0 and 1\n",
" because the total area is normalized to 1.\"\"\"\n",
Expand Down Expand Up @@ -757,7 +765,7 @@
"\n",
"learner = adaptive.Learner2D(f_divergent_2d, [(-1, 1), (-1, 1)], loss_per_triangle=loss)\n",
"runner = adaptive.BlockingRunner(learner, goal=lambda l: l.loss() < 0.02)\n",
"learner.plot(tri_alpha=0.3).relabel('1 / (x^2 + y^2) in log scale')"
"plot_logz(learner)"
]
},
{
Expand Down

0 comments on commit f959566

Please sign in to comment.