{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "#"
      ],
      "id": "b59df579-a5a1-49a9-b0cc-dd3de2945625"
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {},
      "outputs": [],
      "source": [
        "import polars as pl\n",
        "import scipy as sp\n",
        "import numpy as np\n",
        "import matplotlib.pyplot as plt"
      ],
      "id": "9a8b25ec-4384-4f57-a9c9-c1e445e06d58"
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {},
      "outputs": [],
      "source": [
        "# dataset on penguins\n",
        "# copy from lecture notes: ci example\n",
        "url = \"https://roualdes.sfo3.digitaloceanspaces.com/data/penguins.csv\"\n",
        "df = pl.read_csv(url, null_values = [\"NA\"]) # this is the trick"
      ],
      "id": "93eb857d-6452-464e-9990-49dd2d6868e7"
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.33430232558139533)"
            ]
          }
        }
      ],
      "source": [
        "x = df[\"body_mass_g\"].to_numpy() > 4500 # Bernoulli data\n",
        "np.mean(x)"
      ],
      "id": "634420bd-9696-4246-b377-8b563b25fdfc"
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {},
      "outputs": [],
      "source": [
        "def ll_bernoulli(theta, data):\n",
        "    p = theta\n",
        "    x = data\n",
        "    return -np.sum(sp.stats.binom(1, p).logpmf(x))"
      ],
      "id": "1c834f27-753e-4878-9025-52357680ff27"
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {},
      "outputs": [],
      "source": [
        "p = np.linspace(1e-5, 1-1e-5, np.size(x))\n",
        "fp = [ll_bernoulli(pn, x) for pn in p] # list comprehension"
      ],
      "id": "86a3964e-9692-42a2-a611-dfd7aeb24667"
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "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NG+fft09dVXBx/z+/2SJLvdrsLCQg0YMKB9izahSH6fs7KyFBcXJ5vNFnxs2LBh8ng8qq+vl8Ph\naNeazSiS8/xf//VfmjVrlm6//XZJ0qhRo1RVVaU777xTP//5z2W18nd8WzjdZ6HL5WqX3heJHpgQ\nDodD48aN04oVK4KP+f1+rVixQrm5uaf8mdzc3JD2kpSfn3/a9mgSybmWpPnz5+uxxx7T0qVLdf75\n53dEqaYW7nkeOnSotm7dqoKCguDtmmuu0eWXX66CggLl5OR0ZPmmEcnv8yWXXKLdu3cHA6IkffHF\nF8rKyiK8nEYk57m6uvprISUQGg22AmwzUfksbLfhwSb12muvGU6n01iwYIGxfft248477zRSUlIM\nj8djGIZhzJo1y/jpT38abL9u3TrDbrcbTz75pLFjxw7j4YcfZhp1K4V7rp944gnD4XAYb731lnHo\n0KHgraKiIlpvwRTCPc9fxSyk1gn3PBcXFxvJycnGnDlzjMLCQmPx4sVGenq68fjjj0frLZhCuOf5\n4YcfNpKTk42//e1vxt69e41ly5YZAwYMMK6//vpovQVTqKioMDZv3mxs3rzZkGQ8/fTTxubNm40v\nv/zSMAzD+OlPf2rMmjUr2D4wjfree+81duzYYTz33HNMo46GZ5991ujTp4/hcDiMCy+80NiwYUPw\n2KWXXmrceuutIe3feOMNY/DgwYbD4TBGjBhhLFmypIMrNq9wznXfvn0NSV+7Pfzwwx1fuMmE+zvd\nEgGm9cI9zx9++KExfvx4w+l0Gv379zf++7//22hsbOzgqs0nnPPc0NBgPPLII8aAAQOM+Ph4Iycn\nx/jRj35knDhxouMLN5EPPvjglP/eBs7trbfealx66aVf+5lzzz3XcDgcRv/+/Y2XX365XWu0GAZ9\naAAAwFwYAwMAAEyHAAMAAEyHAAMAAEyHAAMAAEyHAAMAAEyHAAMAAEyHAAMAAEyHAAMAAEyHAAMA\nAEyHAAMAAEyHAAMAAEyHAAMAAEzn/wEJC8Vev3Fx0QAAAABJRU5ErkJggg==\n"
          }
        }
      ],
      "source": [
        "plt.plot(p, fp)"
      ],
      "id": "405c940c-5958-4f5f-9c64-de074f84d1dc"
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "np.float64(0.3352802623906706)"
            ]
          }
        }
      ],
      "source": [
        "idx = np.argmin(fp)\n",
        "p[idx] # a grid guesss"
      ],
      "id": "b0c73690-f6e7-4b6b-8c5c-055b6558b7f6"
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/plain": [
              "  message: CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL\n",
              "  success: True\n",
              "   status: 0\n",
              "      fun: 219.1911965607544\n",
              "        x: [ 3.343e-01]\n",
              "      nit: 4\n",
              "      jac: [ 2.842e-06]\n",
              "     nfev: 14\n",
              "     njev: 7\n",
              " hess_inv: <1x1 LbfgsInvHessProduct with dtype=float64>"
            ]
          }
        }
      ],
      "source": [
        "init = sp.stats.uniform().rvs()\n",
        "sp.optimize.minimize(ll_bernoulli, init, args = (x,),\n",
        "                     method = \"L-BFGS-B\", bounds = [(1e-5, 1-1e-5),])"
      ],
      "id": "e481919f-eccf-4af8-a302-c2fbef19c9d3"
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {},
      "outputs": [
        {
          "output_type": "display_data",
          "metadata": {},
          "data": {
            "text/html": [
              "<pre><span class=\"ansi-red-fg\">Signature:</span>\n",
              "sp<span class=\"ansi-blue-fg\">.</span>optimize<span class=\"ansi-blue-fg\">.</span>minimize<span class=\"ansi-blue-fg\">(</span>\n",
              "    fun<span class=\"ansi-blue-fg\">,</span>\n",
              "    x0<span class=\"ansi-blue-fg\">,</span>\n",
              "    args<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-blue-fg\">(</span><span class=\"ansi-blue-fg\">)</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    method<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-green-fg\">None</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    jac<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-green-fg\">None</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    hess<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-green-fg\">None</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    hessp<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-green-fg\">None</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    bounds<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-green-fg\">None</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    constraints<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-blue-fg\">(</span><span class=\"ansi-blue-fg\">)</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    tol<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-green-fg\">None</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    callback<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-green-fg\">None</span><span class=\"ansi-blue-fg\">,</span>\n",
              "    options<span class=\"ansi-blue-fg\">=</span><span class=\"ansi-green-fg\">None</span><span class=\"ansi-blue-fg\">,</span>\n",
              "<span class=\"ansi-blue-fg\">)</span>\n",
              "<span class=\"ansi-red-fg\">Docstring:</span>\n",
              "Minimization of scalar function of one or more variables.\n",
              "Parameters\n",
              "----------\n",
              "fun : callable\n",
              "    The objective function to be minimized::\n",
              "        fun(x, *args) -&gt; float\n",
              "    where ``x`` is a 1-D array with shape (n,) and ``args``\n",
              "    is a tuple of the fixed parameters needed to completely\n",
              "    specify the function.\n",
              "    Suppose the callable has signature ``f0(x, *my_args, **my_kwargs)``, where\n",
              "    ``my_args`` and ``my_kwargs`` are required positional and keyword arguments.\n",
              "    Rather than passing ``f0`` as the callable, wrap it to accept\n",
              "    only ``x``; e.g., pass ``fun=lambda x: f0(x, *my_args, **my_kwargs)`` as the\n",
              "    callable, where ``my_args`` (tuple) and ``my_kwargs`` (dict) have been\n",
              "    gathered before invoking this function.\n",
              "x0 : ndarray, shape (n,)\n",
              "    Initial guess. Array of real elements of size (n,),\n",
              "    where ``n`` is the number of independent variables.\n",
              "args : tuple, optional\n",
              "    Extra arguments passed to the objective function and its\n",
              "    derivatives (`fun`, `jac` and `hess` functions).\n",
              "method : str or callable, optional\n",
              "    Type of solver.  Should be one of\n",
              "    - 'Nelder-Mead' :ref:`(see here) &lt;optimize.minimize-neldermead&gt;`\n",
              "    - 'Powell'      :ref:`(see here) &lt;optimize.minimize-powell&gt;`\n",
              "    - 'CG'          :ref:`(see here) &lt;optimize.minimize-cg&gt;`\n",
              "    - 'BFGS'        :ref:`(see here) &lt;optimize.minimize-bfgs&gt;`\n",
              "    - 'Newton-CG'   :ref:`(see here) &lt;optimize.minimize-newtoncg&gt;`\n",
              "    - 'L-BFGS-B'    :ref:`(see here) &lt;optimize.minimize-lbfgsb&gt;`\n",
              "    - 'TNC'         :ref:`(see here) &lt;optimize.minimize-tnc&gt;`\n",
              "    - 'COBYLA'      :ref:`(see here) &lt;optimize.minimize-cobyla&gt;`\n",
              "    - 'COBYQA'      :ref:`(see here) &lt;optimize.minimize-cobyqa&gt;`\n",
              "    - 'SLSQP'       :ref:`(see here) &lt;optimize.minimize-slsqp&gt;`\n",
              "    - 'trust-constr':ref:`(see here) &lt;optimize.minimize-trustconstr&gt;`\n",
              "    - 'dogleg'      :ref:`(see here) &lt;optimize.minimize-dogleg&gt;`\n",
              "    - 'trust-ncg'   :ref:`(see here) &lt;optimize.minimize-trustncg&gt;`\n",
              "    - 'trust-exact' :ref:`(see here) &lt;optimize.minimize-trustexact&gt;`\n",
              "    - 'trust-krylov' :ref:`(see here) &lt;optimize.minimize-trustkrylov&gt;`\n",
              "    - custom - a callable object, see below for description.\n",
              "    If not given, chosen to be one of ``BFGS``, ``L-BFGS-B``, ``SLSQP``,\n",
              "    depending on whether or not the problem has constraints or bounds.\n",
              "jac : {callable,  '2-point', '3-point', 'cs', bool}, optional\n",
              "    Method for computing the gradient vector. Only for CG, BFGS,\n",
              "    Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov,\n",
              "    trust-exact and trust-constr.\n",
              "    If it is a callable, it should be a function that returns the gradient\n",
              "    vector::\n",
              "        jac(x, *args) -&gt; array_like, shape (n,)\n",
              "    where ``x`` is an array with shape (n,) and ``args`` is a tuple with\n",
              "    the fixed parameters. If `jac` is a Boolean and is True, `fun` is\n",
              "    assumed to return a tuple ``(f, g)`` containing the objective\n",
              "    function and the gradient.\n",
              "    Methods 'Newton-CG', 'trust-ncg', 'dogleg', 'trust-exact', and\n",
              "    'trust-krylov' require that either a callable be supplied, or that\n",
              "    `fun` return the objective and gradient.\n",
              "    If None or False, the gradient will be estimated using 2-point finite\n",
              "    difference estimation with an absolute step size.\n",
              "    Alternatively, the keywords  {'2-point', '3-point', 'cs'} can be used\n",
              "    to select a finite difference scheme for numerical estimation of the\n",
              "    gradient with a relative step size. These finite difference schemes\n",
              "    obey any specified `bounds`.\n",
              "hess : {callable, '2-point', '3-point', 'cs', HessianUpdateStrategy}, optional\n",
              "    Method for computing the Hessian matrix. Only for Newton-CG, dogleg,\n",
              "    trust-ncg, trust-krylov, trust-exact and trust-constr.\n",
              "    If it is callable, it should return the Hessian matrix::\n",
              "        hess(x, *args) -&gt; {LinearOperator, spmatrix, array}, (n, n)\n",
              "    where ``x`` is a (n,) ndarray and ``args`` is a tuple with the fixed\n",
              "    parameters.\n",
              "    The keywords {'2-point', '3-point', 'cs'} can also be used to select\n",
              "    a finite difference scheme for numerical estimation of the hessian.\n",
              "    Alternatively, objects implementing the `HessianUpdateStrategy`\n",
              "    interface can be used to approximate the Hessian. Available\n",
              "    quasi-Newton methods implementing this interface are:\n",
              "    - `BFGS`\n",
              "    - `SR1`\n",
              "    Not all of the options are available for each of the methods; for\n",
              "    availability refer to the notes.\n",
              "hessp : callable, optional\n",
              "    Hessian of objective function times an arbitrary vector p. Only for\n",
              "    Newton-CG, trust-ncg, trust-krylov, trust-constr.\n",
              "    Only one of `hessp` or `hess` needs to be given. If `hess` is\n",
              "    provided, then `hessp` will be ignored. `hessp` must compute the\n",
              "    Hessian times an arbitrary vector::\n",
              "        hessp(x, p, *args) -&gt;  ndarray shape (n,)\n",
              "    where ``x`` is a (n,) ndarray, ``p`` is an arbitrary vector with\n",
              "    dimension (n,) and ``args`` is a tuple with the fixed\n",
              "    parameters.\n",
              "bounds : sequence or `Bounds`, optional\n",
              "    Bounds on variables for Nelder-Mead, L-BFGS-B, TNC, SLSQP, Powell,\n",
              "    trust-constr, COBYLA, and COBYQA methods. There are two ways to specify\n",
              "    the bounds:\n",
              "    1. Instance of `Bounds` class.\n",
              "    2. Sequence of ``(min, max)`` pairs for each element in `x`. None\n",
              "       is used to specify no bound.\n",
              "constraints : {Constraint, dict} or List of {Constraint, dict}, optional\n",
              "    Constraints definition. Only for COBYLA, COBYQA, SLSQP and trust-constr.\n",
              "    Constraints for 'trust-constr', 'cobyqa', and 'cobyla' are defined as a single\n",
              "    object or a list of objects specifying constraints to the optimization problem.\n",
              "    Available constraints are:\n",
              "    - `LinearConstraint`\n",
              "    - `NonlinearConstraint`\n",
              "    Constraints for COBYLA, SLSQP are defined as a list of dictionaries.\n",
              "    Each dictionary with fields:\n",
              "    type : str\n",
              "        Constraint type: 'eq' for equality, 'ineq' for inequality.\n",
              "    fun : callable\n",
              "        The function defining the constraint.\n",
              "    jac : callable, optional\n",
              "        The Jacobian of `fun` (only for SLSQP).\n",
              "    args : sequence, optional\n",
              "        Extra arguments to be passed to the function and Jacobian.\n",
              "    Equality constraint means that the constraint function result is to\n",
              "    be zero whereas inequality means that it is to be non-negative.\n",
              "tol : float, optional\n",
              "    Tolerance for termination. When `tol` is specified, the selected\n",
              "    minimization algorithm sets some relevant solver-specific tolerance(s)\n",
              "    equal to `tol`. For detailed control, use solver-specific\n",
              "    options.\n",
              "options : dict, optional\n",
              "    A dictionary of solver options. All methods except `TNC` accept the\n",
              "    following generic options:\n",
              "    maxiter : int\n",
              "        Maximum number of iterations to perform. Depending on the\n",
              "        method each iteration may use several function evaluations.\n",
              "        For `TNC` use `maxfun` instead of `maxiter`.\n",
              "    disp : bool\n",
              "        Set to True to print convergence messages.\n",
              "    For method-specific options, see :func:`show_options()`.\n",
              "callback : callable, optional\n",
              "    A callable called after each iteration.\n",
              "    All methods except TNC and SLSQP support a callable with\n",
              "    the signature::\n",
              "        callback(intermediate_result: OptimizeResult)\n",
              "    where ``intermediate_result`` is a keyword parameter containing an\n",
              "    `OptimizeResult` with attributes ``x`` and ``fun``, the present values\n",
              "    of the parameter vector and objective function. Not all attributes of\n",
              "    `OptimizeResult` may be present. The name of the parameter must be\n",
              "    ``intermediate_result`` for the callback to be passed an `OptimizeResult`.\n",
              "    These methods will also terminate if the callback raises ``StopIteration``.\n",
              "    All methods except trust-constr (also) support a signature like::\n",
              "        callback(xk)\n",
              "    where ``xk`` is the current parameter vector.\n",
              "    Introspection is used to determine which of the signatures above to\n",
              "    invoke.\n",
              "Returns\n",
              "-------\n",
              "res : OptimizeResult\n",
              "    The optimization result represented as a ``OptimizeResult`` object.\n",
              "    Important attributes are: ``x`` the solution array, ``success`` a\n",
              "    Boolean flag indicating if the optimizer exited successfully and\n",
              "    ``message`` which describes the cause of the termination. See\n",
              "    `OptimizeResult` for a description of other attributes.\n",
              "See also\n",
              "--------\n",
              "minimize_scalar : Interface to minimization algorithms for scalar\n",
              "    univariate functions\n",
              "show_options : Additional options accepted by the solvers\n",
              "Notes\n",
              "-----\n",
              "This section describes the available solvers that can be selected by the\n",
              "'method' parameter. The default method is *BFGS*.\n",
              "**Unconstrained minimization**\n",
              "Method :ref:`CG &lt;optimize.minimize-cg&gt;` uses a nonlinear conjugate\n",
              "gradient algorithm by Polak and Ribiere, a variant of the\n",
              "Fletcher-Reeves method described in [5]_ pp.120-122. Only the\n",
              "first derivatives are used.\n",
              "Method :ref:`BFGS &lt;optimize.minimize-bfgs&gt;` uses the quasi-Newton\n",
              "method of Broyden, Fletcher, Goldfarb, and Shanno (BFGS) [5]_\n",
              "pp. 136. It uses the first derivatives only. BFGS has proven good\n",
              "performance even for non-smooth optimizations. This method also\n",
              "returns an approximation of the Hessian inverse, stored as\n",
              "`hess_inv` in the OptimizeResult object.\n",
              "Method :ref:`Newton-CG &lt;optimize.minimize-newtoncg&gt;` uses a\n",
              "Newton-CG algorithm [5]_ pp. 168 (also known as the truncated\n",
              "Newton method). It uses a CG method to the compute the search\n",
              "direction. See also *TNC* method for a box-constrained\n",
              "minimization with a similar algorithm. Suitable for large-scale\n",
              "problems.\n",
              "Method :ref:`dogleg &lt;optimize.minimize-dogleg&gt;` uses the dog-leg\n",
              "trust-region algorithm [5]_ for unconstrained minimization. This\n",
              "algorithm requires the gradient and Hessian; furthermore the\n",
              "Hessian is required to be positive definite.\n",
              "Method :ref:`trust-ncg &lt;optimize.minimize-trustncg&gt;` uses the\n",
              "Newton conjugate gradient trust-region algorithm [5]_ for\n",
              "unconstrained minimization. This algorithm requires the gradient\n",
              "and either the Hessian or a function that computes the product of\n",
              "the Hessian with a given vector. Suitable for large-scale problems.\n",
              "Method :ref:`trust-krylov &lt;optimize.minimize-trustkrylov&gt;` uses\n",
              "the Newton GLTR trust-region algorithm [14]_, [15]_ for unconstrained\n",
              "minimization. This algorithm requires the gradient\n",
              "and either the Hessian or a function that computes the product of\n",
              "the Hessian with a given vector. Suitable for large-scale problems.\n",
              "On indefinite problems it requires usually less iterations than the\n",
              "`trust-ncg` method and is recommended for medium and large-scale problems.\n",
              "Method :ref:`trust-exact &lt;optimize.minimize-trustexact&gt;`\n",
              "is a trust-region method for unconstrained minimization in which\n",
              "quadratic subproblems are solved almost exactly [13]_. This\n",
              "algorithm requires the gradient and the Hessian (which is\n",
              "*not* required to be positive definite). It is, in many\n",
              "situations, the Newton method to converge in fewer iterations\n",
              "and the most recommended for small and medium-size problems.\n",
              "**Bound-Constrained minimization**\n",
              "Method :ref:`Nelder-Mead &lt;optimize.minimize-neldermead&gt;` uses the\n",
              "Simplex algorithm [1]_, [2]_. This algorithm is robust in many\n",
              "applications. However, if numerical computation of derivative can be\n",
              "trusted, other algorithms using the first and/or second derivatives\n",
              "information might be preferred for their better performance in\n",
              "general.\n",
              "Method :ref:`L-BFGS-B &lt;optimize.minimize-lbfgsb&gt;` uses the L-BFGS-B\n",
              "algorithm [6]_, [7]_ for bound constrained minimization.\n",
              "Method :ref:`Powell &lt;optimize.minimize-powell&gt;` is a modification\n",
              "of Powell's method [3]_, [4]_ which is a conjugate direction\n",
              "method. It performs sequential one-dimensional minimizations along\n",
              "each vector of the directions set (`direc` field in `options` and\n",
              "`info`), which is updated at each iteration of the main\n",
              "minimization loop. The function need not be differentiable, and no\n",
              "derivatives are taken. If bounds are not provided, then an\n",
              "unbounded line search will be used. If bounds are provided and\n",
              "the initial guess is within the bounds, then every function\n",
              "evaluation throughout the minimization procedure will be within\n",
              "the bounds. If bounds are provided, the initial guess is outside\n",
              "the bounds, and `direc` is full rank (default has full rank), then\n",
              "some function evaluations during the first iteration may be\n",
              "outside the bounds, but every function evaluation after the first\n",
              "iteration will be within the bounds. If `direc` is not full rank,\n",
              "then some parameters may not be optimized and the solution is not\n",
              "guaranteed to be within the bounds.\n",
              "Method :ref:`TNC &lt;optimize.minimize-tnc&gt;` uses a truncated Newton\n",
              "algorithm [5]_, [8]_ to minimize a function with variables subject\n",
              "to bounds. This algorithm uses gradient information; it is also\n",
              "called Newton Conjugate-Gradient. It differs from the *Newton-CG*\n",
              "method described above as it wraps a C implementation and allows\n",
              "each variable to be given upper and lower bounds.\n",
              "**Constrained Minimization**\n",
              "Method :ref:`COBYLA &lt;optimize.minimize-cobyla&gt;` uses the PRIMA\n",
              "implementation [19]_ of the\n",
              "Constrained Optimization BY Linear Approximation (COBYLA) method\n",
              "[9]_, [10]_, [11]_. The algorithm is based on linear\n",
              "approximations to the objective function and each constraint.\n",
              "Method :ref:`COBYQA &lt;optimize.minimize-cobyqa&gt;` uses the Constrained\n",
              "Optimization BY Quadratic Approximations (COBYQA) method [18]_. The\n",
              "algorithm is a derivative-free trust-region SQP method based on quadratic\n",
              "approximations to the objective function and each nonlinear constraint. The\n",
              "bounds are treated as unrelaxable constraints, in the sense that the\n",
              "algorithm always respects them throughout the optimization process.\n",
              "Method :ref:`SLSQP &lt;optimize.minimize-slsqp&gt;` uses Sequential\n",
              "Least SQuares Programming to minimize a function of several\n",
              "variables with any combination of bounds, equality and inequality\n",
              "constraints. The method wraps the SLSQP Optimization subroutine\n",
              "originally implemented by Dieter Kraft [12]_. Note that the\n",
              "wrapper handles infinite values in bounds by converting them into\n",
              "large floating values.\n",
              "Method :ref:`trust-constr &lt;optimize.minimize-trustconstr&gt;` is a\n",
              "trust-region algorithm for constrained optimization. It switches\n",
              "between two implementations depending on the problem definition.\n",
              "It is the most versatile constrained minimization algorithm\n",
              "implemented in SciPy and the most appropriate for large-scale problems.\n",
              "For equality constrained problems it is an implementation of Byrd-Omojokun\n",
              "Trust-Region SQP method described in [17]_ and in [5]_, p. 549. When\n",
              "inequality constraints are imposed as well, it switches to the trust-region\n",
              "interior point method described in [16]_. This interior point algorithm,\n",
              "in turn, solves inequality constraints by introducing slack variables\n",
              "and solving a sequence of equality-constrained barrier problems\n",
              "for progressively smaller values of the barrier parameter.\n",
              "The previously described equality constrained SQP method is\n",
              "used to solve the subproblems with increasing levels of accuracy\n",
              "as the iterate gets closer to a solution.\n",
              "**Finite-Difference Options**\n",
              "For Method :ref:`trust-constr &lt;optimize.minimize-trustconstr&gt;`\n",
              "the gradient and the Hessian may be approximated using\n",
              "three finite-difference schemes: {'2-point', '3-point', 'cs'}.\n",
              "The scheme 'cs' is, potentially, the most accurate but it\n",
              "requires the function to correctly handle complex inputs and to\n",
              "be differentiable in the complex plane. The scheme '3-point' is more\n",
              "accurate than '2-point' but requires twice as many operations. If the\n",
              "gradient is estimated via finite-differences the Hessian must be\n",
              "estimated using one of the quasi-Newton strategies.\n",
              "**Method specific options for the** `hess` **keyword**\n",
              "+--------------+------+----------+-------------------------+-----+\n",
              "| method/Hess  | None | callable | '2-point/'3-point'/'cs' | HUS |\n",
              "+==============+======+==========+=========================+=====+\n",
              "| Newton-CG    | x    | (n, n)   | x                       | x   |\n",
              "|              |      | LO       |                         |     |\n",
              "+--------------+------+----------+-------------------------+-----+\n",
              "| dogleg       |      | (n, n)   |                         |     |\n",
              "+--------------+------+----------+-------------------------+-----+\n",
              "| trust-ncg    |      | (n, n)   | x                       | x   |\n",
              "+--------------+------+----------+-------------------------+-----+\n",
              "| trust-krylov |      | (n, n)   | x                       | x   |\n",
              "+--------------+------+----------+-------------------------+-----+\n",
              "| trust-exact  |      | (n, n)   |                         |     |\n",
              "+--------------+------+----------+-------------------------+-----+\n",
              "| trust-constr | x    | (n, n)   |  x                      | x   |\n",
              "|              |      | LO       |                         |     |\n",
              "|              |      | sp       |                         |     |\n",
              "+--------------+------+----------+-------------------------+-----+\n",
              "where LO=LinearOperator, sp=Sparse matrix, HUS=HessianUpdateStrategy\n",
              "**Custom minimizers**\n",
              "It may be useful to pass a custom minimization method, for example\n",
              "when using a frontend to this method such as `scipy.optimize.basinhopping`\n",
              "or a different library.  You can simply pass a callable as the ``method``\n",
              "parameter.\n",
              "The callable is called as ``method(fun, x0, args, **kwargs, **options)``\n",
              "where ``kwargs`` corresponds to any other parameters passed to `minimize`\n",
              "(such as `callback`, `hess`, etc.), except the `options` dict, which has\n",
              "its contents also passed as `method` parameters pair by pair.  Also, if\n",
              "`jac` has been passed as a bool type, `jac` and `fun` are mangled so that\n",
              "`fun` returns just the function values and `jac` is converted to a function\n",
              "returning the Jacobian.  The method shall return an `OptimizeResult`\n",
              "object.\n",
              "The provided `method` callable must be able to accept (and possibly ignore)\n",
              "arbitrary parameters; the set of parameters accepted by `minimize` may\n",
              "expand in future versions and then these parameters will be passed to\n",
              "the method.  You can find an example in the scipy.optimize tutorial.\n",
              "References\n",
              "----------\n",
              ".. [1] Nelder, J A, and R Mead. 1965. A Simplex Method for Function\n",
              "    Minimization. The Computer Journal 7: 308-13.\n",
              ".. [2] Wright M H. 1996. Direct search methods: Once scorned, now\n",
              "    respectable, in Numerical Analysis 1995: Proceedings of the 1995\n",
              "    Dundee Biennial Conference in Numerical Analysis (Eds. D F\n",
              "    Griffiths and G A Watson). Addison Wesley Longman, Harlow, UK.\n",
              "    191-208.\n",
              ".. [3] Powell, M J D. 1964. An efficient method for finding the minimum of\n",
              "   a function of several variables without calculating derivatives. The\n",
              "   Computer Journal 7: 155-162.\n",
              ".. [4] Press W, S A Teukolsky, W T Vetterling and B P Flannery.\n",
              "   Numerical Recipes (any edition), Cambridge University Press.\n",
              ".. [5] Nocedal, J, and S J Wright. 2006. Numerical Optimization.\n",
              "   Springer New York.\n",
              ".. [6] Byrd, R H and P Lu and J. Nocedal. 1995. A Limited Memory\n",
              "   Algorithm for Bound Constrained Optimization. SIAM Journal on\n",
              "   Scientific and Statistical Computing 16 (5): 1190-1208.\n",
              ".. [7] Zhu, C and R H Byrd and J Nocedal. 1997. L-BFGS-B: Algorithm\n",
              "   778: L-BFGS-B, FORTRAN routines for large scale bound constrained\n",
              "   optimization. ACM Transactions on Mathematical Software 23 (4):\n",
              "   550-560.\n",
              ".. [8] Nash, S G. Newton-Type Minimization Via the Lanczos Method.\n",
              "   1984. SIAM Journal of Numerical Analysis 21: 770-778.\n",
              ".. [9] Powell, M J D. A direct search optimization method that models\n",
              "   the objective and constraint functions by linear interpolation.\n",
              "   1994. Advances in Optimization and Numerical Analysis, eds. S. Gomez\n",
              "   and J-P Hennart, Kluwer Academic (Dordrecht), 51-67.\n",
              ".. [10] Powell M J D. Direct search algorithms for optimization\n",
              "   calculations. 1998. Acta Numerica 7: 287-336.\n",
              ".. [11] Powell M J D. A view of algorithms for optimization without\n",
              "   derivatives. 2007.Cambridge University Technical Report DAMTP\n",
              "   2007/NA03\n",
              ".. [12] Kraft, D. A software package for sequential quadratic\n",
              "   programming. 1988. Tech. Rep. DFVLR-FB 88-28, DLR German Aerospace\n",
              "   Center -- Institute for Flight Mechanics, Koln, Germany.\n",
              ".. [13] Conn, A. R., Gould, N. I., and Toint, P. L.\n",
              "   Trust region methods. 2000. Siam. pp. 169-200.\n",
              ".. [14] F. Lenders, C. Kirches, A. Potschka: \"trlib: A vector-free\n",
              "   implementation of the GLTR method for iterative solution of\n",
              "   the trust region problem\", :arxiv:`1611.04718`\n",
              ".. [15] N. Gould, S. Lucidi, M. Roma, P. Toint: \"Solving the\n",
              "   Trust-Region Subproblem using the Lanczos Method\",\n",
              "   SIAM J. Optim., 9(2), 504--525, (1999).\n",
              ".. [16] Byrd, Richard H., Mary E. Hribar, and Jorge Nocedal. 1999.\n",
              "    An interior point algorithm for large-scale nonlinear  programming.\n",
              "    SIAM Journal on Optimization 9.4: 877-900.\n",
              ".. [17] Lalee, Marucha, Jorge Nocedal, and Todd Plantenga. 1998. On the\n",
              "    implementation of an algorithm for large-scale equality constrained\n",
              "    optimization. SIAM Journal on Optimization 8.3: 682-706.\n",
              ".. [18] Ragonneau, T. M. *Model-Based Derivative-Free Optimization Methods\n",
              "    and Software*. PhD thesis, Department of Applied Mathematics, The Hong\n",
              "    Kong Polytechnic University, Hong Kong, China, 2022. URL:\n",
              "    https://theses.lib.polyu.edu.hk/handle/200/12294.\n",
              ".. [19] Zhang, Z. \"PRIMA: Reference Implementation for Powell's Methods with\n",
              "    Modernization and Amelioration\", https://www.libprima.net,\n",
              "    :doi:`10.5281/zenodo.8052654`\n",
              ".. [20] Karush-Kuhn-Tucker conditions,\n",
              "    https://en.wikipedia.org/wiki/Karush%E2%80%93Kuhn%E2%80%93Tucker_conditions\n",
              "Examples\n",
              "--------\n",
              "Let us consider the problem of minimizing the Rosenbrock function. This\n",
              "function (and its respective derivatives) is implemented in `rosen`\n",
              "(resp. `rosen_der`, `rosen_hess`) in the `scipy.optimize`.\n",
              "&gt;&gt;&gt; from scipy.optimize import minimize, rosen, rosen_der\n",
              "A simple application of the *Nelder-Mead* method is:\n",
              "&gt;&gt;&gt; x0 = [1.3, 0.7, 0.8, 1.9, 1.2]\n",
              "&gt;&gt;&gt; res = minimize(rosen, x0, method='Nelder-Mead', tol=1e-6)\n",
              "&gt;&gt;&gt; res.x\n",
              "array([ 1.,  1.,  1.,  1.,  1.])\n",
              "Now using the *BFGS* algorithm, using the first derivative and a few\n",
              "options:\n",
              "&gt;&gt;&gt; res = minimize(rosen, x0, method='BFGS', jac=rosen_der,\n",
              "...                options={'gtol': 1e-6, 'disp': True})\n",
              "Optimization terminated successfully.\n",
              "         Current function value: 0.000000\n",
              "         Iterations: 26\n",
              "         Function evaluations: 31\n",
              "         Gradient evaluations: 31\n",
              "&gt;&gt;&gt; res.x\n",
              "array([ 1.,  1.,  1.,  1.,  1.])\n",
              "&gt;&gt;&gt; print(res.message)\n",
              "Optimization terminated successfully.\n",
              "&gt;&gt;&gt; res.hess_inv\n",
              "array([\n",
              "    [ 0.00749589,  0.01255155,  0.02396251,  0.04750988,  0.09495377],  # may vary\n",
              "    [ 0.01255155,  0.02510441,  0.04794055,  0.09502834,  0.18996269],\n",
              "    [ 0.02396251,  0.04794055,  0.09631614,  0.19092151,  0.38165151],\n",
              "    [ 0.04750988,  0.09502834,  0.19092151,  0.38341252,  0.7664427 ],\n",
              "    [ 0.09495377,  0.18996269,  0.38165151,  0.7664427,   1.53713523]\n",
              "])\n",
              "Next, consider a minimization problem with several constraints (namely\n",
              "Example 16.4 from [5]_). The objective function is:\n",
              "&gt;&gt;&gt; fun = lambda x: (x[0] - 1)**2 + (x[1] - 2.5)**2\n",
              "There are three constraints defined as:\n",
              "&gt;&gt;&gt; cons = ({'type': 'ineq', 'fun': lambda x:  x[0] - 2 * x[1] + 2},\n",
              "...         {'type': 'ineq', 'fun': lambda x: -x[0] - 2 * x[1] + 6},\n",
              "...         {'type': 'ineq', 'fun': lambda x: -x[0] + 2 * x[1] + 2})\n",
              "And variables must be positive, hence the following bounds:\n",
              "&gt;&gt;&gt; bnds = ((0, None), (0, None))\n",
              "The optimization problem is solved using the SLSQP method as:\n",
              "&gt;&gt;&gt; res = minimize(fun, (2, 0), method='SLSQP', bounds=bnds, constraints=cons)\n",
              "It should converge to the theoretical solution ``[1.4 ,1.7]``. *SLSQP* also\n",
              "returns the multipliers that are used in the solution of the problem. These\n",
              "multipliers, when the problem constraints are linear, can be thought of as the\n",
              "Karush-Kuhn-Tucker (KKT) multipliers, which are a generalization\n",
              "of Lagrange multipliers to inequality-constrained optimization problems ([20]_).\n",
              "Notice that at the solution, the first constraint is active. Let's evaluate the\n",
              "function at solution:\n",
              "&gt;&gt;&gt; cons[0]['fun'](res.x)\n",
              "np.float64(1.4901224698604665e-09)\n",
              "Also, notice that at optimality there is a non-zero multiplier:\n",
              "&gt;&gt;&gt; res.multipliers\n",
              "array([0.8, 0. , 0. ])\n",
              "This can be understood as the local sensitivity of the optimal value of the\n",
              "objective function with respect to changes in the first constraint. If we\n",
              "tighten the constraint by a small amount ``eps``:\n",
              "&gt;&gt;&gt; eps = 0.01\n",
              "&gt;&gt;&gt; cons[0]['fun'] = lambda x: x[0] - 2 * x[1] + 2 - eps\n",
              "we expect the optimal value of the objective function to increase by\n",
              "approximately ``eps * res.multipliers[0]``:\n",
              "&gt;&gt;&gt; eps * res.multipliers[0]  # Expected change in f0\n",
              "np.float64(0.008000000027153205)\n",
              "&gt;&gt;&gt; f0 = res.fun  # Keep track of the previous optimal value\n",
              "&gt;&gt;&gt; res = minimize(fun, (2, 0), method='SLSQP', bounds=bnds, constraints=cons)\n",
              "&gt;&gt;&gt; f1 = res.fun  # New optimal value\n",
              "&gt;&gt;&gt; f1 - f0\n",
              "np.float64(0.008019998807885509)\n",
              "<span class=\"ansi-red-fg\">File:</span>      ~/venvs/py3/lib/python3.12/site-packages/scipy/optimize/_minimize.py\n",
              "<span class=\"ansi-red-fg\">Type:</span>      function</pre>"
            ]
          }
        }
      ],
      "source": [
        "?sp.optimize.minimize"
      ],
      "id": "fa7635c2-6339-4d90-929b-a6f6ca4dcb14"
    }
  ],
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3 (ipykernel)",
      "language": "python"
    },
    "language_info": {
      "name": "python",
      "codemirror_mode": {
        "name": "ipython",
        "version": "3"
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.12"
    }
  }
}