{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Developer API Example on Hartmann6\n", "\n", "The Developer API is suitable when the user wants maximal customization of the optimization loop. This tutorial demonstrates optimization of a Hartmann6 function using the `SimpleExperiment` construct, which we use for synchronous experiments, where trials can be evaluated right away.\n", "\n", "For more details on the different Ax constructs, see the \"Building Blocks of Ax\" tutorial." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "[INFO 04-17 18:30:07] ipy_plotting: Injecting Plotly library into cell. Do not overwrite or delete cell.\n" ] }, { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "from ax import (\n", " ComparisonOp,\n", " ParameterType, \n", " RangeParameter,\n", " SearchSpace, \n", " SimpleExperiment, \n", " OutcomeConstraint, \n", ")\n", "from ax.metrics.l2norm import L2NormMetric\n", "from ax.modelbridge.registry import Models\n", "from ax.plot.contour import plot_contour\n", "from ax.plot.trace import optimization_trace_single_method\n", "from ax.utils.measurement.synthetic_functions import hartmann6\n", "from ax.utils.notebook.plotting import render, init_notebook_plotting\n", "\n", "init_notebook_plotting()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Define evaluation function\n", "\n", "First, we define an evaluation function that is able to compute all the metrics needed for this experiment. This function needs to accept a set of parameter values and can also accept a weight. It should produce a dictionary of metric names to tuples of mean and standard error for those metrics. Note that when using `Experiment` (instead of `SimpleExperiment`), it's possible to deploy trials and fetch their evaluation results asynchronously; more on that in the \"Building Blocks of Ax\" tutorial." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def hartmann_evaluation_function(\n", " parameterization, # Mapping of parameter names to values of those parameters.\n", " weight=None, # Optional weight argument.\n", "):\n", " x = np.array([parameterization.get(f\"x{i}\") for i in range(6)])\n", " # In our case, standard error is 0, since we are computing a synthetic function.\n", " return {\"hartmann6\": (hartmann6(x), 0.0), \"l2norm\": (np.sqrt((x ** 2).sum()), 0.0)}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If there is only one metric in the experiment – the objective – then evaluation function can return a single tuple of mean and SEM, in which case Ax will assume that evaluation corresponds to the objective. It can also return only the mean as a float, in which case Ax will treat SEM as unknown and use a model that can infer it. For more details on evaluation function, refer to the \"Trial Evaluation\" section in the docs." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Create Search Space\n", "\n", "Second, we define a search space, which defines the type and allowed range for the parameters." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "hartmann_search_space = SearchSpace(\n", " parameters=[\n", " RangeParameter(\n", " name=f\"x{i}\", parameter_type=ParameterType.FLOAT, lower=0.0, upper=1.0\n", " )\n", " for i in range(6)\n", " ]\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Create Experiment\n", "\n", "Third, we make a `SimpleExperiment`. In addition to the search space and evaluation function, here we define the `objective_name` and `outcome_constraints`.\n", "\n", "When doing the optimization, we will find points that minimize the objective while obeying the constraints (which in this case means `l2norm < 1.25`)." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "exp = SimpleExperiment(\n", " name=\"test_branin\",\n", " search_space=hartmann_search_space,\n", " evaluation_function=hartmann_evaluation_function,\n", " objective_name=\"hartmann6\",\n", " minimize=True,\n", " outcome_constraints=[\n", " OutcomeConstraint(\n", " metric=L2NormMetric(\n", " name=\"l2norm\", param_names=[f\"x{i}\" for i in range(6)], noise_sd=0.2\n", " ),\n", " op=ComparisonOp.LEQ,\n", " bound=1.25,\n", " relative=False,\n", " )\n", " ],\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Perform Optimization\n", "\n", "Run the optimization using the settings defined on the experiment. We will create 5 random sobol points for exploration followed by 15 points generated using the GPEI optimizer." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running Sobol initialization trials...\n", "Running GP+EI optimization trial 1/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 2/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 3/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 4/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 5/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 6/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 7/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 8/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 9/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 10/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 11/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 12/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 13/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 14/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 15/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 16/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 17/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 18/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 19/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 20/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 21/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 22/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 23/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 24/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running GP+EI optimization trial 25/15...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Done!\n" ] } ], "source": [ "print(f\"Running Sobol initialization trials...\")\n", "sobol = Models.SOBOL(exp.search_space)\n", "for i in range(5):\n", " exp.new_trial(generator_run=sobol.gen(1))\n", " \n", "for i in range(25):\n", " print(f\"Running GP+EI optimization trial {i+1}/15...\")\n", " # Reinitialize GP+EI model at each step with updated data.\n", " gpei = Models.BOTORCH(experiment=exp, data=exp.eval())\n", " batch = exp.new_trial(generator_run=gpei.gen(1))\n", " \n", "print(\"Done!\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5. Inspect trials' data\n", "\n", "Now we can inspect the `SimpleExperiment`'s data by calling `eval()`, which retrieves evaluation data for all batches of the experiment.\n", "\n", "We can also use the `eval_trial` function to get evaluation data for a specific trial in the experiment, like so:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
arm_namemetric_namemeansemtrial_index
01_0hartmann6-0.1431740.01
11_0l2norm1.1118970.01
\n", "
" ], "text/plain": [ " arm_name metric_name mean sem trial_index\n", "0 1_0 hartmann6 -0.143174 0.0 1\n", "1 1_0 l2norm 1.111897 0.0 1" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "trial_data = exp.eval_trial(exp.trials[1])\n", "trial_data.df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 6. Plot results\n", "Now we can plot the results of our optimization:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": false }, "data": [ { "hoverinfo": "none", "legendgroup": "", "line": { "width": 0 }, "mode": "lines", "showlegend": false, "type": "scatter", "x": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ], "y": [ -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -2.3050333604714535, -2.3050333604714535, -2.5134225819592686, -2.5134225819592686, -2.5134225819592686, -2.71284060093931, -2.9441030512617092, -2.9441030512617092, -2.9441030512617092, -3.1483841368566434, -3.2582095733439287, -3.2582095733439287, -3.2582095733439287, -3.3084208583254937, -3.309898789985639, -3.309898789985639, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267 ] }, { "fill": "tonexty", "fillcolor": "rgba(128,177,211,0.3)", "legendgroup": "mean", "line": { "color": "rgba(128,177,211,1)" }, "mode": "lines", "name": "mean", "type": "scatter", "x": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ], "y": [ -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -2.3050333604714535, -2.3050333604714535, -2.5134225819592686, -2.5134225819592686, -2.5134225819592686, -2.71284060093931, -2.9441030512617092, -2.9441030512617092, -2.9441030512617092, -3.1483841368566434, -3.2582095733439287, -3.2582095733439287, -3.2582095733439287, -3.3084208583254937, -3.309898789985639, -3.309898789985639, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267 ] }, { "fill": "tonexty", "fillcolor": "rgba(128,177,211,0.3)", "hoverinfo": "none", "legendgroup": "", "line": { "width": 0 }, "mode": "lines", "showlegend": false, "type": "scatter", "x": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 ], "y": [ -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -1.74841576325801, -2.3050333604714535, -2.3050333604714535, -2.5134225819592686, -2.5134225819592686, -2.5134225819592686, -2.71284060093931, -2.9441030512617092, -2.9441030512617092, -2.9441030512617092, -3.1483841368566434, -3.2582095733439287, -3.2582095733439287, -3.2582095733439287, -3.3084208583254937, -3.309898789985639, -3.309898789985639, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267, -3.3203731433920267 ] }, { "line": { "color": "rgba(253,180,98,1)", "dash": "dash" }, "mode": "lines", "name": "Optimum", "type": "scatter", "x": [ 1, 30 ], "y": [ -3.32237, -3.32237 ] } ], "layout": { "showlegend": true, "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ], "sequentialminus": [ [ 0.0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1.0, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } }, "title": { "text": "" }, "xaxis": { "title": { "text": "Iteration" } }, "yaxis": { "title": { "text": "" } } } }, "text/html": [ "
\n", " \n", " \n", "
\n", " \n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# `plot_single_method` expects a 2-d array of means, because it expects to average means from multiple \n", "# optimization runs, so we wrap out best objectives array in another array.\n", "objective_means = np.array([[trial.objective_mean for trial in exp.trials.values()]])\n", "best_objective_plot = optimization_trace_single_method(\n", " y=np.minimum.accumulate(objective_means, axis=1),\n", " optimum=-3.32237, # Known minimum objective for Hartmann6 function.\n", ")\n", "render(best_objective_plot)" ] } ], "metadata": { "kernelspec": { "display_name": "python3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.1" } }, "nbformat": 4, "nbformat_minor": 2 }