Skip to content

Commit 7be3854

Browse files
committed
updated basic tour with updated paths
1 parent 6ae61d9 commit 7be3854

File tree

1 file changed

+14
-65
lines changed

1 file changed

+14
-65
lines changed

examples/basic-tour.ipynb

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -421,19 +421,7 @@
421421
"cell_type": "code",
422422
"execution_count": 20,
423423
"metadata": {},
424-
"outputs": [
425-
{
426-
"name": "stderr",
427-
"output_type": "stream",
428-
"text": [
429-
"/Users/adrianmolzon/oss/BayesianOptimization/bayes_opt/bayesian_optimization.py:240: UserWarning: \n",
430-
"Data point [-1.97693359 -2.9275359 ] is outside the bounds of the parameter y.\n",
431-
"\tBounds:\n",
432-
"[-2. 2.]\n",
433-
" self._space.register(params, target, constraint_value)\n"
434-
]
435-
}
436-
],
424+
"outputs": [],
437425
"source": [
438426
"load_logs(new_optimizer, logs=[\"./logs.log\"]);"
439427
]
@@ -521,35 +509,21 @@
521509
"source": [
522510
"## 5.2 Loading the optimizer state\n",
523511
"\n",
524-
"There are two ways to load a saved state, depending on your needs:\n",
525-
"\n",
526-
"1. With the target function (to continue optimization):\n"
512+
"To load with a previously saved state, pass the path of your saved state file to the `load_state_path` parameter. Note that if you've changed the bounds of your parameters, you'll need to pass the updated bounds to the new optimizer.\n"
527513
]
528514
},
529515
{
530516
"cell_type": "code",
531517
"execution_count": 24,
532518
"metadata": {},
533-
"outputs": [
534-
{
535-
"name": "stdout",
536-
"output_type": "stream",
537-
"text": [
538-
"| iter | target | x | y |\n",
539-
"-------------------------------------------------\n",
540-
"| \u001b[39m1 \u001b[39m | \u001b[39m0.9988 \u001b[39m | \u001b[39m0.0196213\u001b[39m | \u001b[39m0.9714562\u001b[39m |\n",
541-
"| \u001b[39m2 \u001b[39m | \u001b[39m0.9214 \u001b[39m | \u001b[39m0.0346617\u001b[39m | \u001b[39m0.7218000\u001b[39m |\n",
542-
"| \u001b[39m3 \u001b[39m | \u001b[39m0.9767 \u001b[39m | \u001b[39m-0.116593\u001b[39m | \u001b[39m1.0987579\u001b[39m |\n",
543-
"| \u001b[39m4 \u001b[39m | \u001b[39m0.9967 \u001b[39m | \u001b[39m0.0414245\u001b[39m | \u001b[39m1.0402841\u001b[39m |\n",
544-
"| \u001b[39m5 \u001b[39m | \u001b[39m0.985 \u001b[39m | \u001b[39m0.1168371\u001b[39m | \u001b[39m0.9630685\u001b[39m |\n",
545-
"=================================================\n"
546-
]
547-
}
548-
],
519+
"outputs": [],
549520
"source": [
550-
"new_optimizer = BayesianOptimization.load(\n",
551-
" \"optimizer_state.json\",\n",
552-
" f=black_box_function\n",
521+
"new_optimizer = BayesianOptimization(\n",
522+
" f=black_box_function,\n",
523+
" pbounds={\"x\": (-2, 3), \"y\": (-3, 3)},\n",
524+
" random_state=1,\n",
525+
" verbose=0,\n",
526+
" load_state_path=\"./optimizer_state.json\"\n",
553527
")\n",
554528
"\n",
555529
"# Continue optimization\n",
@@ -559,36 +533,6 @@
559533
")"
560534
]
561535
},
562-
{
563-
"cell_type": "markdown",
564-
"metadata": {},
565-
"source": [
566-
"2. Without the target function (for analysis only):\n"
567-
]
568-
},
569-
{
570-
"cell_type": "code",
571-
"execution_count": 25,
572-
"metadata": {},
573-
"outputs": [
574-
{
575-
"name": "stdout",
576-
"output_type": "stream",
577-
"text": [
578-
"Best result: {'target': np.float64(0.913023173060441), 'params': {'x': np.float64(0.20692536368024994), 'y': np.float64(1.2101397649312364)}}\n",
579-
"All results: 17 points\n"
580-
]
581-
}
582-
],
583-
"source": [
584-
"# Load state for analysis\n",
585-
"analysis_optimizer = BayesianOptimization.load(\"optimizer_state.json\")\n",
586-
"\n",
587-
"# Can inspect results\n",
588-
"print(\"Best result:\", analysis_optimizer.max)\n",
589-
"print(\"All results:\", len(analysis_optimizer.res), \"points\")"
590-
]
591-
},
592536
{
593537
"cell_type": "markdown",
594538
"metadata": {},
@@ -604,6 +548,11 @@
604548
"\n",
605549
"This tour should be enough to cover most usage scenarios of this package. If, however, you feel like you need to know more, please checkout the `advanced-tour` notebook. There you will be able to find other, more advanced features of this package that could be what you're looking for. Also, browse the examples folder for implementation tips and ideas."
606550
]
551+
},
552+
{
553+
"cell_type": "markdown",
554+
"metadata": {},
555+
"source": []
607556
}
608557
],
609558
"metadata": {

0 commit comments

Comments
 (0)