{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "expmkveO04pw" }, "source": [ "## Learning Rate Calibration of Gradient Descent in PyBOP\n", "\n", "In this notebook, we calibrate the learning rate for the gradient descent optimiser on a parameter identification problem. The gradient descent learning rate is taken as the `sigma0` value passed to the `pybop.Optimisation` class, or via `problem.sigma0` or `cost.sigma0` if it is passed earlier in the workflow.\n", "\n", "### Setting up the Environment\n", "\n", "Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP from its development branch and upgrade some dependencies:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "execution": { "iopub.execute_input": "2024-04-14T18:57:35.622071Z", "iopub.status.busy": "2024-04-14T18:57:35.621492Z", "iopub.status.idle": "2024-04-14T18:57:40.830883Z", "shell.execute_reply": "2024-04-14T18:57:40.830233Z" }, "id": "X87NUGPW04py", "outputId": "0d785b07-7cff-4aeb-e60a-4ff5a669afbf" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pip in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (24.0)\n", "Requirement already satisfied: ipywidgets in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (8.1.2)\n", "Requirement already satisfied: comm>=0.1.3 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipywidgets) (0.2.1)\n", "Requirement already satisfied: ipython>=6.1.0 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipywidgets) (8.22.1)\n", "Requirement already satisfied: traitlets>=4.3.1 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipywidgets) (5.14.1)\n", "Requirement already satisfied: widgetsnbextension~=4.0.10 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipywidgets) (4.0.10)\n", "Requirement already satisfied: jupyterlab-widgets~=3.0.10 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipywidgets) (3.0.10)\n", "Requirement already satisfied: decorator in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (5.1.1)\n", "Requirement already satisfied: jedi>=0.16 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (0.19.1)\n", "Requirement already satisfied: matplotlib-inline in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (0.1.6)\n", "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (3.0.43)\n", "Requirement already satisfied: pygments>=2.4.0 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (2.17.2)\n", "Requirement already satisfied: stack-data in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (0.6.3)\n", "Requirement already satisfied: pexpect>4.3 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidgets) (4.9.0)\n", "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets) (0.8.3)\n", "Requirement already satisfied: ptyprocess>=0.5 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from pexpect>4.3->ipython>=6.1.0->ipywidgets) (0.7.0)\n", "Requirement already satisfied: wcwidth in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython>=6.1.0->ipywidgets) (0.2.13)\n", "Requirement already satisfied: executing>=1.2.0 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (2.0.1)\n", "Requirement already satisfied: asttokens>=2.1.0 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (2.4.1)\n", "Requirement already satisfied: pure-eval in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (0.2.2)\n", "Requirement already satisfied: six>=1.12.0 in /Users/engs2510/.pyenv/versions/3.11.7/envs/pybop/lib/python3.11/site-packages (from asttokens>=2.1.0->stack-data->ipython>=6.1.0->ipywidgets) (1.16.0)\n", "Note: you may need to restart the kernel to use updated packages.\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "%pip install --upgrade pip ipywidgets\n", "%pip install pybop -q" ] }, { "cell_type": "markdown", "metadata": { "id": "jAvD5fk104p0" }, "source": [ "### Importing Libraries\n", "\n", "With the environment set up, we can now import PyBOP alongside other libraries we will need:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:40.833454Z", "iopub.status.busy": "2024-04-14T18:57:40.833211Z", "iopub.status.idle": "2024-04-14T18:57:46.230918Z", "shell.execute_reply": "2024-04-14T18:57:46.230420Z" }, "id": "SQdt4brD04p1" }, "outputs": [], "source": [ "import numpy as np\n", "\n", "import pybop" ] }, { "cell_type": "markdown", "metadata": { "id": "5XU-dMtU04p2" }, "source": [ "## Generating Synthetic Data\n", "\n", "To demonstrate parameter estimation, we first need some data. We will generate synthetic data using a forward model, which requires defining a parameter set and the model itself.\n", "\n", "### Defining Parameters and Model\n", "\n", "We start by creating an example parameter set, constructing the single-particle model (SPM) and generating the synthetic data." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:46.247936Z", "iopub.status.busy": "2024-04-14T18:57:46.247644Z", "iopub.status.idle": "2024-04-14T18:57:46.446493Z", "shell.execute_reply": "2024-04-14T18:57:46.446198Z" } }, "outputs": [], "source": [ "parameter_set = pybop.ParameterSet.pybamm(\"Chen2020\")\n", "model = pybop.lithium_ion.SPM(parameter_set=parameter_set)\n", "t_eval = np.arange(0, 900, 1)\n", "values = model.predict(t_eval=t_eval)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Adding Noise to Voltage Data\n", "\n", "To make the parameter estimation more realistic, we add Gaussian noise to the data." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:46.448424Z", "iopub.status.busy": "2024-04-14T18:57:46.448310Z", "iopub.status.idle": "2024-04-14T18:57:46.463231Z", "shell.execute_reply": "2024-04-14T18:57:46.462472Z" } }, "outputs": [], "source": [ "sigma = 0.001\n", "corrupt_values = values[\"Voltage [V]\"].data + np.random.normal(0, sigma, len(t_eval))" ] }, { "cell_type": "markdown", "metadata": { "id": "X8-tubYY04p_" }, "source": [ "## Identifying the Parameters" ] }, { "cell_type": "markdown", "metadata": { "id": "PQqhvSZN04p_" }, "source": [ "We will now set up the parameter estimation process by defining the datasets for optimisation and selecting the model parameters we wish to estimate." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating a Dataset\n", "\n", "The dataset for optimisation is composed of time, current, and the noisy voltage data:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:46.466648Z", "iopub.status.busy": "2024-04-14T18:57:46.466165Z", "iopub.status.idle": "2024-04-14T18:57:46.479234Z", "shell.execute_reply": "2024-04-14T18:57:46.478887Z" }, "id": "zuvGHWID04p_" }, "outputs": [], "source": [ "dataset = pybop.Dataset(\n", " {\n", " \"Time [s]\": t_eval,\n", " \"Current function [A]\": values[\"Current [A]\"].data,\n", " \"Voltage [V]\": corrupt_values,\n", " }\n", ")" ] }, { "cell_type": "markdown", "metadata": { "id": "ffS3CF_704qA" }, "source": [ "### Defining Parameters to Estimate\n", "\n", "We select the parameters for estimation and set up their prior distributions and bounds:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:46.480892Z", "iopub.status.busy": "2024-04-14T18:57:46.480800Z", "iopub.status.idle": "2024-04-14T18:57:46.482933Z", "shell.execute_reply": "2024-04-14T18:57:46.482614Z" }, "id": "WPCybXIJ04qA" }, "outputs": [], "source": [ "parameters = [\n", " pybop.Parameter(\n", " \"Negative electrode active material volume fraction\",\n", " prior=pybop.Gaussian(0.7, 0.025),\n", " bounds=[0.6, 0.9],\n", " ),\n", " pybop.Parameter(\n", " \"Positive electrode active material volume fraction\",\n", " prior=pybop.Gaussian(0.6, 0.025),\n", " bounds=[0.5, 0.8],\n", " ),\n", "]" ] }, { "cell_type": "markdown", "metadata": { "id": "n4OHa-aF04qA" }, "source": [ "### Setting up the Optimisation Problem with Default sigma\n", "\n", "With the datasets and parameters defined, we can set up the optimisation problem, its cost function, and the optimiser. For gradient descent, the `sigma0` value corresponds to the learning rate. The default value for this parameter is `sigma0=0.1`." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:46.484362Z", "iopub.status.busy": "2024-04-14T18:57:46.484269Z", "iopub.status.idle": "2024-04-14T18:57:46.549050Z", "shell.execute_reply": "2024-04-14T18:57:46.548811Z" }, "id": "etMzRtx404qA" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NOTE: Boundaries ignored by Gradient Descent\n" ] } ], "source": [ "problem = pybop.FittingProblem(model, parameters, dataset)\n", "cost = pybop.SumSquaredError(problem)\n", "optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent)\n", "optim.set_max_iterations(100)" ] }, { "cell_type": "markdown", "metadata": { "id": "caprp-bV04qB" }, "source": [ "### Running the Optimisation\n", "\n", "We proceed to run the optimisation algorithm to estimate the parameters with the default learning rate." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:46.550494Z", "iopub.status.busy": "2024-04-14T18:57:46.550406Z", "iopub.status.idle": "2024-04-14T18:57:47.825440Z", "shell.execute_reply": "2024-04-14T18:57:47.824752Z" }, "id": "-9OVt0EQ04qB" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error: Events ['Maximum voltage [V]'] are non-positive at initial conditions\n", "Error: Events ['Maximum voltage [V]'] are non-positive at initial conditions\n", "Error: Events ['Maximum voltage [V]'] are non-positive at initial conditions\n", "Error: Events ['Maximum voltage [V]'] are non-positive at initial conditions\n", "Error: Events ['Maximum voltage [V]'] are non-positive at initial conditions\n", "Error: Events ['Maximum voltage [V]'] are non-positive at initial conditions\n", "Error: Events ['Maximum voltage [V]'] are non-positive at initial conditions\n", "Error: Events ['Maximum voltage [V]'] are non-positive at initial conditions\n" ] } ], "source": [ "x, final_cost = optim.run()" ] }, { "cell_type": "markdown", "metadata": { "id": "-4pZsDmS04qC" }, "source": [ "### Viewing the Estimated Parameters\n", "\n", "After the optimisation, we can examine the estimated parameter values. In this case, the optimiser misses the optimal solution by a large amount." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "execution": { "iopub.execute_input": "2024-04-14T18:57:47.828249Z", "iopub.status.busy": "2024-04-14T18:57:47.827941Z", "iopub.status.idle": "2024-04-14T18:57:47.839261Z", "shell.execute_reply": "2024-04-14T18:57:47.838577Z" }, "id": "Hgz8SV4i04qC", "outputId": "e1e42ae7-5075-4c47-dd68-1b22ecc170f6" }, "outputs": [ { "data": { "text/plain": [ "array([0.71033729, 0.55945988])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x # This will output the estimated parameters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's plot the time-series prediction for the given solution. As we suspected, the optimiser found a very poor solution. " ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:47.841607Z", "iopub.status.busy": "2024-04-14T18:57:47.841388Z", "iopub.status.idle": "2024-04-14T18:57:50.112707Z", "shell.execute_reply": "2024-04-14T18:57:50.111902Z" } }, "outputs": [ { "data": { "image/svg+xml": [ "02004006008003.753.83.853.93.9544.05ReferenceModelOptimised ComparisonTime / sVoltage / V" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "pybop.quick_plot(problem, parameter_values=x, title=\"Optimised Comparison\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calibrating the Learning Rate \n", "\n", "Now that we've seen how poor the default `sigma0` value is for this optimisation problem, let's calibrate this value to find the optimal solution in the lowest number of iterations." ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:57:50.118807Z", "iopub.status.busy": "2024-04-14T18:57:50.118279Z", "iopub.status.idle": "2024-04-14T18:59:24.213183Z", "shell.execute_reply": "2024-04-14T18:59:24.212776Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.001\n", "NOTE: Boundaries ignored by Gradient Descent\n", "0.0045\n", "NOTE: Boundaries ignored by Gradient Descent\n", "0.008\n", "NOTE: Boundaries ignored by Gradient Descent\n", "0.0115\n", "NOTE: Boundaries ignored by Gradient Descent\n", "0.015\n", "NOTE: Boundaries ignored by Gradient Descent\n" ] } ], "source": [ "sigmas = np.linspace(\n", " 0.001, 0.015, 5\n", ") # Change this to a smaller range for a quicker run\n", "xs = []\n", "optims = []\n", "for sigma in sigmas:\n", " print(sigma)\n", " problem = pybop.FittingProblem(model, parameters, dataset)\n", " cost = pybop.SumSquaredError(problem)\n", " optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent, sigma0=sigma)\n", " optim.set_max_iterations(100)\n", " x, final_cost = optim.run()\n", " optims.append(optim)\n", " xs.append(x)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:59:24.215261Z", "iopub.status.busy": "2024-04-14T18:59:24.215124Z", "iopub.status.idle": "2024-04-14T18:59:24.217691Z", "shell.execute_reply": "2024-04-14T18:59:24.217462Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "| Sigma: 0.001 | Num Iterations: 47 | Best Cost: 0.0008637695988057631 | Results: [0.75766989 0.66379605] |\n", "| Sigma: 0.0045 | Num Iterations: 100 | Best Cost: 0.0011612381826846523 | Results: [0.72722617 0.66903422] |\n", "| Sigma: 0.008 | Num Iterations: 100 | Best Cost: 0.0012674705312650204 | Results: [0.72350919 0.66970245] |\n", "| Sigma: 0.0115 | Num Iterations: 100 | Best Cost: 0.001026517347060025 | Results: [0.73304834 0.66800235] |\n", "| Sigma: 0.015 | Num Iterations: 74 | Best Cost: 0.36327076213686793 | Results: [0.62594548 0.62583821] |\n" ] } ], "source": [ "for optim, sigma in zip(optims, sigmas):\n", " print(\n", " f\"| Sigma: {sigma} | Num Iterations: {optim._iterations} | Best Cost: {optim.optimiser.f_best()} | Results: {optim.optimiser.x_best()} |\"\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Perhaps a better way to view this information is to plot the optimiser convergences," ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:59:24.219013Z", "iopub.status.busy": "2024-04-14T18:59:24.218873Z", "iopub.status.idle": "2024-04-14T18:59:34.711291Z", "shell.execute_reply": "2024-04-14T18:59:34.710975Z" } }, "outputs": [ { "data": { "image/svg+xml": [ "1020304000.20.40.60.8Sigma: 0.001IterationCost" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "0102030400.7460.7480.750.7520.7540.7560.7580102030400.580.60.620.640.66Negative electrode active material volume fractionPositive electrode active material volume fractionParameter ConvergenceFunction CallFunction CallNegative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "2040608010000.020.040.060.080.10.120.140.16Sigma: 0.0045IterationCost" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "0204060800.7050.710.7150.720.7250204060800.630.6350.640.6450.650.6550.660.6650.67Negative electrode active material volume fractionPositive electrode active material volume fractionParameter ConvergenceFunction CallFunction CallNegative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "2040608010000.20.40.60.811.2Sigma: 0.008IterationCost" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "0204060800.680.690.70.710.720204060800.60.650.70.75Negative electrode active material volume fractionPositive electrode active material volume fractionParameter ConvergenceFunction CallFunction CallNegative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "2040608010000.511.52Sigma: 0.0115IterationCost" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "0204060800.690.70.710.720.730.740204060800.550.60.650.70.750.80.850.9Negative electrode active material volume fractionPositive electrode active material volume fractionParameter ConvergenceFunction CallFunction CallNegative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "102030405060700.40.50.60.70.80.911.11.2Sigma: 0.015IterationCost" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "02040600.640.660.680.70.7202040600.60.650.70.750.8Negative electrode active material volume fractionPositive electrode active material volume fractionParameter ConvergenceFunction CallFunction CallNegative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for optim, sigma in zip(optims, sigmas):\n", " pybop.plot_convergence(optim, title=f\"Sigma: {sigma}\")\n", " pybop.plot_parameters(optim)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Cost Landscapes\n", "\n", "Finally, we can visualise the cost landscape and the path taken by the optimiser:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:59:34.712645Z", "iopub.status.busy": "2024-04-14T18:59:34.712544Z", "iopub.status.idle": "2024-04-14T18:59:54.695647Z", "shell.execute_reply": "2024-04-14T18:59:54.691926Z" } }, "outputs": [ { "data": { "image/svg+xml": [ "0.60.650.70.750.80.850.90.50.550.60.650.70.750.812345Sigma: 0.001Negative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "0.60.650.70.750.80.850.90.50.550.60.650.70.750.812345Sigma: 0.0045Negative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "0.60.650.70.750.80.850.90.50.550.60.650.70.750.812345Sigma: 0.008Negative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "0.60.650.70.750.80.850.90.50.550.60.650.70.750.812345Sigma: 0.0115Negative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "0.60.650.70.750.80.850.90.50.550.60.650.70.750.812345Sigma: 0.015Negative electrode active material volume fractionPositive electrode active material volume fraction" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Plot the cost landscape with optimisation path and updated bounds\n", "bounds = np.array([[0.6, 0.9], [0.5, 0.8]])\n", "for optim, sigma in zip(optims, sigmas):\n", " pybop.plot2d(optim, bounds=bounds, steps=15, title=f\"Sigma: {sigma}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Updating the Learning Rate\n", "\n", "Let's take `sigma0 = 0.0115` as the best learning rate for this problem and look at the time-series trajectories." ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2024-04-14T18:59:54.698068Z", "iopub.status.busy": "2024-04-14T18:59:54.697929Z", "iopub.status.idle": "2024-04-14T19:00:24.667004Z", "shell.execute_reply": "2024-04-14T19:00:24.666609Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NOTE: Boundaries ignored by Gradient Descent\n" ] }, { "data": { "image/svg+xml": [ "02004006008003.83.853.93.9544.05ReferenceModelOptimised ComparisonTime / sVoltage / V" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent, sigma0=0.0115)\n", "x, final_cost = optim.run()\n", "pybop.quick_plot(problem, parameter_values=x, title=\"Optimised Comparison\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Conclusion\n", "\n", "This notebook covers how to calibrate the learning rate for the gradient descent optimiser. This provides an introduction into hyper-parameter tuning that will be discussed in further notebooks." ] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.7" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "06f2374f91c8455bb63252092512f2ed": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "423bffea3a1c42b49a9ad71218e5811b": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "56ff19291e464d63b23e63b8e2ac9ea3": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "SliderStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "SliderStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "StyleView", "description_width": "", "handle_color": null } }, "646a8670cb204a31bb56bc2380898093": { "model_module": "@jupyter-widgets/base", "model_module_version": "2.0.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "2.0.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "2.0.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border_bottom": null, "border_left": null, "border_right": null, "border_top": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "7d46516469314b88be3500e2afcafcf6": { "model_module": "@jupyter-widgets/output", "model_module_version": "1.0.0", "model_name": "OutputModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/output", "_model_module_version": "1.0.0", "_model_name": "OutputModel", "_view_count": null, "_view_module": "@jupyter-widgets/output", "_view_module_version": "1.0.0", "_view_name": "OutputView", "layout": "IPY_MODEL_646a8670cb204a31bb56bc2380898093", "msg_id": "", "outputs": [], "tabbable": null, "tooltip": null } }, "8d003c14da5f4fa68284b28c15cee6e6": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "VBoxModel", "state": { "_dom_classes": [ "widget-interact" ], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "VBoxModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "VBoxView", "box_style": "", "children": [ "IPY_MODEL_aef2fa7adcc14ad0854b73d5910ae3b4", "IPY_MODEL_7d46516469314b88be3500e2afcafcf6" ], "layout": "IPY_MODEL_423bffea3a1c42b49a9ad71218e5811b", "tabbable": null, "tooltip": null } }, "aef2fa7adcc14ad0854b73d5910ae3b4": { "model_module": "@jupyter-widgets/controls", "model_module_version": "2.0.0", "model_name": "FloatSliderModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "2.0.0", "_model_name": "FloatSliderModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "2.0.0", "_view_name": "FloatSliderView", "behavior": "drag-tap", "continuous_update": true, "description": "t", "description_allow_html": false, "disabled": false, "layout": "IPY_MODEL_06f2374f91c8455bb63252092512f2ed", "max": 1.1333333333333333, "min": 0, "orientation": "horizontal", "readout": true, "readout_format": ".2f", "step": 0.011333333333333332, "style": "IPY_MODEL_56ff19291e464d63b23e63b8e2ac9ea3", "tabbable": null, "tooltip": null, "value": 0 } } } } }, "nbformat": 4, "nbformat_minor": 4 }