|
69 | 69 | "Once you have Git installed open your terminal, go to your desired directory, and type:\n",
|
70 | 70 | "\n",
|
71 | 71 | "``` bash\n",
|
72 |
| - "git clone https://github.com/machine-learning-tutorial/neural-networks\n", |
73 |
| - "cd neural-networks\n", |
| 72 | + "git clone https://github.com/machine-learning-tutorial/bayesian-optimization\n", |
| 73 | + "cd bayesian-optimization\n", |
74 | 74 | "```\n",
|
75 | 75 | "\n",
|
76 | 76 | "Or get the repository with direct download:\n",
|
77 | 77 | "\n",
|
78 | 78 | "``` bash\n",
|
79 |
| - "wget https://github.com/machine-learning-tutorial/neural_networks/archive/refs/heads/main.zip\n", |
| 79 | + "wget https://github.com/machine-learning-tutorial/bayesian-optimization/archive/refs/heads/main.zip\n", |
80 | 80 | "unzip main.zip\n",
|
81 |
| - "cd neural-networks\n", |
| 81 | + "cd bayesian-optimization\n", |
82 | 82 | "```"
|
83 | 83 | ]
|
84 | 84 | },
|
|
102 | 102 | "Then run the following commands:\n",
|
103 | 103 | "\n",
|
104 | 104 | "```bash\n",
|
105 |
| - "conda create -n nn-tutorial python=3.10\n", |
106 |
| - "conda activate nn-tutorial\n", |
| 105 | + "conda create -n bo-tutorial python=3.10\n", |
| 106 | + "conda activate bo-tutorial\n", |
107 | 107 | "pip install -r requirements.txt\n",
|
108 | 108 | "jupyter contrib nbextension install --user\n",
|
109 | 109 | "jupyter nbextension enable varInspector/main\n",
|
110 | 110 | "```\n",
|
111 | 111 | "\n",
|
112 |
| - "- After the tutorial you can remove your environment with `conda remove -n nn-tutorial --all`" |
| 112 | + "- **After** the tutorial you can remove your environment with `conda remove -n bo-tutorial --all`" |
113 | 113 | ]
|
114 | 114 | },
|
115 | 115 | {
|
|
132 | 132 | "Alternatively, you can create the virtual env with `venv` in the standard library\n",
|
133 | 133 | "\n",
|
134 | 134 | "```bash\n",
|
135 |
| - "python -m venv nn-tutorial\n", |
| 135 | + "python -m venv bo-tutorial\n", |
136 | 136 | "```\n",
|
137 | 137 | "\n",
|
138 | 138 | "and activate the env with $ source <venv>/bin/activate (bash) or C:> <venv>/Scripts/activate.bat (Windows)\n",
|
|
181 | 181 | },
|
182 | 182 | {
|
183 | 183 | "cell_type": "code",
|
184 |
| - "execution_count": 2, |
| 184 | + "execution_count": null, |
185 | 185 | "id": "e538eebc",
|
186 | 186 | "metadata": {
|
187 | 187 | "slideshow": {
|
|
665 | 665 | ]
|
666 | 666 | },
|
667 | 667 | {
|
668 |
| - "attachments": {}, |
669 | 668 | "cell_type": "markdown",
|
670 | 669 | "id": "52408173",
|
671 | 670 | "metadata": {
|
|
830 | 829 | "execution_count": null,
|
831 | 830 | "id": "e12804c8",
|
832 | 831 | "metadata": {
|
| 832 | + "scrolled": true, |
833 | 833 | "slideshow": {
|
834 | 834 | "slide_type": "slide"
|
835 | 835 | }
|
|
1012 | 1012 | "outputs": [],
|
1013 | 1013 | "source": [
|
1014 | 1014 | "# You can change the GP hyperparameters here again\n",
|
1015 |
| - "model.covar_module.base_kernel.lengthscale = 0.5\n", |
| 1015 | + "model.covar_module.base_kernel.lengthscale = 0.1\n", |
1016 | 1016 | "model.covar_module.outputscale = 0.5 # signal variance\n",
|
1017 |
| - "model.likelihood.noise_covar.noise = 0.5" |
| 1017 | + "model.likelihood.noise_covar.noise = 0.02" |
1018 | 1018 | ]
|
1019 | 1019 | },
|
1020 | 1020 | {
|
1021 | 1021 | "cell_type": "code",
|
1022 | 1022 | "execution_count": null,
|
1023 | 1023 | "id": "910e9471",
|
1024 | 1024 | "metadata": {
|
| 1025 | + "scrolled": true, |
1025 | 1026 | "slideshow": {
|
1026 | 1027 | "slide_type": "-"
|
1027 | 1028 | }
|
|
1254 | 1255 | },
|
1255 | 1256 | "outputs": [],
|
1256 | 1257 | "source": [
|
1257 |
| - "acq_UCB = UpperConfidenceBound(model, beta=4)\n", |
| 1258 | + "acq_UCB = UpperConfidenceBound(model, beta=100)\n", |
1258 | 1259 | "plot_acq_with_gp(model, observations_x, observations_y, acq_UCB, test_X, show_true_f=True, \n",
|
1259 | 1260 | " true_f_x= objective_x, true_f_y=objective_y)"
|
1260 | 1261 | ]
|
|
1293 | 1294 | "execution_count": null,
|
1294 | 1295 | "id": "ccb09c56",
|
1295 | 1296 | "metadata": {
|
| 1297 | + "scrolled": true, |
1296 | 1298 | "slideshow": {
|
1297 | 1299 | "slide_type": "slide"
|
1298 | 1300 | }
|
|
1412 | 1414 | "source": [
|
1413 | 1415 | "<h3 style=\"color:#e6541a;\">Get familiar with the Gym environment</h3>\n",
|
1414 | 1416 | "<p style=\"color:#e6541a;\">$\\implies$ Change the magnet values, i.e. the actions</p>\n",
|
1415 |
| - "<p style=\"color:#e6541a;\">$\\implies$ The actions are normalized to 1, so valid values are in the [0, 1] interval</p>\n", |
| 1417 | + "<p style=\"color:#e6541a;\">$\\implies$ The actions are normalized to 1, so valid values are in the [-1, 1] interval</p>\n", |
1416 | 1418 | "<p style=\"color:#e6541a;\">$\\implies$ The values of the <code>action</code> list in the cell below follows this magnet order: [Q1, Q2, CV, Q3, CH]</p>\n",
|
1417 | 1419 | "<p style=\"color:#e6541a;\">$\\implies$ Observe the plot below, what beam does that magnet configuration yield? can you center and focus the beam by hand?</p>"
|
1418 | 1420 | ]
|
|
1428 | 1430 | },
|
1429 | 1431 | "outputs": [],
|
1430 | 1432 | "source": [
|
1431 |
| - "action = [0.5, 0.5, 0.5, 0.5, 0.5]\n", |
1432 |
| - "action = np.array(action)" |
| 1433 | + "action = # fill here\n", |
| 1434 | + "action = np.array(action) # [Q1, Q2, CV, Q3, CH]" |
1433 | 1435 | ]
|
1434 | 1436 | },
|
1435 | 1437 | {
|
|
1528 | 1530 | "metadata": {},
|
1529 | 1531 | "outputs": [],
|
1530 | 1532 | "source": [
|
1531 |
| - "target_beam = [#fill here!]" |
| 1533 | + "target_beam = [0, 1e-4, 0, 1e-4]#fill here!]" |
1532 | 1534 | ]
|
1533 | 1535 | },
|
1534 | 1536 | {
|
|
1705 | 1707 | "<h2>Let's apply Bayesian optimization to this problem</h2>\n",
|
1706 | 1708 | "\n",
|
1707 | 1709 | "- We will use the loop implemented in the cell above\n",
|
1708 |
| - "- In order to quantify how the algorithm is performing, we will use the __log maximum aboslute error (L1 error)__ as metric:\n", |
| 1710 | + "- In order to quantify how the algorithm is performing, we will use the __log mean aboslute error (L1 error)__ as metric:\n", |
1709 | 1711 | "\n",
|
1710 | 1712 | "$$\\begin{aligned}\n",
|
1711 | 1713 | "f(x) &= -\\log(\\mathrm{MAE}(b_\\mathrm{current},b_\\mathrm{target})) \\\\\n",
|
|
1791 | 1793 | "beta = 2.0\n",
|
1792 | 1794 | "acquisition = \"UCB\"\n",
|
1793 | 1795 | "\n",
|
1794 |
| - "opt_info = bayesian_optimize(env, observation, n_steps=40, acquisition=acquisition, beta=beta,\n", |
| 1796 | + "opt_info = bayesian_optimize(env, observation, n_steps=50, acquisition=acquisition, beta=beta,\n", |
1795 | 1797 | " max_step_size=0.3, show_plot=True, time_sleep=0.05) "
|
1796 | 1798 | ]
|
1797 | 1799 | },
|
|
0 commit comments