{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

Minimization

" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib\n", "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "from scipy.stats import chi2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Minimization, not using least squares

\n", "\n", "Let's try a general minimization function, for Poisson uncertainties on a Gaussian profile. First write out obligatory routine to return a Gaussian. Here, we'll add another constant background/continuum value. We will also add an option to return the vector of derivatives of the Gaussian with respect to each parameter.\n", "
\n", "if \n", "$$f = A \\exp{-0.5(x-x_0)/\\sigma^2} + c$$\n", "then the derivatives are:\n", "$${df\\over dA} = \\exp{-0.5(x-x_0)^2/\\sigma^2}$$\n", "$${df\\over dx_0} = f {(x-x_0)\\over \\sigma^2}$$\n", "$${df\\over d\\sigma} = f {(x-x_0)^2\\over \\sigma^3}$$\n", "$${df\\over dc } = 1$$" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXxU1fn48c/JSkJISCBhT4JCtVY0SkDcU7GKfN3w64IdEQSNa39Ctf0iWGtrU7V1Qa2KQRC0I4o7WBURG2y1ARGBIGJBSULY1yQQyDI5vz9mgkmYLbPcuXPzvF+vvMjcuTP34c69T+6c+5xzlNYaIYQQ0S8m0gEIIYQIDUnoQghhEZLQhRDCIiShCyGERUhCF0IIi4gzcmM9e/bUubm5Rm5SCCGi3ldffbVHa53paz1DE3pubi4rV640cpN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W9rzlVLDcZ7Pew2IzZ/PaCFwo6vaZQRQ3dLMYBCP354jtd9aaX1MecpTi4GLlFLprmbTi1zLvDPiTm8H7giPwfmXqR7YCSxu9dx0nBUJ3wGXtFr+AdDX9ftxOBP9JuANIDGMsc4Fbmu3rC/wQatY1rh+vsHZ5GDEPnwFKAPWug6cPu1jcz0ejbNy4nsDY9uEs11wtetnZvvYjN5v7vYD8Eecf3QAuriOpU2uY+s4g/bVOTi/Yq9ttb9GA7e1HHfAXa59tAbnTeazDIrN7WfULjYFPOvar2W0qlozIL5knAk6rdWyiOw3nH9UtgONrtw2Cec9mKXARte/Ga5184EXW712ouu42wTc5M/2pOu/EEJYRLQ0uQghhPBBEroQQliEJHQhhLAISehCCGERktCFEMIiJKELIYRFSEIXQgiL+P9Bhj0WXKLMQQAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "# here we define the function. For use with curve_fit, we need each parameter to \n", "# be a separate argument (i.e., not have all arguments as a single list/array)\n", "def model(x,amp,cent,sigma,const,deriv=False) :\n", " \"\"\" Gaussian profile function with amplitude, center, sigma, plus constant\n", " with deriv=False, return array of model values at location of input x\n", " with deriv=True, also return array of derivatives\n", " \"\"\"\n", " delta=(x-cent)**2/sigma**2\n", " f= amp*np.exp(-0.5*delta)\n", " if not deriv :\n", " return f+const\n", " else :\n", " # extra code here for computing derivatives if requested\n", " tmp=f*(x-cent)/sigma**2\n", " d = np.array([f/amp, tmp, tmp*(x-cent)/sigma,np.ones(len(x))])\n", " return f+const,d\n", "\n", "# simulate some data. Note that I've defined a par array for convenience, but pass it as\n", "# individual arguments using *par\n", "x=np.arange(-10,10,0.5)\n", "par=[10.,0.,3.,1.]\n", "\n", "# here's what we would get if we assumed Gaussian uncertainties\n", "sig=np.sqrt(model(x,*par))\n", "y=model(x,*par)+np.random.normal(0.,sig,size=len(x))\n", "plt.errorbar(x,y,sig,fmt='ro')\n", "\n", "# here's using Poisson uncertainties\n", "y=np.random.poisson(model(x,*par))\n", "plt.errorbar(x,y,sig,fmt='go')\n", "plt.plot(x,model(x,*par))\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Given that, for a Poisson distribution, the probability of getting an observed value, $y_i$, given an underlying model value, $f_i$, at each $x_i$ is: \n", "$$P(x_i|f_i) = {\\exp(-f_i) f_i^{x_i} \\over x_i!}$$\n", "\n", "what is the expression/function for the log(likelihood) of this data set? Remember the probability of the data set is just the product of the probabilties of the individual points.\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " ANSWER: " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To maximize the likelihood, we will minimize the log(likelihood). For a Poisson distribution, the probability of getting an observed value, y, given an underlying model value, f, is: \n", "$$P(x|f) = {\\exp(-f) f^x \\over x!}$$\n", "Take the log to get:\n", "$$ ln(P(x)) = -f(x) + x ln(f) - ln(x!)$$\n", "Multiplying the probabilities of each individual point is taking the sum of the logs. Since the last term is independent of the model parameters, we can neglect it when looking for a maximum with respect to parameter values.\n", "$$ln(L) = \\sum -f_i + y ln(f_i)$$\n", "where $f_i$ is the model value at each $x_i$\n", "
\n", "Write a routine to routine the -ln(likelihood), which will use the data values, as well as the model values given the independent variable values. Include an option to return the vector of derivatives with respect to each parameters as well." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-132.1069679423997\n", " fun: -140.25780751783714\n", " hess_inv: array([[ 1.25663502, -0.00775656, -0.17409553, -0.00186432],\n", " [-0.00775656, 0.08412766, -0.01932584, 0.024792 ],\n", " [-0.17409553, -0.01932584, 0.16306609, -0.13126844],\n", " [-0.00186432, 0.024792 , -0.13126844, 0.1817842 ]])\n", " jac: array([ 0.00000000e+00, -1.90734863e-06, 1.90734863e-06, 1.90734863e-06])\n", " message: 'Optimization terminated successfully.'\n", " nfev: 70\n", " nit: 11\n", " njev: 14\n", " status: 0\n", " success: True\n", " x: array([9.51996749, 0.312664 , 2.77652864, 1.18851471])\n", "-140.25780751783714\n" ] }, { "data": { "text/plain": [ "[]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD6CAYAAAC4RRw1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXxU9bnH8c9D2BdZLiA7KKVcbXHBXKzikhYX0CIuuMYqym1ciutt1cp1N23VqnUrNhZFba5o3RCXKlKxLhUNKgYEyyJBBAFFQAhCIL/7x29SQ5hJJrOdOZPv+/WaVyZnfXLOmSdnfuf3nGPOOUREJHyaBR2AiIgkRglcRCSklMBFREJKCVxEJKSUwEVEQkoJXEQkpBpM4GbW18xeM7MFZjbfzC6JDO9iZjPMbFHkZ+f0hysiIjWsoX7gZtYT6Omce9/MOgBzgOOBccA659zvzOwqoLNz7sr6ltW1a1c3YMCAlAQuItJUzJkz50vnXLe6w5s3NKNzbhWwKvL+GzNbAPQGxgAFkckeBmYB9SbwAQMGUFZW1qjARUSaOjOriDa8UW3gZjYA2B+YDeweSe41Sb57ciGKiEhjxJ3Azaw98BRwqXNuYyPmKzKzMjMrW7t2bSIxiohIFHElcDNrgU/epc65pyODV0fax2vayddEm9c5V+Kcy3fO5XfrtksTjoiIJCieXigGTAYWOOfuqDXqOeDsyPuzgWmpD09ERGJp8CImMBz4GVBuZh9Ghl0N/A54wszGA8uBk9MTooiIRBNPL5Q3AYsxekRqwxERkXipElNEJKSUwEVEQkoJXHJCwZQCCqYUBB2GSEYpgYuIhJQSuIhISCmBi4iElBK4iEhIKYGLiISUEriISEgpgYuIhJQSuIhISCmBi4iElBK4iEhIKYGLiISUEriISEgpgYuIhJQSuIhISCmBi4iElBK4iEhIKYGLiISUEriISE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BZkd4oPwI21DQdZEDMb8FBbK86ah9HsXLRy8BRZtY50uR5VGRY/DJxlbYRV3NPwP9X2gqsBl6uNW4ivgfBJ8CoWsNfBHpF3u+JT+yLgb8CrdIU5xTg/DrDegEv1opjbuQ1H9+UkO5t9yhQDnwUOXh61o0r8vsx+F4OSzIU12J8O9+Hkdf9dePK5PaK9vcDN+L/wQC0jhw7iyPH0p4Z2EaH4L86f1RrOx0DnF9znAETIttmLv5i8MEZiCvqfqkTlwH3RbZnObV6j6U5trb4hNyx1rBAthf+n8gqoCqSv8bjr5vMBBZFfnaJTJsP/LnWvOdGjrXFwDmNXbcqMUVEQiosTSgiIlKHEriISEgpgYuIhJQSuIhISCmBi4iElBK4iEhIKYGLiISUEriISEj9P8rMTcLE5sK6AAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "def logl(pars,x,y,deriv=False) :\n", " \"\"\" log(likelihood) function\n", " Poisson p(x|f) = exp(-f)*f(y) / y!\n", " ln(p) = -f + y*f - ln(y!)\n", " but last term is independent of pars\n", " \"\"\"\n", " mod=model(x,*pars,deriv=deriv)\n", " if not deriv :\n", " tmp = np.sum(-mod+y*np.log(mod))\n", " bd=np.where(mod <=0)[0]\n", " if len(bd) > 0 : print('bad: ',pars)\n", " return -tmp\n", " else :\n", " tmp = np.sum(-mod[0]+y*np.log(mod[0]))\n", " return -tmp,-np.sum(-mod[1] + y*mod[1]/mod[0],axis=1)\n", "\n", "\n", "from scipy.optimize import minimize\n", "p0=[8,1,3,0]\n", "p0=[10,0,3,2]\n", "print(logl(p0,x,y))\n", "# default BFGS algorithm, numerical derivatives\n", "out=minimize(logl,p0,args=(x,y))\n", "print(out)\n", "print(logl(out['x'],x,y))\n", "\n", "xfit=np.arange(-10,10,0.01)\n", "plt.errorbar(x,y,sig,fmt='go')\n", "plt.plot(xfit,model(xfit,*out.x),color='b')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we will use scipy.optimize.minimize() to find the minimum of our -ln(likelihood) function. You'll need to supply a starting guess." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " fun: -135.02762072896473\n", " hess_inv: array([[ 1.31411877, -0.01418979, -0.14358744, -0.03101242],\n", " [-0.01418979, 0.09643986, 0.0179437 , -0.01432622],\n", " [-0.14358744, 0.0179437 , 0.08565652, -0.05610299],\n", " [-0.03101242, -0.01432622, -0.05610299, 0.10216768]])\n", " jac: array([0.00000000e+00, 0.00000000e+00, 3.81469727e-06, 1.90734863e-06])\n", " message: 'Optimization terminated successfully.'\n", " nfev: 100\n", " nit: 17\n", " njev: 20\n", " status: 0\n", " success: True\n", " x: array([ 9.82479012, -0.22915828, 2.76639097, 0.91959623])\n" ] }, { "data": { "text/plain": [ "[]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD5CAYAAAA+0W6bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXwU9f3H8deHcIkoIAJqFaIt3lSl0VbrEcUDUUSpRTT1RGOrVG219chD5YdNPVr9eR94gRoRC943oqD2gQfwQ0HBGpFLELAKiGgg5Pv747uRGHaTTXZmZ2fzfj4e+8hmdnbmM5PvfjL7nfnM15xziIhI/LSKOgAREWkeJXARkZhSAhcRiSklcBGRmFICFxGJKSVwEZGYat3YDGa2A/AQsA1QA4xyzt1iZlsB44BCYD4wxDn3dUPL2nrrrV1hYWGGIYuItCzTp0//0jnXrf50a+w6cDPbFtjWOTfDzLYApgPHA2cAXznnrjOzy4AuzrlLG1pWUVGRmzZtWnO3QUSkRTKz6c65ovrTG+1Ccc4tdc7NSDz/BpgD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J1zhzfjbYuBHer8vj2wpN48X+K/vrVOHDklmyeQGM2sNTAY+EUDy1iS+LnczJ7Ef33PKCGlu+/M7F7guSQvpbMfA48rcXLmWKCfS3T+JVlG4PsriXS2v3aexYm/cyc2/XocODNrg0/eFc65J+q/XjehO+deMLM7zWxr51yo9/xI4+8SSptK09HADOfcsvovRLW/6lhmZts655YmupSWJ5lnMb6vvtb2+PN/aYtLF8ozwNDEFQI74v+Tvlt3hkRieB04MTHpdCDVEX2mDgfmOucWJ3vRzDY3sy1qn+NP5M1ONm9Q6vU7npBife8Bvc1frdMW//XzmZDj6g9cChznnFubYp5s7a90tv8ZfNsB35ZeS/VPJyiJPvb7gTnOuZtSzLNNbV+8me2H/+z+N+S40vm7PAOclrga5VfAqtqugyxI+S04iv1VT912lCoXvQwcaWZdEl2eRyampS8bZ2mbcDb3BPx/pSpgGfByndfK8FcQfAwcXWf6C8B2iec74RN7JfAvoF1IcY4Gfl9v2nbAC3XieD/x+BDflRD2vnsYmAV8kGg829aPK/H7APxVDp9mKa5KfD/fzMTj7vpxZXN/Jdt+YCT+HwxA+0TbqUy0pZ2ysI8OxH91/qDOfhoA/L62nQHDE/vmffzJ4AOyEFfSv0u9uAy4I7E/Z1Hn6rGQY+uAT8id6kyLZH/h/4ksBdYn8tcw/HmTScAniZ9bJeYtAu6r896zEm2tEjizqetWJaaISEzFpQtFRETqUQIXEYkpJXARkZhSAhcRiSklcBGRmFICFxGJKSVwEZGYUgIXEYmp/wdeJGpexjxZmgAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "from scipy.optimize import minimize\n", "p0=[8,1,3,0]\n", "# default BFGS algorithm, numerical derivatives\n", "out=minimize(logl,p0,args=(x,y))\n", "print(out)\n", "\n", "xfit=np.arange(-10,10,0.01)\n", "plt.errorbar(x,y,sig,fmt='go')\n", "plt.plot(xfit,model(xfit,*out.x),color='b')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here's an example of specifying bounds on a parameter" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " fun: -135.0276207289479\n", " hess_inv: <4x4 LbfgsInvHessProduct with dtype=float64>\n", " jac: array([ 0.00000000e+00, -1.13686838e-05, -1.70530258e-05, 0.00000000e+00])\n", " message: 'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'\n", " nfev: 85\n", " nit: 15\n", " njev: 17\n", " status: 0\n", " success: True\n", " x: array([ 9.8247912 , -0.22915942, 2.7663895 , 0.91959721])\n" ] }, { "data": { "text/plain": [ "[]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD5CAYAAAA+0W6bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3de3gU1f3H8feXqyAKqIBahWhLvVIVo63WSxQviCJKrYKpoqKxVaq22nrJo/LTpl5a/Xm/4A3UiFjwfkcU1D6gAj8UFKwRuSNglZtoIOT8/jgbiWE32WRndnY2n9fz7JPN7OzMdyZnv5k9M9855pxDRETip0XUAYiISNMogYuIxJQSuIhITCmBi4jElBK4iEhMKYGLiMRUq4ZmMLOdgUeB7YFqYIRz7nYz2wYYAxQA84BTnXPf1Les7bbbzhUUFGQYsohI8zJt2rSvnHNd6k63hq4DN7MdgB2cc9PNbCtgGnAScBbwtXPuRjO7AujsnLu8vmUVFha6qVOnNnUbRESaJTOb5pwrrDu9wS4U59xS59z0xPM1wGzgJ8AAYFRitlH4pC4iIlnSqD5wMysA9gPeA7o555aCT/JA16CDExGR1NJO4GbWARgHXOKcW92I95WY2VQzm7pixYqmxCgiIkmklcDNrDU+eZc7555OTF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+qmWZme3gnFua6FJanmSeRfi++ho74c//pS0uXSjPA4MSVwjsgv9P+n7tGRKJ4S3glMSkIUCqI/pMHQXMcc4tSvaimW1pZlvVPMefyJuVbN6g1Ol3PDnF+j4Aepq/WqcN/uvn8yHH1Re4HDjRObcuxTzZ2l/pbP/z+LYDvi29meqfTlASfewPAbOdc7emmGf7mr54MzsQ/9n9b8hxpfN3eR44M3E1yq+AVTVdB1mQ8ltwFPurjtrtKFUueg04xsw6J7o8j0lMS182ztI24mzuyfj/SpXAMuC1Wq+V4q8g+BQ4rtb0l4EdE893xSf2CuBfQNuQ4hwJ/L7OtB2Bl2vF8WHi8TG+KyHsffcYMBP4KNF4dqgbV+L3fvirHD7PUlwV+H6+GYnHfXXjyub+Srb9wHX4fzAAWyTaTkWiLe2ahX10CP6r80e19lM/4Pc17QwYltg3H+JPBh+chbiS/l3qxGXA3Yn9OZNaV4+FHFt7fELuWGtaJPsL/09kKbAhkb+G4s+bTAA+S/zcJjFvIfBgrfeek2hrFcDZjV23KjFFRGIqLl0oIiJShxK4iEhMKYGLiMSUEriISEwpgYuIxJQSuIhITCmBi4jElBK4iEhM/T/hT2pgY8i1jAAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "nobounds=(None,None)\n", "out=minimize(logl,p0,args=(x,y),bounds=[(0,None),nobounds,(0,None),(0,None)])\n", "\n", "print(out)\n", "\n", "xfit=np.arange(-10,10,0.01)\n", "plt.errorbar(x,y,sig,fmt='go')\n", "plt.plot(xfit,model(xfit,*out.x),color='b')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here are some examples for timing different algorithms, with and without analytical derivatives" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# default BFGS algorithm, numerical derivatives\n", "print('BFGS, numerical derivatives')\n", "%timeit -n100 out=minimize(logl,p0,args=(x,y))\n", "out=minimize(logl,p0,args=(x,y))\n", "print(out)\n", "\n", "# BFGS algorithm, supplying derivatives: jac=True means that function returns derivatives as well as value\n", "print('\\nBFGS, analytical derivatives')\n", "%timeit -n100 out=minimize(logl,p0,args=(x,y,True),jac=True)\n", "out=minimize(logl,p0,args=(x,y,True),jac=True)\n", "print(out)\n", "\n", "# Downhill simplex (Nelder-Mead) algorithm\n", "print('\\nDownhill simplex (Nelder-Mead)')\n", "%timeit -n100 out=minimize(logl,p0,args=(x,y),method='Nelder-Mead')\n", "out=minimize(logl,p0,args=(x,y),method='Nelder-Mead')\n", "print(out)\n", "\n", "# here's treating the problem with least squares\n", "print('\\nleast squares')\n", "from scipy.optimize import curve_fit\n", "%timeit -n100 fit=curve_fit(model,x,y,p0=p0,sigma=sig)\n", "fit=curve_fit(model,x,y,p0=p0,sigma=sig)\n", "print('least squares: ',fit[0])\n", "\n", "xfit=np.arange(-10,10,0.01)\n", "plt.errorbar(x,y,sig,fmt='go')\n", "plt.plot(xfit,model(xfit,*out.x),color='b')\n", "plt.plot(xfit,model(xfit,*fit[0]),color='r')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "How do the speeds of the different algorithms compare? Are they what you would expect, given what you know about the algorithms?\n", "
ANSWER HERE: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "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.7.11" } }, "nbformat": 4, "nbformat_minor": 1 }