Browse code

small changes to notebook

Bas Nijholt authored on 18/08/2017 18:14:50
Showing 1 changed files
... ...
@@ -2,10 +2,7 @@
2 2
  "cells": [
3 3
   {
4 4
    "cell_type": "markdown",
5
-   "metadata": {
6
-    "deletable": true,
7
-    "editable": true
8
-   },
5
+   "metadata": {},
9 6
    "source": [
10 7
     "# Adaptive"
11 8
    ]
... ...
@@ -13,28 +10,13 @@
13 10
   {
14 11
    "cell_type": "code",
15 12
    "execution_count": null,
16
-   "metadata": {
17
-    "collapsed": false,
18
-    "deletable": true,
19
-    "editable": true
20
-   },
13
+   "metadata": {},
21 14
    "outputs": [],
22 15
    "source": [
23 16
     "import adaptive\n",
17
+    "import numpy as np\n",
18
+    "adaptive.notebook_extension()\n",
24 19
     "\n",
25
-    "adaptive.notebook_extension()"
26
-   ]
27
-  },
28
-  {
29
-   "cell_type": "code",
30
-   "execution_count": null,
31
-   "metadata": {
32
-    "collapsed": true,
33
-    "deletable": true,
34
-    "editable": true
35
-   },
36
-   "outputs": [],
37
-   "source": [
38 20
     "def func(x, wait=True):\n",
39 21
     "    \"\"\"Function with a sharp peak on a smooth background\"\"\"\n",
40 22
     "    import numpy as np\n",
... ...
@@ -45,15 +27,13 @@
45 27
     "    a = 0.001\n",
46 28
     "    if wait:\n",
47 29
     "        sleep(np.random.randint(1, 3))\n",
48
-    "    return x + a**2/(a**2 + (x)**2) #+ np.random.rand(1)"
30
+    "    return x + a**2/(a**2 + (x)**2)"
49 31
    ]
50 32
   },
51 33
   {
52 34
    "cell_type": "markdown",
53 35
    "metadata": {
54
-    "collapsed": true,
55
-    "deletable": true,
56
-    "editable": true
36
+    "collapsed": true
57 37
    },
58 38
    "source": [
59 39
     "## Local Process Pool (default)"
... ...
@@ -62,27 +42,25 @@
62 42
   {
63 43
    "cell_type": "code",
64 44
    "execution_count": null,
65
-   "metadata": {
66
-    "collapsed": false,
67
-    "deletable": true,
68
-    "editable": true
69
-   },
45
+   "metadata": {},
70 46
    "outputs": [],
71 47
    "source": [
48
+    "import concurrent.futures as concurrent\n",
72 49
     "# Initialize the learner\n",
73
-    "learner = adaptive.learner.Learner1D(func)\n",
50
+    "learner = adaptive.learner.Learner1D(func, bounds=(-1, 1))\n",
51
+    "\n",
52
+    "# Next two lines not needed, but just as example that it still works\n",
74 53
     "learner.add_point(-1, func(-1))\n",
75 54
     "learner.add_point(1, func(1))\n",
76
-    "runner = adaptive.Runner(learner, goal=lambda l: l.loss() < 0.1)\n",
55
+    "\n",
56
+    "runner = adaptive.Runner(learner, concurrent.ProcessPoolExecutor(48), goal=lambda l: l.loss(real=True) < 0.01)\n",
77 57
     "adaptive.live_plot(runner)"
78 58
    ]
79 59
   },
80 60
   {
81 61
    "cell_type": "markdown",
82 62
    "metadata": {
83
-    "collapsed": true,
84
-    "deletable": true,
85
-    "editable": true
63
+    "collapsed": true
86 64
    },
87 65
    "source": [
88 66
     "## ipyparallel"
... ...
@@ -92,9 +70,7 @@
92 70
    "cell_type": "code",
93 71
    "execution_count": null,
94 72
    "metadata": {
95
-    "collapsed": false,
96
-    "deletable": true,
97
-    "editable": true
73
+    "collapsed": true
98 74
    },
99 75
    "outputs": [],
100 76
    "source": [
... ...
@@ -104,9 +80,6 @@
104 80
     "\n",
105 81
     "# Initialize the learner\n",
106 82
     "learner = adaptive.learner.Learner1D(func)\n",
107
-    "learner.add_point(-1, func(-1))\n",
108
-    "learner.add_point(1, func(1))\n",
109
-    "\n",
110 83
     "runner = adaptive.Runner(learner, client, goal=lambda l: l.loss() < 0.1)\n",
111 84
     "adaptive.live_plot(runner)"
112 85
    ]
... ...
@@ -115,9 +88,9 @@
115 88
  "metadata": {
116 89
   "anaconda-cloud": {},
117 90
   "kernelspec": {
118
-   "display_name": "adaptive",
91
+   "display_name": "Python 3",
119 92
    "language": "python",
120
-   "name": "adaptive"
93
+   "name": "python3"
121 94
   },
122 95
   "language_info": {
123 96
    "codemirror_mode": {
... ...
@@ -129,7 +102,7 @@
129 102
    "name": "python",
130 103
    "nbconvert_exporter": "python",
131 104
    "pygments_lexer": "ipython3",
132
-   "version": "3.6.1"
105
+   "version": "3.6.2"
133 106
   }
134 107
  },
135 108
  "nbformat": 4,