|
421 | 421 | "cell_type": "code", |
422 | 422 | "execution_count": 20, |
423 | 423 | "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": [], |
437 | 425 | "source": [ |
438 | 426 | "load_logs(new_optimizer, logs=[\"./logs.log\"]);" |
439 | 427 | ] |
|
521 | 509 | "source": [ |
522 | 510 | "## 5.2 Loading the optimizer state\n", |
523 | 511 | "\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" |
527 | 513 | ] |
528 | 514 | }, |
529 | 515 | { |
530 | 516 | "cell_type": "code", |
531 | 517 | "execution_count": 24, |
532 | 518 | "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": [], |
549 | 520 | "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", |
553 | 527 | ")\n", |
554 | 528 | "\n", |
555 | 529 | "# Continue optimization\n", |
|
559 | 533 | ")" |
560 | 534 | ] |
561 | 535 | }, |
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 | | - }, |
592 | 536 | { |
593 | 537 | "cell_type": "markdown", |
594 | 538 | "metadata": {}, |
|
604 | 548 | "\n", |
605 | 549 | "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." |
606 | 550 | ] |
| 551 | + }, |
| 552 | + { |
| 553 | + "cell_type": "markdown", |
| 554 | + "metadata": {}, |
| 555 | + "source": [] |
607 | 556 | } |
608 | 557 | ], |
609 | 558 | "metadata": { |
|
0 commit comments