{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": { "nteract": { "transient": { "deleting": false } } }, "source": [ "# OPT python exercise 3" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { "nteract": { "transient": { "deleting": false } } }, "source": [ "In this exercise we want to the minimize the following cost function $f(x,y)$\n", "\n", "$$ f(x,y) = \\left(x-\\sin{\\left(2.x.y+x \\right)} \\right)^2 + \\left(y-\\cos\\left(x.y\\right)\\right)^2$$\n", "\n", "The variables $x$ and $y$ are bounded and defined by:\n", "\n", "$$ -2\\le x \\le 6$$\n", "$$ -3\\le y \\le 1$$\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { "nteract": { "transient": { "deleting": false } } }, "source": [ "In this exercice you should:\n", "1. Define a function to compute the cost function $f$ to be used within the optimization packages.\n", "2. Plot the cost function $f$ as a filled contour plot alongside a colorbar within the bounds define earlier.\n", "3. Using the starting points $x_0=6.0$ and $y_0=0.0$ and the SLSQP algorithm find the optimal solution of the defined problem.\n", "4. Plot both the initial guess and the optimized value of the parameters onto the countour plot of the cost function.\n", "5. Using the starting points $x_0=6.0$ and $y_0=0.5$ and the SLSQP algorithm find the optimal solution of the defined problem.\n", "6. Plot both the initial guess and the optimized value of the parameters onto the countour plot of the cost function. Can you comment on what you observe?\n", "7. Repeat the optimization problem using the basin hopping algorithm. You can use the two starting points defined in questions 3 and 4. In the basin hopping algorithm you can use 10 iterations.\n", "8. Repeat question 7 using 20 iterations instead of 10.\n", "9. Apply the differential evolution algorithms to find the global minima of the cost function.\n", "10. Discuss the numerical cost (number of iterations and function evaluations) associated with the different algorithms used in 5, 8 and 9. Can you comment on what you observe?\n" ] } ], "metadata": { "kernel_info": { "name": "python3" }, "kernelspec": { "argv": [ "/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9", "-m", "ipykernel_launcher", "-f", "{connection_file}" ], "display_name": "Python 3", "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.9.10" }, "nteract": { "version": "0.28.0" } }, "nbformat": 4, "nbformat_minor": 0 }