{ "cells": [ { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Analyzing results\n", "=================\n", "\n", "Optimas provides a convenient :class:`~optimas.diagnostics.ExplorationDiagnostics`\n", "class to easily analyze and visualize the output of an exploration without\n", "having to manually access each file.\n", "\n", "The examples below showcase the functionality of this class by analyzing the\n", "output of this :ref:`basic Bayesian optimization example `." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "%cd ../../../../examples/dummy/\n", "!python run_example.py" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Import and initialize diagnostics\n", "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", "\n", "The diagnostics class only requires the path to the exploration directory\n", "as input parameter." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from optimas.diagnostics import ExplorationDiagnostics\n", "\n", "diags = ExplorationDiagnostics(\"./exploration\")" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Access exploration history\n", "~~~~~~~~~~~~~~~~~~~~~~~~~~\n", "\n", "The diagnostics provide easy access to the exploration history, which\n", "is returned as a pandas ``DataFrame``." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "diags.history" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Built-in plotting utilities\n", "~~~~~~~~~~~~~~~~~~~~~~~~~~~\n", "\n", "Several basic plotting functions are provided by the diagnostics class.\n", "The example below uses\n", ":meth:`~optimas.diagnostics.ExplorationDiagnostics.plot_objective`\n", "to show the value of the objective `f` for each evaluation, as well as\n", "the evolution of the cumulative best." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "diags.plot_objective(show_trace=True)" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "User plots\n", "~~~~~~~~~~\n", "\n", "The :class:`~optimas.diagnostics.ExplorationDiagnostics` exposes all\n", "necessary data to perform any analysis or plot of the exploration.\n", "As an example, the code below generates a plot of the phase-space of the\n", "optimization, including the value of each evaluation and the boundaries of\n", "the varying parameters." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "fig, ax = plt.subplots()\n", "vps = diags.varying_parameters\n", "df = diags.history\n", "f1 = diags.objectives[0]\n", "ax.axvline(vps[0].lower_bound)\n", "ax.axvline(vps[0].upper_bound)\n", "ax.set_xlabel(vps[0].name)\n", "ax.axhline(vps[1].lower_bound)\n", "ax.axhline(vps[1].upper_bound)\n", "ax.set_ylabel(vps[1].name)\n", "ax.scatter(df[vps[0].name], df[vps[1].name], c=df[f1.name])" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }