-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from sgbaird/dev
Add new toggleable options - Attach existing data - Categorical variables - Custom threshold - Single vs. batch optimization
- Loading branch information
Showing
187 changed files
with
14,494 additions
and
1,567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...mposition_constraint-False+categorical-False+custom_threshold-False+synchrony-batch.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1e89e727", | ||
"metadata": {}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/sgbaird/honegumi/blob/main/docs\\generated_notebooks\\ax\\objective-multi+model-FULLYBAYESIAN+custom_gen-True+existing_data-False+sum_constraint-False+order_constraint-False+linear_constraint-False+composition_constraint-False+categorical-False+custom_threshold-False+synchrony-batch.ipynb\"><img alt=\"Open In Colab\" src=\"https://colab.research.google.com/assets/colab-badge.svg\"></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "2e4a348b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%pip install ax-platform" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "c69bdeb0", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"from ax.service.ax_client import AxClient, ObjectiveProperties\n", | ||
"\n", | ||
"from ax.modelbridge.factory import Models\n", | ||
"from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy\n", | ||
"\n", | ||
"\n", | ||
"obj1_name = \"branin\"\n", | ||
"obj2_name = \"branin_swapped\"\n", | ||
"\n", | ||
"\n", | ||
"def branin_moo(x1, x2):\n", | ||
" y = float(\n", | ||
" (x2 - 5.1 / (4 * np.pi**2) * x1**2 + 5.0 / np.pi * x1 - 6.0) ** 2\n", | ||
" + 10 * (1 - 1.0 / (8 * np.pi)) * np.cos(x1)\n", | ||
" + 10\n", | ||
" )\n", | ||
"\n", | ||
" # second objective has x1 and x2 swapped\n", | ||
" y2 = float(\n", | ||
" (x1 - 5.1 / (4 * np.pi**2) * x2**2 + 5.0 / np.pi * x2 - 6.0) ** 2\n", | ||
" + 10 * (1 - 1.0 / (8 * np.pi)) * np.cos(x2)\n", | ||
" + 10\n", | ||
" )\n", | ||
"\n", | ||
" return {obj1_name: y, obj2_name: y2}\n", | ||
"\n", | ||
"\n", | ||
"gs = GenerationStrategy(\n", | ||
" steps=[\n", | ||
" GenerationStep(\n", | ||
" model=Models.SOBOL,\n", | ||
" num_trials=4, # https://github.com/facebook/Ax/issues/922\n", | ||
" min_trials_observed=3,\n", | ||
" max_parallelism=5,\n", | ||
" model_kwargs={\"seed\": 999},\n", | ||
" model_gen_kwargs={},\n", | ||
" ),\n", | ||
" GenerationStep(\n", | ||
" model=Models.FULLYBAYESIANMOO,\n", | ||
" num_trials=-1,\n", | ||
" max_parallelism=3,\n", | ||
" model_kwargs={\"num_samples\": 256, \"warmup_steps\": 512},\n", | ||
" ),\n", | ||
" ]\n", | ||
")\n", | ||
"\n", | ||
"ax_client = AxClient(generation_strategy=gs)\n", | ||
"\n", | ||
"ax_client.create_experiment(\n", | ||
" parameters=[\n", | ||
" {\"name\": \"x1\", \"type\": \"range\", \"bounds\": [-5.0, 10.0]},\n", | ||
" {\"name\": \"x2\", \"type\": \"range\", \"bounds\": [0.0, 10.0]},\n", | ||
" ],\n", | ||
" objectives={\n", | ||
" obj1_name: ObjectiveProperties(minimize=True),\n", | ||
" obj2_name: ObjectiveProperties(minimize=True),\n", | ||
" },\n", | ||
")\n", | ||
"\n", | ||
"\n", | ||
"batch_size = 2\n", | ||
"\n", | ||
"\n", | ||
"for _ in range(19):\n", | ||
"\n", | ||
" parameterizations, optimization_complete = ax_client.get_next_trials(batch_size)\n", | ||
" for trial_index, parameterization in list(parameterizations.items()):\n", | ||
" # extract parameters\n", | ||
" x1 = parameterization[\"x1\"]\n", | ||
" x2 = parameterization[\"x2\"]\n", | ||
"\n", | ||
" results = branin_moo(x1, x2)\n", | ||
" ax_client.complete_trial(trial_index=trial_index, raw_data=results)\n", | ||
"\n", | ||
"pareto_results = ax_client.get_pareto_optimal_parameters()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"jupytext": { | ||
"cell_metadata_filter": "-all", | ||
"main_language": "python", | ||
"notebook_metadata_filter": "-all" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
113 changes: 113 additions & 0 deletions
113
...position_constraint-False+categorical-False+custom_threshold-False+synchrony-single.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6085c430", | ||
"metadata": {}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/sgbaird/honegumi/blob/main/docs\\generated_notebooks\\ax\\objective-multi+model-FULLYBAYESIAN+custom_gen-True+existing_data-False+sum_constraint-False+order_constraint-False+linear_constraint-False+composition_constraint-False+categorical-False+custom_threshold-False+synchrony-single.ipynb\"><img alt=\"Open In Colab\" src=\"https://colab.research.google.com/assets/colab-badge.svg\"></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b34b6676", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%pip install ax-platform" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0f1868d4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"from ax.service.ax_client import AxClient, ObjectiveProperties\n", | ||
"\n", | ||
"from ax.modelbridge.factory import Models\n", | ||
"from ax.modelbridge.generation_strategy import GenerationStep, GenerationStrategy\n", | ||
"\n", | ||
"\n", | ||
"obj1_name = \"branin\"\n", | ||
"obj2_name = \"branin_swapped\"\n", | ||
"\n", | ||
"\n", | ||
"def branin_moo(x1, x2):\n", | ||
" y = float(\n", | ||
" (x2 - 5.1 / (4 * np.pi**2) * x1**2 + 5.0 / np.pi * x1 - 6.0) ** 2\n", | ||
" + 10 * (1 - 1.0 / (8 * np.pi)) * np.cos(x1)\n", | ||
" + 10\n", | ||
" )\n", | ||
"\n", | ||
" # second objective has x1 and x2 swapped\n", | ||
" y2 = float(\n", | ||
" (x1 - 5.1 / (4 * np.pi**2) * x2**2 + 5.0 / np.pi * x2 - 6.0) ** 2\n", | ||
" + 10 * (1 - 1.0 / (8 * np.pi)) * np.cos(x2)\n", | ||
" + 10\n", | ||
" )\n", | ||
"\n", | ||
" return {obj1_name: y, obj2_name: y2}\n", | ||
"\n", | ||
"\n", | ||
"gs = GenerationStrategy(\n", | ||
" steps=[\n", | ||
" GenerationStep(\n", | ||
" model=Models.SOBOL,\n", | ||
" num_trials=4, # https://github.com/facebook/Ax/issues/922\n", | ||
" min_trials_observed=3,\n", | ||
" max_parallelism=5,\n", | ||
" model_kwargs={\"seed\": 999},\n", | ||
" model_gen_kwargs={},\n", | ||
" ),\n", | ||
" GenerationStep(\n", | ||
" model=Models.FULLYBAYESIANMOO,\n", | ||
" num_trials=-1,\n", | ||
" max_parallelism=3,\n", | ||
" model_kwargs={\"num_samples\": 256, \"warmup_steps\": 512},\n", | ||
" ),\n", | ||
" ]\n", | ||
")\n", | ||
"\n", | ||
"ax_client = AxClient(generation_strategy=gs)\n", | ||
"\n", | ||
"ax_client.create_experiment(\n", | ||
" parameters=[\n", | ||
" {\"name\": \"x1\", \"type\": \"range\", \"bounds\": [-5.0, 10.0]},\n", | ||
" {\"name\": \"x2\", \"type\": \"range\", \"bounds\": [0.0, 10.0]},\n", | ||
" ],\n", | ||
" objectives={\n", | ||
" obj1_name: ObjectiveProperties(minimize=True),\n", | ||
" obj2_name: ObjectiveProperties(minimize=True),\n", | ||
" },\n", | ||
")\n", | ||
"\n", | ||
"\n", | ||
"for _ in range(19):\n", | ||
"\n", | ||
" parameterization, trial_index = ax_client.get_next_trial()\n", | ||
"\n", | ||
" # extract parameters\n", | ||
" x1 = parameterization[\"x1\"]\n", | ||
" x2 = parameterization[\"x2\"]\n", | ||
"\n", | ||
" results = branin_moo(x1, x2)\n", | ||
" ax_client.complete_trial(trial_index=trial_index, raw_data=results)\n", | ||
"\n", | ||
"pareto_results = ax_client.get_pareto_optimal_parameters()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"jupytext": { | ||
"cell_metadata_filter": "-all", | ||
"main_language": "python", | ||
"notebook_metadata_filter": "-all" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.