|
215 | 215 | "metadata": {},
|
216 | 216 | "outputs": [],
|
217 | 217 | "source": [
|
218 |
| - "%%opts EdgePaths (color='w')\n", |
219 |
| - "\n", |
220 | 218 | "import itertools\n",
|
221 | 219 | "\n",
|
222 | 220 | "# Create a learner and add data on homogeneous grid, so that we can plot it\n",
|
|
232 | 230 | " + learner.plot().relabel(\"With adaptive\")\n",
|
233 | 231 | " + learner2.plot(n, tri_alpha=0.4)\n",
|
234 | 232 | " + learner.plot(tri_alpha=0.4)\n",
|
235 |
| - ").cols(2)" |
| 233 | + ").cols(2).opts({\"EdgePaths\": dict(color=\"w\")})" |
236 | 234 | ]
|
237 | 235 | },
|
238 | 236 | {
|
|
287 | 285 | "metadata": {},
|
288 | 286 | "outputs": [],
|
289 | 287 | "source": [
|
290 |
| - "runner.live_plot(update_interval=0.1)" |
| 288 | + "runner.live_plot(update_interval=0.3)" |
291 | 289 | ]
|
292 | 290 | },
|
293 | 291 | {
|
|
392 | 390 | "metadata": {},
|
393 | 391 | "outputs": [],
|
394 | 392 | "source": [
|
395 |
| - "runner.live_plot(update_interval=0.1)" |
| 393 | + "runner.live_plot(update_interval=1)" |
396 | 394 | ]
|
397 | 395 | },
|
398 | 396 | {
|
|
538 | 536 | "metadata": {},
|
539 | 537 | "outputs": [],
|
540 | 538 | "source": [
|
541 |
| - "runner.live_plot(update_interval=0.1)" |
| 539 | + "runner.live_plot(update_interval=0.3)" |
542 | 540 | ]
|
543 | 541 | },
|
544 | 542 | {
|
|
602 | 600 | "metadata": {},
|
603 | 601 | "outputs": [],
|
604 | 602 | "source": [
|
605 |
| - "%%opts Path {+framewise}\n", |
606 | 603 | "def plot_cut(x1, x2, directions, learner=learner):\n",
|
607 |
| - " cut_mapping = {'xyz'.index(d): x for d, x in zip(directions, [x1, x2])}\n", |
608 |
| - " return learner.plot_slice(cut_mapping)\n", |
| 604 | + " cut_mapping = {\"xyz\".index(d): x for d, x in zip(directions, [x1, x2])}\n", |
| 605 | + " return learner.plot_slice(cut_mapping).opts({\"Path\": dict(framewise=True)})\n", |
609 | 606 | "\n",
|
610 |
| - "dm = hv.DynamicMap(plot_cut, kdims=['v1', 'v2', 'directions'])\n", |
611 |
| - "dm.redim.values(v1=np.linspace(-1, 1),\n", |
612 |
| - " v2=np.linspace(-1, 1),\n", |
613 |
| - " directions=['xy', 'xz', 'yz'])" |
| 607 | + "\n", |
| 608 | + "dm = hv.DynamicMap(plot_cut, kdims=[\"v1\", \"v2\", \"directions\"])\n", |
| 609 | + "dm.redim.values(\n", |
| 610 | + " v1=np.linspace(-1, 1),\n", |
| 611 | + " v2=np.linspace(-1, 1),\n", |
| 612 | + " directions=[\"xy\", \"xz\", \"yz\"],\n", |
| 613 | + ")" |
614 | 614 | ]
|
615 | 615 | },
|
616 | 616 | {
|
|
676 | 676 | "metadata": {},
|
677 | 677 | "outputs": [],
|
678 | 678 | "source": [
|
679 |
| - "%%opts EdgePaths (color='w') Image [logz=True]\n", |
680 |
| - "\n", |
681 | 679 | "from adaptive.runner import SequentialExecutor\n",
|
682 | 680 | "\n",
|
| 681 | + "\n", |
683 | 682 | "def uniform_sampling_2d(ip):\n",
|
684 | 683 | " from adaptive.learner.learner2D import areas\n",
|
| 684 | + "\n", |
685 | 685 | " A = areas(ip)\n",
|
686 | 686 | " return np.sqrt(A)\n",
|
687 | 687 | "\n",
|
| 688 | + "\n", |
688 | 689 | "def f_divergent_2d(xy):\n",
|
689 | 690 | " x, y = xy\n",
|
690 |
| - " return 1 / (x**2 + y**2)\n", |
| 691 | + " return 1 / (x ** 2 + y ** 2)\n", |
| 692 | + "\n", |
691 | 693 | "\n",
|
692 |
| - "learner = adaptive.Learner2D(f_divergent_2d, [(-1, 1), (-1, 1)], loss_per_triangle=uniform_sampling_2d)\n", |
| 694 | + "def plot_logz(learner):\n", |
| 695 | + " p = learner.plot(tri_alpha=0.3).relabel(\"1 / (x^2 + y^2) in log scale\")\n", |
| 696 | + " return p.opts({\"Image\": dict(logz=True), \"EdgePaths\": dict(color=\"w\")})\n", |
| 697 | + "\n", |
| 698 | + "\n", |
| 699 | + "learner = adaptive.Learner2D(\n", |
| 700 | + " f_divergent_2d,\n", |
| 701 | + " bounds=[(-1, 1), (-1, 1)],\n", |
| 702 | + " loss_per_triangle=uniform_sampling_2d,\n", |
| 703 | + ")\n", |
693 | 704 | "\n",
|
694 | 705 | "# this takes a while, so use the async Runner so we know *something* is happening\n",
|
695 | 706 | "runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.02)\n",
|
696 | 707 | "runner.live_info()\n",
|
697 |
| - "runner.live_plot(update_interval=0.2,\n", |
698 |
| - " plotter=lambda l: l.plot(tri_alpha=0.3).relabel('1 / (x^2 + y^2) in log scale'))" |
| 708 | + "runner.live_plot(update_interval=0.2, plotter=plot_logz)" |
699 | 709 | ]
|
700 | 710 | },
|
701 | 711 | {
|
|
724 | 734 | "metadata": {},
|
725 | 735 | "outputs": [],
|
726 | 736 | "source": [
|
727 |
| - "%%opts EdgePaths (color='w') Image [logz=True]\n", |
728 |
| - "\n", |
729 | 737 | "def resolution_loss(ip, min_distance=0, max_distance=1):\n",
|
730 | 738 | " \"\"\"min_distance and max_distance should be in between 0 and 1\n",
|
731 | 739 | " because the total area is normalized to 1.\"\"\"\n",
|
|
757 | 765 | "\n",
|
758 | 766 | "learner = adaptive.Learner2D(f_divergent_2d, [(-1, 1), (-1, 1)], loss_per_triangle=loss)\n",
|
759 | 767 | "runner = adaptive.BlockingRunner(learner, goal=lambda l: l.loss() < 0.02)\n",
|
760 |
| - "learner.plot(tri_alpha=0.3).relabel('1 / (x^2 + y^2) in log scale')" |
| 768 | + "plot_logz(learner)" |
761 | 769 | ]
|
762 | 770 | },
|
763 | 771 | {
|
|
0 commit comments