{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "---\n",
    "execute:\n",
    "  enabled: false\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-1 fw=all -->\n",
    "\n",
    "# Multi-Fidelity Hyperparameter Optimization\n",
    "\n",
    "Training neural networks can be expensive even on moderate size datasets.\n",
    "Depending on the configuration space (that section),\n",
    "hyperparameter optimization requires tens to hundreds of function evaluations\n",
    "to find a well-performing hyperparameter configuration. As we have seen in\n",
    "that section, we can significantly speed up the overall wall-clock\n",
    "time of HPO by exploiting parallel resources, but this does not reduce the total\n",
    "amount of compute required.\n",
    "\n",
    "In this section, we will show how the evaluation of hyperparameter configurations\n",
    "can be sped up. Methods such as random search allocate the same amount of\n",
    "resources (e.g., number of epochs, training data points) to each hyperparameter\n",
    "evaluation. the figure depicts learning curves of a set of neural\n",
    "networks trained with different hyperparameter configurations. After a few epochs we are\n",
    "already able to visually distinguish between well-performing and suboptimal\n",
    "configurations. However, the learning curves are noisy, and we might still require\n",
    "the full amount of 100 epochs to identify the best performing one.\n",
    "\n",
    "![Learning curves of random hyperparameter configurations](../img/samples_lc.svg)\n",
    "\n",
    "Multi-fidelity hyperparameter optimization allocates more resources\n",
    "to promising configurations and stops evaluations of poorly performing ones early.\n",
    "This speeds up the optimization process, since we can try a larger number of\n",
    "configurations for the same total amount of resources.\n",
    "\n",
    "More formally, we expand our definition in that section,\n",
    "such that our objective function $f(\\mathbf{x}, r)$ gets an additional input\n",
    "$r \\in [r_{\\mathrm{min}}, r_{\\mathrm{max}}]$, specifying the amount of resources that we are\n",
    "willing to spend for the evaluation of configuration $\\mathbf{x}$. We assume that\n",
    "the error $f(\\mathbf{x}, r)$ decreases with $r$, whereas the computational\n",
    "cost $c(\\mathbf{x}, r)$ increases. Typically, $r$ represents the number of\n",
    "epochs for training the neural network, but it could also be the training\n",
    "subset size or the number of cross-validation folds."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "sh-intro-multi-fidelity-hyperparameter-optimization"
   },
   "source": [
    "import tensorflow as tf\n",
    "tf.config.set_visible_devices([], 'GPU')\n",
    "from d2l import jax as d2l\n",
    "import numpy as np\n",
    "from scipy import stats\n",
    "from collections import defaultdict\n",
    "d2l.set_figsize()"
   ],
   "execution_count": 1,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\nI0000 00:00:1784471612.015549   43722 cpu_feature_guard.cc:227] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\nTo enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-2 fw=all -->\n",
    "\n",
    "## Successive Halving\n",
    "\n",
    "One of the simplest ways to adapt random search to the multi-fidelity setting is\n",
    "*successive halving* [@jamieson-aistats16; @karnin-icml13]. The basic\n",
    "idea is to start with $N$ configurations, for example randomly sampled from the\n",
    "configuration space, and to train each of them for $r_{\\mathrm{min}}$ epochs only. We\n",
    "then discard a fraction of the worst performing trials and train the remaining\n",
    "ones for longer. Iterating this process, fewer trials run for longer, until at\n",
    "least one trial reaches $r_{\\mathrm{max}}$ epochs.\n",
    "\n",
    "More formally, consider a minimum budget $r_{\\mathrm{min}}$ (for example 1 epoch), a maximum\n",
    "budget $r_{\\mathrm{max}}$, for example `max_epochs` in our previous example, and a halving\n",
    "constant $\\eta\\in\\{2, 3, \\dots\\}$. For simplicity, assume that\n",
    "$r_{\\mathrm{max}} = r_{\\mathrm{min}} \\eta^K$, with $K \\in \\mathbb{N}$. The number of initial\n",
    "configurations is then $N = \\eta^K$. Let us define the set of rungs\n",
    "$\\mathcal{R} = \\{ r_{\\mathrm{min}}, r_{\\mathrm{min}}\\eta, r_{\\mathrm{min}}\\eta^2, \\dots, r_{\\mathrm{max}} \\}$.\n",
    "\n",
    "One round of successive halving proceeds as follows. We start with running $N$\n",
    "trials until the first rung $r_{\\mathrm{min}}$. Sorting the validation errors, we keep\n",
    "the top $1 / \\eta$ fraction (which amounts to $\\eta^{K-1}$ configurations) and\n",
    "discard all the rest. The surviving trials are trained for the next rung\n",
    "($r_{\\mathrm{min}}\\eta$ epochs), and the process is repeated. At each rung, a\n",
    "$1 / \\eta$ fraction of trials survives and their training continues with a\n",
    "$\\eta$ times larger budget. With this particular choice of $N$, only a single\n",
    "trial will be trained to the full budget $r_{\\mathrm{max}}$. Once such a round of\n",
    "successive halving is done, we start the next one with a new set of initial\n",
    "configurations, iterating until the total budget is spent.\n",
    "\n",
    "![Learning curves of random hyperparameter configurations.](../img/sh.svg)\n",
    "\n",
    "We subclass the `HPOScheduler` base class from that section in order to\n",
    "implement successive halving, allowing for a generic `HPOSearcher` object to\n",
    "sample configurations (which, in our example below, will be a `RandomSearcher`).\n",
    "Additionally, the user has to pass the minimum resource $r_{\\mathrm{min}}$, the maximum\n",
    "resource $r_{\\mathrm{max}}$ and $\\eta$ as input. Inside our scheduler, we maintain a\n",
    "queue of configurations that still need to be evaluated for the current rung\n",
    "$r_i$. We update the queue every time we jump to the next rung."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "sh-intro-successive-halving-1"
   },
   "source": [
    "class SuccessiveHalvingScheduler(d2l.HPOScheduler):\n",
    "    def __init__(self, searcher, eta, r_min, r_max, prefact=1):\n",
    "        self.save_hyperparameters()\n",
    "        # Compute K, which is later used to determine the number of configurations\n",
    "        self.K = int(np.log(r_max / r_min) / np.log(eta))\n",
    "        # Define the rungs\n",
    "        self.rung_levels = [r_min * eta ** k for k in range(self.K + 1)]\n",
    "        if r_max not in self.rung_levels:\n",
    "            # The final rung should be r_max\n",
    "            self.rung_levels.append(r_max)\n",
    "            self.K += 1\n",
    "        # Bookkeeping\n",
    "        self.observed_error_at_rungs = defaultdict(list)\n",
    "        self.all_observed_error_at_rungs = defaultdict(list)\n",
    "        # Our processing queue\n",
    "        self.queue = []"
   ],
   "execution_count": 2,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-3 fw=all -->\n",
    "\n",
    "In the beginning our queue is empty, and we fill it with\n",
    "$n = \\textrm{prefact} \\cdot \\eta^{K}$ configurations, which are first evaluated on\n",
    "the smallest rung $r_{\\mathrm{min}}$. Here, $\\textrm{prefact}$ allows us to reuse our\n",
    "code in a different context. For the purpose of this section, we fix\n",
    "$\\textrm{prefact} = 1$. Every time resources become available and the `HPOTuner`\n",
    "object queries the `suggest` function, we return an element from the queue. Once\n",
    "we finish one round of successive halving, which means that we evaluated all\n",
    "surviving configurations on the highest resource level $r_{\\mathrm{max}}$ and our queue\n",
    "is empty, we start the entire process again with a new, randomly sampled set\n",
    "of configurations."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "sh-intro-successive-halving-2"
   },
   "source": [
    "@d2l.add_to_class(SuccessiveHalvingScheduler)\n",
    "def suggest(self):\n",
    "    if len(self.queue) == 0:\n",
    "        # Start a new round of successive halving\n",
    "        # Number of configurations for the first rung:\n",
    "        n0 = int(self.prefact * self.eta ** self.K)\n",
    "        for _ in range(n0):\n",
    "            config = self.searcher.sample_configuration()\n",
    "            config[\"max_epochs\"] = self.r_min  # Set r = r_min\n",
    "            self.queue.append(config)\n",
    "    # Return an element from the queue\n",
    "    return self.queue.pop()"
   ],
   "execution_count": 3,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-4 fw=all -->\n",
    "\n",
    "When we collected a new data point, we first update the searcher module.\n",
    "Afterwards we check if we have already collected all data points on the current rung.\n",
    "If so, we sort all configurations and push the top $\\frac{1}{\\eta}$\n",
    "configurations into the queue."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "sh-intro-successive-halving-3"
   },
   "source": [
    "@d2l.add_to_class(SuccessiveHalvingScheduler)\n",
    "def update(self, config: dict, error: float, info=None):\n",
    "    ri = int(config[\"max_epochs\"])  # Rung r_i\n",
    "    # Update our searcher, e.g if we use Bayesian optimization later\n",
    "    self.searcher.update(config, error, additional_info=info)\n",
    "    self.all_observed_error_at_rungs[ri].append((config, error))\n",
    "    if ri < self.r_max:\n",
    "        # Bookkeeping\n",
    "        self.observed_error_at_rungs[ri].append((config, error))\n",
    "        # Determine how many configurations should be evaluated on this rung\n",
    "        ki = self.K - self.rung_levels.index(ri)\n",
    "        ni = int(self.prefact * self.eta ** ki)\n",
    "        # If we observed all configuration on this rung r_i, we estimate the\n",
    "        # top 1 / eta configuration, add them to queue and promote them for\n",
    "        # the next rung r_{i+1}\n",
    "        if len(self.observed_error_at_rungs[ri]) >= ni:\n",
    "            kiplus1 = ki - 1\n",
    "            niplus1 = int(self.prefact * self.eta ** kiplus1)\n",
    "            best_performing_configurations = self.get_top_n_configurations(\n",
    "                rung_level=ri, n=niplus1\n",
    "            )\n",
    "            riplus1 = self.rung_levels[self.K - kiplus1]  # r_{i+1}\n",
    "            # Queue may not be empty: insert new entries at the beginning\n",
    "            self.queue = [\n",
    "                dict(config, max_epochs=riplus1)\n",
    "                for config in best_performing_configurations\n",
    "            ] + self.queue\n",
    "            self.observed_error_at_rungs[ri] = []  # Reset"
   ],
   "execution_count": 4,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-5 fw=all -->\n",
    "\n",
    "Configurations are sorted based on their observed performance on the current\n",
    "rung."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "sh-intro-successive-halving-4"
   },
   "source": [
    "\n",
    "@d2l.add_to_class(SuccessiveHalvingScheduler)\n",
    "def get_top_n_configurations(self, rung_level, n):\n",
    "    rung = self.observed_error_at_rungs[rung_level]\n",
    "    if not rung:\n",
    "        return []\n",
    "    sorted_rung = sorted(rung, key=lambda x: x[1])\n",
    "    return [x[0] for x in sorted_rung[:n]]"
   ],
   "execution_count": 5,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-6 fw=all -->\n",
    "\n",
    "Let us see how successive halving is doing on our neural network example. We\n",
    "will use $r_{\\mathrm{min}} = 2$, $\\eta = 2$, $r_{\\mathrm{max}} = 10$, so that rung levels are\n",
    "$2, 4, 8, 10$."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "sh-intro-successive-halving-5"
   },
   "source": [
    "min_number_of_epochs = 2\n",
    "max_number_of_epochs = 10\n",
    "eta = 2\n",
    "num_gpus=1\n",
    "\n",
    "config_space = {\n",
    "    \"learning_rate\": stats.loguniform(1e-2, 1),\n",
    "    \"batch_size\": stats.randint(32, 256),\n",
    "}\n",
    "initial_config = {\n",
    "    \"learning_rate\": 0.1,\n",
    "    \"batch_size\": 128,\n",
    "}"
   ],
   "execution_count": 6,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-7 fw=all -->\n",
    "\n",
    "We just replace the scheduler with our new `SuccessiveHalvingScheduler`."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "sh-intro-successive-halving-6"
   },
   "source": [
    "searcher = d2l.RandomSearcher(config_space, initial_config=initial_config)\n",
    "scheduler = SuccessiveHalvingScheduler(\n",
    "    searcher=searcher,\n",
    "    eta=eta,\n",
    "    r_min=min_number_of_epochs,\n",
    "    r_max=max_number_of_epochs,\n",
    ")\n",
    "tuner = d2l.HPOTuner(\n",
    "    scheduler=scheduler,\n",
    "    objective=d2l.hpo_objective_lenet,\n",
    ")\n",
    "tuner.run(number_of_trials=30)"
   ],
   "execution_count": 7,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "    error = 0.13659995794296265, runtime = 27.789305686950684\n"
     ]
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-8 fw=all -->\n",
    "\n",
    "We can visualize the learning curves of all configurations that we evaluated.\n",
    "Most of the configurations are stopped early and only the better performing\n",
    "configurations survive until $r_{\\mathrm{max}}$. Compare this to vanilla random search,\n",
    "which would allocate $r_{\\mathrm{max}}$ to every configuration."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {
    "id": "sh-intro-successive-halving-7"
   },
   "source": [
    "for rung_index, rung in scheduler.all_observed_error_at_rungs.items():\n",
    "    errors = [xi[1] for xi in rung]\n",
    "    d2l.plt.scatter([rung_index] * len(errors), errors)\n",
    "d2l.plt.xlim(min_number_of_epochs - 0.5, max_number_of_epochs + 0.5)\n",
    "d2l.plt.xticks(\n",
    "    np.arange(min_number_of_epochs, max_number_of_epochs + 1),\n",
    "    np.arange(min_number_of_epochs, max_number_of_epochs + 1)\n",
    ")\n",
    "d2l.plt.ylabel(\"validation error\")\n",
    "d2l.plt.xlabel(\"epochs\")"
   ],
   "execution_count": 8,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "Text(0.5, 0, 'epochs')"
     },
     "metadata": {},
     "execution_count": 8
    },
    {
     "output_type": "display_data",
     "data": {
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"246.28125pt\" height=\"183.35625pt\" viewBox=\"0 0 246.28125 183.35625\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n <metadata>\n  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n   <cc:Work>\n    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n    <dc:date>2026-07-19T14:39:37.522362</dc:date>\n    <dc:format>image/svg+xml</dc:format>\n    <dc:creator>\n     <cc:Agent>\n      <dc:title>Matplotlib v3.10.8, https://matplotlib.org/</dc:title>\n     </cc:Agent>\n    </dc:creator>\n   </cc:Work>\n  </rdf:RDF>\n </metadata>\n <defs>\n  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n </defs>\n <g id=\"figure_1\">\n  <g id=\"patch_1\">\n   <path d=\"M 0 183.35625 \nL 246.28125 183.35625 \nL 246.28125 0 \nL 0 0 \nz\n\" style=\"fill: #ffffff\"/>\n  </g>\n  <g id=\"axes_1\">\n   <g id=\"patch_2\">\n    <path d=\"M 43.78125 145.8 \nL 239.08125 145.8 \nL 239.08125 7.2 \nL 43.78125 7.2 \nz\n\" style=\"fill: #ffffff\"/>\n   </g>\n   <g id=\"PathCollection_1\">\n    <defs>\n     <path id=\"m7c165c2805\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #1f77b4\"/>\n    </defs>\n    <g clip-path=\"url(#p5ba8ad4c16)\">\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"104.245082\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"116.343327\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.516498\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"113.256881\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"93.021615\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"121.641471\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n     <use xlink:href=\"#m7c165c2805\" x=\"54.63125\" y=\"13.5\" style=\"fill: #1f77b4; stroke: #1f77b4\"/>\n    </g>\n   </g>\n   <g id=\"PathCollection_2\">\n    <defs>\n     <path id=\"m7a77c138e3\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #ff7f0e\"/>\n    </defs>\n    <g clip-path=\"url(#p5ba8ad4c16)\">\n     <use xlink:href=\"#m7a77c138e3\" x=\"98.03125\" y=\"100.26736\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7a77c138e3\" x=\"98.03125\" y=\"116.524884\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7a77c138e3\" x=\"98.03125\" y=\"120.585145\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7a77c138e3\" x=\"98.03125\" y=\"127.055149\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7a77c138e3\" x=\"98.03125\" y=\"13.5\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7a77c138e3\" x=\"98.03125\" y=\"34.213905\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7a77c138e3\" x=\"98.03125\" y=\"111.688891\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n     <use xlink:href=\"#m7a77c138e3\" x=\"98.03125\" y=\"131.098903\" style=\"fill: #ff7f0e; stroke: #ff7f0e\"/>\n    </g>\n   </g>\n   <g id=\"PathCollection_3\">\n    <defs>\n     <path id=\"m377861e7af\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #2ca02c\"/>\n    </defs>\n    <g clip-path=\"url(#p5ba8ad4c16)\">\n     <use xlink:href=\"#m377861e7af\" x=\"184.83125\" y=\"128.936729\" style=\"fill: #2ca02c; stroke: #2ca02c\"/>\n     <use xlink:href=\"#m377861e7af\" x=\"184.83125\" y=\"134.300894\" style=\"fill: #2ca02c; stroke: #2ca02c\"/>\n     <use xlink:href=\"#m377861e7af\" x=\"184.83125\" y=\"121.509427\" style=\"fill: #2ca02c; stroke: #2ca02c\"/>\n     <use xlink:href=\"#m377861e7af\" x=\"184.83125\" y=\"136.875685\" style=\"fill: #2ca02c; stroke: #2ca02c\"/>\n    </g>\n   </g>\n   <g id=\"PathCollection_4\">\n    <defs>\n     <path id=\"md9d4e1bfb3\" d=\"M 0 3 \nC 0.795609 3 1.55874 2.683901 2.12132 2.12132 \nC 2.683901 1.55874 3 0.795609 3 0 \nC 3 -0.795609 2.683901 -1.55874 2.12132 -2.12132 \nC 1.55874 -2.683901 0.795609 -3 0 -3 \nC -0.795609 -3 -1.55874 -2.683901 -2.12132 -2.12132 \nC -2.683901 -1.55874 -3 -0.795609 -3 0 \nC -3 0.795609 -2.683901 1.55874 -2.12132 2.12132 \nC -1.55874 2.683901 -0.795609 3 0 3 \nz\n\" style=\"stroke: #d62728\"/>\n    </defs>\n    <g clip-path=\"url(#p5ba8ad4c16)\">\n     <use xlink:href=\"#md9d4e1bfb3\" x=\"228.23125\" y=\"138.839794\" style=\"fill: #d62728; stroke: #d62728\"/>\n     <use xlink:href=\"#md9d4e1bfb3\" x=\"228.23125\" y=\"139.5\" style=\"fill: #d62728; stroke: #d62728\"/>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_1\">\n    <g id=\"xtick_1\">\n     <g id=\"line2d_1\">\n      <defs>\n       <path id=\"mbf74142cc2\" d=\"M 0 0 \nL 0 3.5 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"54.63125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_1\">\n      <!-- 2 -->\n      <g transform=\"translate(51.45 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \nL 3431 531 \nL 3431 0 \nL 469 0 \nL 469 531 \nQ 828 903 1448 1529 \nQ 2069 2156 2228 2338 \nQ 2531 2678 2651 2914 \nQ 2772 3150 2772 3378 \nQ 2772 3750 2511 3984 \nQ 2250 4219 1831 4219 \nQ 1534 4219 1204 4116 \nQ 875 4013 500 3803 \nL 500 4441 \nQ 881 4594 1212 4672 \nQ 1544 4750 1819 4750 \nQ 2544 4750 2975 4387 \nQ 3406 4025 3406 3419 \nQ 3406 3131 3298 2873 \nQ 3191 2616 2906 2266 \nQ 2828 2175 2409 1742 \nQ 1991 1309 1228 531 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-32\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_2\">\n     <g id=\"line2d_2\">\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"76.33125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_2\">\n      <!-- 3 -->\n      <g transform=\"translate(73.15 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \nQ 3050 2419 3304 2112 \nQ 3559 1806 3559 1356 \nQ 3559 666 3084 287 \nQ 2609 -91 1734 -91 \nQ 1441 -91 1130 -33 \nQ 819 25 488 141 \nL 488 750 \nQ 750 597 1062 519 \nQ 1375 441 1716 441 \nQ 2309 441 2620 675 \nQ 2931 909 2931 1356 \nQ 2931 1769 2642 2001 \nQ 2353 2234 1838 2234 \nL 1294 2234 \nL 1294 2753 \nL 1863 2753 \nQ 2328 2753 2575 2939 \nQ 2822 3125 2822 3475 \nQ 2822 3834 2567 4026 \nQ 2313 4219 1838 4219 \nQ 1578 4219 1281 4162 \nQ 984 4106 628 3988 \nL 628 4550 \nQ 988 4650 1302 4700 \nQ 1616 4750 1894 4750 \nQ 2613 4750 3031 4423 \nQ 3450 4097 3450 3541 \nQ 3450 3153 3228 2886 \nQ 3006 2619 2597 2516 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-33\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_3\">\n     <g id=\"line2d_3\">\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"98.03125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_3\">\n      <!-- 4 -->\n      <g transform=\"translate(94.85 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \nL 825 1625 \nL 2419 1625 \nL 2419 4116 \nz\nM 2253 4666 \nL 3047 4666 \nL 3047 1625 \nL 3713 1625 \nL 3713 1100 \nL 3047 1100 \nL 3047 0 \nL 2419 0 \nL 2419 1100 \nL 313 1100 \nL 313 1709 \nL 2253 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-34\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_4\">\n     <g id=\"line2d_4\">\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"119.73125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_4\">\n      <!-- 5 -->\n      <g transform=\"translate(116.55 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \nL 3169 4666 \nL 3169 4134 \nL 1269 4134 \nL 1269 2991 \nQ 1406 3038 1543 3061 \nQ 1681 3084 1819 3084 \nQ 2600 3084 3056 2656 \nQ 3513 2228 3513 1497 \nQ 3513 744 3044 326 \nQ 2575 -91 1722 -91 \nQ 1428 -91 1123 -41 \nQ 819 9 494 109 \nL 494 744 \nQ 775 591 1075 516 \nQ 1375 441 1709 441 \nQ 2250 441 2565 725 \nQ 2881 1009 2881 1497 \nQ 2881 1984 2565 2268 \nQ 2250 2553 1709 2553 \nQ 1456 2553 1204 2497 \nQ 953 2441 691 2322 \nL 691 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-35\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_5\">\n     <g id=\"line2d_5\">\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"141.43125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_5\">\n      <!-- 6 -->\n      <g transform=\"translate(138.25 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \nQ 1688 2584 1439 2293 \nQ 1191 2003 1191 1497 \nQ 1191 994 1439 701 \nQ 1688 409 2113 409 \nQ 2538 409 2786 701 \nQ 3034 994 3034 1497 \nQ 3034 2003 2786 2293 \nQ 2538 2584 2113 2584 \nz\nM 3366 4563 \nL 3366 3988 \nQ 3128 4100 2886 4159 \nQ 2644 4219 2406 4219 \nQ 1781 4219 1451 3797 \nQ 1122 3375 1075 2522 \nQ 1259 2794 1537 2939 \nQ 1816 3084 2150 3084 \nQ 2853 3084 3261 2657 \nQ 3669 2231 3669 1497 \nQ 3669 778 3244 343 \nQ 2819 -91 2113 -91 \nQ 1303 -91 875 529 \nQ 447 1150 447 2328 \nQ 447 3434 972 4092 \nQ 1497 4750 2381 4750 \nQ 2619 4750 2861 4703 \nQ 3103 4656 3366 4563 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-36\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_6\">\n     <g id=\"line2d_6\">\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"163.13125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_6\">\n      <!-- 7 -->\n      <g transform=\"translate(159.95 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-37\" d=\"M 525 4666 \nL 3525 4666 \nL 3525 4397 \nL 1831 0 \nL 1172 0 \nL 2766 4134 \nL 525 4134 \nL 525 4666 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-37\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_7\">\n     <g id=\"line2d_7\">\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"184.83125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_7\">\n      <!-- 8 -->\n      <g transform=\"translate(181.65 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \nQ 1584 2216 1326 1975 \nQ 1069 1734 1069 1313 \nQ 1069 891 1326 650 \nQ 1584 409 2034 409 \nQ 2484 409 2743 651 \nQ 3003 894 3003 1313 \nQ 3003 1734 2745 1975 \nQ 2488 2216 2034 2216 \nz\nM 1403 2484 \nQ 997 2584 770 2862 \nQ 544 3141 544 3541 \nQ 544 4100 942 4425 \nQ 1341 4750 2034 4750 \nQ 2731 4750 3128 4425 \nQ 3525 4100 3525 3541 \nQ 3525 3141 3298 2862 \nQ 3072 2584 2669 2484 \nQ 3125 2378 3379 2068 \nQ 3634 1759 3634 1313 \nQ 3634 634 3220 271 \nQ 2806 -91 2034 -91 \nQ 1263 -91 848 271 \nQ 434 634 434 1313 \nQ 434 1759 690 2068 \nQ 947 2378 1403 2484 \nz\nM 1172 3481 \nQ 1172 3119 1398 2916 \nQ 1625 2713 2034 2713 \nQ 2441 2713 2670 2916 \nQ 2900 3119 2900 3481 \nQ 2900 3844 2670 4047 \nQ 2441 4250 2034 4250 \nQ 1625 4250 1398 4047 \nQ 1172 3844 1172 3481 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-38\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_8\">\n     <g id=\"line2d_8\">\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"206.53125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_8\">\n      <!-- 9 -->\n      <g transform=\"translate(203.35 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-39\" d=\"M 703 97 \nL 703 672 \nQ 941 559 1184 500 \nQ 1428 441 1663 441 \nQ 2288 441 2617 861 \nQ 2947 1281 2994 2138 \nQ 2813 1869 2534 1725 \nQ 2256 1581 1919 1581 \nQ 1219 1581 811 2004 \nQ 403 2428 403 3163 \nQ 403 3881 828 4315 \nQ 1253 4750 1959 4750 \nQ 2769 4750 3195 4129 \nQ 3622 3509 3622 2328 \nQ 3622 1225 3098 567 \nQ 2575 -91 1691 -91 \nQ 1453 -91 1209 -44 \nQ 966 3 703 97 \nz\nM 1959 2075 \nQ 2384 2075 2632 2365 \nQ 2881 2656 2881 3163 \nQ 2881 3666 2632 3958 \nQ 2384 4250 1959 4250 \nQ 1534 4250 1286 3958 \nQ 1038 3666 1038 3163 \nQ 1038 2656 1286 2365 \nQ 1534 2075 1959 2075 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-39\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"xtick_9\">\n     <g id=\"line2d_9\">\n      <g>\n       <use xlink:href=\"#mbf74142cc2\" x=\"228.23125\" y=\"145.8\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_9\">\n      <!-- 10 -->\n      <g transform=\"translate(221.86875 160.398438) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-31\" d=\"M 794 531 \nL 1825 531 \nL 1825 4091 \nL 703 3866 \nL 703 4441 \nL 1819 4666 \nL 2450 4666 \nL 2450 531 \nL 3481 531 \nL 3481 0 \nL 794 0 \nL 794 531 \nz\n\" transform=\"scale(0.015625)\"/>\n        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \nQ 1547 4250 1301 3770 \nQ 1056 3291 1056 2328 \nQ 1056 1369 1301 889 \nQ 1547 409 2034 409 \nQ 2525 409 2770 889 \nQ 3016 1369 3016 2328 \nQ 3016 3291 2770 3770 \nQ 2525 4250 2034 4250 \nz\nM 2034 4750 \nQ 2819 4750 3233 4129 \nQ 3647 3509 3647 2328 \nQ 3647 1150 3233 529 \nQ 2819 -91 2034 -91 \nQ 1250 -91 836 529 \nQ 422 1150 422 2328 \nQ 422 3509 836 4129 \nQ 1250 4750 2034 4750 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-31\"/>\n       <use xlink:href=\"#DejaVuSans-30\" transform=\"translate(63.623047 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_10\">\n     <!-- epochs -->\n     <g transform=\"translate(123.598438 174.076563) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \nL 3597 1613 \nL 953 1613 \nQ 991 1019 1311 708 \nQ 1631 397 2203 397 \nQ 2534 397 2845 478 \nQ 3156 559 3463 722 \nL 3463 178 \nQ 3153 47 2828 -22 \nQ 2503 -91 2169 -91 \nQ 1331 -91 842 396 \nQ 353 884 353 1716 \nQ 353 2575 817 3079 \nQ 1281 3584 2069 3584 \nQ 2775 3584 3186 3129 \nQ 3597 2675 3597 1894 \nz\nM 3022 2063 \nQ 3016 2534 2758 2815 \nQ 2500 3097 2075 3097 \nQ 1594 3097 1305 2825 \nQ 1016 2553 972 2059 \nL 3022 2063 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \nL 1159 -1331 \nL 581 -1331 \nL 581 3500 \nL 1159 3500 \nL 1159 2969 \nQ 1341 3281 1617 3432 \nQ 1894 3584 2278 3584 \nQ 2916 3584 3314 3078 \nQ 3713 2572 3713 1747 \nQ 3713 922 3314 415 \nQ 2916 -91 2278 -91 \nQ 1894 -91 1617 61 \nQ 1341 213 1159 525 \nz\nM 3116 1747 \nQ 3116 2381 2855 2742 \nQ 2594 3103 2138 3103 \nQ 1681 3103 1420 2742 \nQ 1159 2381 1159 1747 \nQ 1159 1113 1420 752 \nQ 1681 391 2138 391 \nQ 2594 391 2855 752 \nQ 3116 1113 3116 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \nQ 1497 3097 1228 2736 \nQ 959 2375 959 1747 \nQ 959 1119 1226 758 \nQ 1494 397 1959 397 \nQ 2419 397 2687 759 \nQ 2956 1122 2956 1747 \nQ 2956 2369 2687 2733 \nQ 2419 3097 1959 3097 \nz\nM 1959 3584 \nQ 2709 3584 3137 3096 \nQ 3566 2609 3566 1747 \nQ 3566 888 3137 398 \nQ 2709 -91 1959 -91 \nQ 1206 -91 779 398 \nQ 353 888 353 1747 \nQ 353 2609 779 3096 \nQ 1206 3584 1959 3584 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-63\" d=\"M 3122 3366 \nL 3122 2828 \nQ 2878 2963 2633 3030 \nQ 2388 3097 2138 3097 \nQ 1578 3097 1268 2742 \nQ 959 2388 959 1747 \nQ 959 1106 1268 751 \nQ 1578 397 2138 397 \nQ 2388 397 2633 464 \nQ 2878 531 3122 666 \nL 3122 134 \nQ 2881 22 2623 -34 \nQ 2366 -91 2075 -91 \nQ 1284 -91 818 406 \nQ 353 903 353 1747 \nQ 353 2603 823 3093 \nQ 1294 3584 2113 3584 \nQ 2378 3584 2631 3529 \nQ 2884 3475 3122 3366 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-68\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 4863 \nL 1159 4863 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-73\" d=\"M 2834 3397 \nL 2834 2853 \nQ 2591 2978 2328 3040 \nQ 2066 3103 1784 3103 \nQ 1356 3103 1142 2972 \nQ 928 2841 928 2578 \nQ 928 2378 1081 2264 \nQ 1234 2150 1697 2047 \nL 1894 2003 \nQ 2506 1872 2764 1633 \nQ 3022 1394 3022 966 \nQ 3022 478 2636 193 \nQ 2250 -91 1575 -91 \nQ 1294 -91 989 -36 \nQ 684 19 347 128 \nL 347 722 \nQ 666 556 975 473 \nQ 1284 391 1588 391 \nQ 1994 391 2212 530 \nQ 2431 669 2431 922 \nQ 2431 1156 2273 1281 \nQ 2116 1406 1581 1522 \nL 1381 1569 \nQ 847 1681 609 1914 \nQ 372 2147 372 2553 \nQ 372 3047 722 3315 \nQ 1072 3584 1716 3584 \nQ 2034 3584 2315 3537 \nQ 2597 3491 2834 3397 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-65\"/>\n      <use xlink:href=\"#DejaVuSans-70\" transform=\"translate(61.523438 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-63\" transform=\"translate(186.181641 0)\"/>\n      <use xlink:href=\"#DejaVuSans-68\" transform=\"translate(241.162109 0)\"/>\n      <use xlink:href=\"#DejaVuSans-73\" transform=\"translate(304.541016 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"matplotlib.axis_2\">\n    <g id=\"ytick_1\">\n     <g id=\"line2d_10\">\n      <defs>\n       <path id=\"m2452abaddb\" d=\"M 0 0 \nL -3.5 0 \n\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </defs>\n      <g>\n       <use xlink:href=\"#m2452abaddb\" x=\"43.78125\" y=\"129.035754\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_11\">\n      <!-- 0.2 -->\n      <g transform=\"translate(20.878125 132.834973) scale(0.1 -0.1)\">\n       <defs>\n        <path id=\"DejaVuSans-2e\" d=\"M 684 794 \nL 1344 794 \nL 1344 0 \nL 684 0 \nL 684 794 \nz\n\" transform=\"scale(0.015625)\"/>\n       </defs>\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-32\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_2\">\n     <g id=\"line2d_11\">\n      <g>\n       <use xlink:href=\"#m2452abaddb\" x=\"43.78125\" y=\"96.025538\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_12\">\n      <!-- 0.4 -->\n      <g transform=\"translate(20.878125 99.824756) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-34\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_3\">\n     <g id=\"line2d_12\">\n      <g>\n       <use xlink:href=\"#m2452abaddb\" x=\"43.78125\" y=\"63.015321\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_13\">\n      <!-- 0.6 -->\n      <g transform=\"translate(20.878125 66.81454) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-36\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"ytick_4\">\n     <g id=\"line2d_13\">\n      <g>\n       <use xlink:href=\"#m2452abaddb\" x=\"43.78125\" y=\"30.005104\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n      </g>\n     </g>\n     <g id=\"text_14\">\n      <!-- 0.8 -->\n      <g transform=\"translate(20.878125 33.804323) scale(0.1 -0.1)\">\n       <use xlink:href=\"#DejaVuSans-30\"/>\n       <use xlink:href=\"#DejaVuSans-2e\" transform=\"translate(63.623047 0)\"/>\n       <use xlink:href=\"#DejaVuSans-38\" transform=\"translate(95.410156 0)\"/>\n      </g>\n     </g>\n    </g>\n    <g id=\"text_15\">\n     <!-- validation error -->\n     <g transform=\"translate(14.798438 114.808594) rotate(-90) scale(0.1 -0.1)\">\n      <defs>\n       <path id=\"DejaVuSans-76\" d=\"M 191 3500 \nL 800 3500 \nL 1894 563 \nL 2988 3500 \nL 3597 3500 \nL 2284 0 \nL 1503 0 \nL 191 3500 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \nQ 1497 1759 1228 1600 \nQ 959 1441 959 1056 \nQ 959 750 1161 570 \nQ 1363 391 1709 391 \nQ 2188 391 2477 730 \nQ 2766 1069 2766 1631 \nL 2766 1759 \nL 2194 1759 \nz\nM 3341 1997 \nL 3341 0 \nL 2766 0 \nL 2766 531 \nQ 2569 213 2275 61 \nQ 1981 -91 1556 -91 \nQ 1019 -91 701 211 \nQ 384 513 384 1019 \nQ 384 1609 779 1909 \nQ 1175 2209 1959 2209 \nL 2766 2209 \nL 2766 2266 \nQ 2766 2663 2505 2880 \nQ 2244 3097 1772 3097 \nQ 1472 3097 1187 3025 \nQ 903 2953 641 2809 \nL 641 3341 \nQ 956 3463 1253 3523 \nQ 1550 3584 1831 3584 \nQ 2591 3584 2966 3190 \nQ 3341 2797 3341 1997 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \nL 1178 4863 \nL 1178 0 \nL 603 0 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \nL 1178 3500 \nL 1178 0 \nL 603 0 \nL 603 3500 \nz\nM 603 4863 \nL 1178 4863 \nL 1178 4134 \nL 603 4134 \nL 603 4863 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-64\" d=\"M 2906 2969 \nL 2906 4863 \nL 3481 4863 \nL 3481 0 \nL 2906 0 \nL 2906 525 \nQ 2725 213 2448 61 \nQ 2172 -91 1784 -91 \nQ 1150 -91 751 415 \nQ 353 922 353 1747 \nQ 353 2572 751 3078 \nQ 1150 3584 1784 3584 \nQ 2172 3584 2448 3432 \nQ 2725 3281 2906 2969 \nz\nM 947 1747 \nQ 947 1113 1208 752 \nQ 1469 391 1925 391 \nQ 2381 391 2643 752 \nQ 2906 1113 2906 1747 \nQ 2906 2381 2643 2742 \nQ 2381 3103 1925 3103 \nQ 1469 3103 1208 2742 \nQ 947 2381 947 1747 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \nL 1172 3500 \nL 2356 3500 \nL 2356 3053 \nL 1172 3053 \nL 1172 1153 \nQ 1172 725 1289 603 \nQ 1406 481 1766 481 \nL 2356 481 \nL 2356 0 \nL 1766 0 \nQ 1100 0 847 248 \nQ 594 497 594 1153 \nL 594 3053 \nL 172 3053 \nL 172 3500 \nL 594 3500 \nL 594 4494 \nL 1172 4494 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-6e\" d=\"M 3513 2113 \nL 3513 0 \nL 2938 0 \nL 2938 2094 \nQ 2938 2591 2744 2837 \nQ 2550 3084 2163 3084 \nQ 1697 3084 1428 2787 \nQ 1159 2491 1159 1978 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1366 3272 1645 3428 \nQ 1925 3584 2291 3584 \nQ 2894 3584 3203 3211 \nQ 3513 2838 3513 2113 \nz\n\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-20\" transform=\"scale(0.015625)\"/>\n       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \nQ 2534 3019 2420 3045 \nQ 2306 3072 2169 3072 \nQ 1681 3072 1420 2755 \nQ 1159 2438 1159 1844 \nL 1159 0 \nL 581 0 \nL 581 3500 \nL 1159 3500 \nL 1159 2956 \nQ 1341 3275 1631 3429 \nQ 1922 3584 2338 3584 \nQ 2397 3584 2469 3576 \nQ 2541 3569 2628 3553 \nL 2631 2963 \nz\n\" transform=\"scale(0.015625)\"/>\n      </defs>\n      <use xlink:href=\"#DejaVuSans-76\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(59.179688 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6c\" transform=\"translate(120.458984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(148.242188 0)\"/>\n      <use xlink:href=\"#DejaVuSans-64\" transform=\"translate(176.025391 0)\"/>\n      <use xlink:href=\"#DejaVuSans-61\" transform=\"translate(239.501953 0)\"/>\n      <use xlink:href=\"#DejaVuSans-74\" transform=\"translate(300.78125 0)\"/>\n      <use xlink:href=\"#DejaVuSans-69\" transform=\"translate(339.990234 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(367.773438 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6e\" transform=\"translate(428.955078 0)\"/>\n      <use xlink:href=\"#DejaVuSans-20\" transform=\"translate(492.333984 0)\"/>\n      <use xlink:href=\"#DejaVuSans-65\" transform=\"translate(524.121094 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(585.644531 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(625.007812 0)\"/>\n      <use xlink:href=\"#DejaVuSans-6f\" transform=\"translate(663.871094 0)\"/>\n      <use xlink:href=\"#DejaVuSans-72\" transform=\"translate(725.052734 0)\"/>\n     </g>\n    </g>\n   </g>\n   <g id=\"patch_3\">\n    <path d=\"M 43.78125 145.8 \nL 43.78125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_4\">\n    <path d=\"M 239.08125 145.8 \nL 239.08125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_5\">\n    <path d=\"M 43.78125 145.8 \nL 239.08125 145.8 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n   <g id=\"patch_6\">\n    <path d=\"M 43.78125 7.2 \nL 239.08125 7.2 \n\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n   </g>\n  </g>\n </g>\n <defs>\n  <clipPath id=\"p5ba8ad4c16\">\n   <rect x=\"43.78125\" y=\"7.2\" width=\"195.3\" height=\"138.6\"/>\n  </clipPath>\n </defs>\n</svg>\n"
     },
     "metadata": {}
    }
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-9 fw=all -->\n",
    "\n",
    "Finally, note some slight complexity in our implementation of\n",
    "`SuccessiveHalvingScheduler`. Say that a worker is free to run a job, and\n",
    "`suggest` is called when the current rung has almost been completely filled, but\n",
    "another worker is still busy with an evaluation. Since we lack the metric value\n",
    "from this worker, we cannot determine the top $1 / \\eta$ fraction to open up\n",
    "the next rung. On the other hand, we want to assign a job to our free worker,\n",
    "so it does not remain idle. Our solution is to start a new round of successive\n",
    "halving and assign our worker to the first trial there. However, once a rung is\n",
    "completed in `update`, we make sure to insert new configurations at the\n",
    "beginning of the queue, so they take precedence over configurations from the\n",
    "next round.\n",
    "\n",
    "## Summary\n",
    "\n",
    "In this section, we introduced the concept of multi-fidelity hyperparameter\n",
    "optimization, where we assume to have access to cheap-to-evaluate approximations\n",
    "of the objective function, such as validation error after a certain number of\n",
    "epochs of training as proxy to validation error after the full number of epochs.\n",
    "Multi-fidelity hyperparameter optimization allows to reduce the overall\n",
    "computation of the HPO instead of just reducing the wall-clock time.\n",
    "\n",
    "We implemented and evaluated successive halving, a simple yet efficient\n",
    "multi-fidelity HPO algorithm."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!-- d2l:prose id=sh-intro-md-10 fw=jax -->\n",
    "\n",
    "[Discussions](https://d2l.discourse.group/t/12094)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "d2l-jax",
   "display_name": "d2l (JAX)",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
