{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "ce759ad2",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "01fa447a",
            "cell_type": "markdown",
            "source": "The following example is a 2-D problem with four local minima: minimizing\nthe Styblinski-Tang function\n(https://en.wikipedia.org/wiki/Test_functions_for_optimization).\n",
            "metadata": {}
        },
        {
            "id": "296f9c15",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.optimize import direct, Bounds\ndef styblinski_tang(pos):\n    x, y = pos\n    return 0.5 * (x**4 - 16*x**2 + 5*x + y**4 - 16*y**2 + 5*y)\nbounds = Bounds([-4., -4.], [4., 4.])\nresult = direct(styblinski_tang, bounds)\nresult.x, result.fun, result.nfev",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([-2.90321597, -2.90321597]), -78.3323279095383, 2011"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "dc9f4afb",
            "cell_type": "markdown",
            "source": "The correct global minimum was found but with a huge number of function\nevaluations (2011). Loosening the termination tolerances `vol_tol` and\n`len_tol` can be used to stop DIRECT earlier.\n",
            "metadata": {}
        },
        {
            "id": "f5f26021",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "result = direct(styblinski_tang, bounds, len_tol=1e-3)\nresult.x, result.fun, result.nfev",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([-2.9044353, -2.9044353]), -78.33230330754142, 207"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}