Created
September 23, 2015 06:42
-
-
Save andyfaff/c51d04cec2a6454c1e1a to your computer and use it in GitHub Desktop.
model selection with lmfit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Model selection using lmfit and emcee " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"`lmfit` can be used to obtain the posterior probability distribution of parameters, given a set of experimental data." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import lmfit\n", | |
"import matplotlib.pyplot as plt\n", | |
"import triangle\n", | |
"%matplotlib inline" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def gauss(x, a_max, loc, sd):\n", | |
" return a_max * np.exp(-((x - loc) / sd)**2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"x = np.linspace(3, 7, 250)\n", | |
"np.random.seed(0)\n", | |
"y = 4 + 10 * x + gauss(x, 200, 5, 0.5) + gauss(x, 60, 5.8, 0.2)\n", | |
"dy = np.sqrt(y)\n", | |
"y += dy * np.random.randn(np.size(y))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<Container object of 3 artists>" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAEACAYAAAC9Gb03A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RpjzXB7EiI6+ki1PWK6/UUkUwAX1fVZwD2\n06nqHp/d4n49w7QTSJzf55kAtqhqsU97o69lVIVeRNJEZDWACgALVbXIZxd/g6vyo2mTL2HYqAAm\nuR6R3hKR4bG0z4PfA/g5gOMBtsf9WroIZWeiXE8F8J6IrBCR6/1sT5TrGcrORLie/QBUicjfReQz\nEXlaRNr57JMI1zMcOxPhejrMAvAvP+2NvpbR9uiPq+polxGTRaTAz26+d8+Y9g6HYeNn4KPTKAB/\nBvB6LO0DABE5H0Clqq5CcG8jrtcyTDvjfj1dnKqqYwCcA+CHIvJ1P/vE9Xq6CGVnIlzPdABjATyu\nqmMB7Adwu5/94n09w7EzEa4nRCQDwDcB/CfQLj7rQa9lTMoUux6P/h+AcT6bSgH08ljPd7XFnEA2\nqmqdE95R1fkAWotIdozNmwRguohsBfACgDNE5DmffRLhWoa0M0GuJ1R1p+u9CsBrYI0mTxLheoa0\nM0GuZwmAElX91LX+MiioniTC9QxpZ4JcT4A39pWuv7svjb6W0cy66SoiWa7ltgDOArDKZ7d5AK50\n7TMRwG5VrYiWTU2xUURyRURcyxPAlFR/cfyooap3qmovVe0HPs59oKpX+uwW12sZrp2JcD1FpJ2I\ndHQttwcwFcBan93ifj3DsTMRrqeqlgMoFpHBrqYzAaz32S3u1zMcOxPherq4FHSW/NHoaxnxAVMe\n5AF4VkTSwBvK86r6voh8DwBU9a+q+paInCsim8HHqKujaE+TbATwbQA/EJGjAOpBAYs3CgAJdi39\n0cBOJMb1zAXwmuv/OR3AP1X13QS8niHtRGJcTwD4EYB/ukIOWwBck4DXM6SdSIDr6bqpnwngeo+2\nZl1LGzBlGIaR4thUgoZhGCmOCb1hGEaKY0JvGIaR4pjQG4ZhpDgm9IZhGCmOCb1hGEaKY0JvGIaR\n4pjQG4ZhpDj/H0alzV+vYglmAAAAAElFTkSuQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x104e23710>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"plt.errorbar(x, y)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def residual(p, just_generative=False):\n", | |
" v = p.valuesdict()\n", | |
" generative = v['a'] + v['b'] * x\n", | |
" M = 0\n", | |
" while 'a_max%d' % M in v:\n", | |
" generative += gauss(x, v['a_max%d'%M], v['loc%d'%M], v['sd%d'%M])\n", | |
" M += 1\n", | |
"\n", | |
" if just_generative:\n", | |
" return generative\n", | |
" return (generative - y) / dy" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# create a Parameter set for the initial guesses\n", | |
"def initial_peak_params(M):\n", | |
" p = lmfit.Parameters()\n", | |
" a = np.mean(y)\n", | |
" b = 1\n", | |
" a_max = np.max(y)\n", | |
" loc = np.mean(x)\n", | |
" sd = (np.max(x) - np.min(x)) * 0.5\n", | |
"\n", | |
" p.add_many(('a', np.mean(y), True, 0, 10), ('b', b, True, 1, 15))\n", | |
"\n", | |
" for i in range(M):\n", | |
" p.add_many(('a_max%d'%i, 0.5 * a_max, True, 10, a_max),\n", | |
" ('loc%d'%i, loc, True, np.min(x), np.max(x)),\n", | |
" ('sd%d'%i, sd, True, 0.1, np.max(x) - np.min(x)))\n", | |
" return p" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Solving with `minimize` gives the Maximum Likelihood solution." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[[Variables]]\n", | |
" a: 1.51224223 (init= 10)\n", | |
" b: 10.5609028 (init= 1)\n", | |
" a_max0: 193.129507 (init= 141.2683)\n", | |
" loc0: 5.03878771 (init= 5)\n", | |
" sd0: 0.57125988 (init= 2)\n", | |
"[[Correlations]] (unreported correlations are < 0.500)\n" | |
] | |
} | |
], | |
"source": [ | |
"p1 = initial_peak_params(1)\n", | |
"mi1 = lmfit.minimize(residual, p1, method='differential_evolution')\n", | |
"\n", | |
"lmfit.printfuncs.report_fit(mi1.params, min_correl=0.5)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"However, this doesn't give a probability distribution for the parameters. Furthermore, we wish to deal with the data uncertainty. This is called marginalisation of a nuisance parameter. `emcee` requires a function that returns the log-posterior probability. The log-posterior probability is a sum of the log-prior probability and log-likelihood functions. The log-prior probability is assumed to be zero if all the parameters are within their bounds and `-np.inf` if any of the parameters are outside their bounds." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# This is the log-likelihood probability for the sampling.\n", | |
"def lnprob(p):\n", | |
" resid = residual(p, just_generative=True)\n", | |
" return -0.5 * np.sum(((resid - y) / dy)**2 + np.log(2 * np.pi * dy**2))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0 310 (-4396.6022688087269, 0.49210220942131855)\n", | |
"1 310 (-1045.339451412781, 6.7159454900820492)\n", | |
"2 310 (-937.58116589602696, 9.1279318938875349)\n", | |
"3 310 (-950.16931281126676, 10.295013691219992)\n" | |
] | |
} | |
], | |
"source": [ | |
"# Now lets work out the log-evidence for different numbers of peaks\n", | |
"burn = 300\n", | |
"thin = 10\n", | |
"ntemps = 15\n", | |
"workers=4\n", | |
"log_evidence = []\n", | |
"mini = []\n", | |
"res = []\n", | |
"\n", | |
"# set up the Minimizers\n", | |
"for i in range(4):\n", | |
" p0 = initial_peak_params(i)\n", | |
" mini.append(lmfit.Minimizer(lnprob, p0))\n", | |
" out = mini[i].minimize(method='differential_evolution')\n", | |
" res.append(out)\n", | |
"\n", | |
"total_steps = 310\n", | |
"# burn in the samplers\n", | |
"for i in range(4):\n", | |
" # do the sampling\n", | |
" out = mini[i].emcee(steps=310, ntemps=ntemps, workers=workers, reuse_sampler=False,\n", | |
" params=res[i].params)\n", | |
" # get the evidence\n", | |
" print(i, total_steps, mini[i].sampler.thermodynamic_integration_log_evidence())\n", | |
" log_evidence.append(mini[i].sampler.thermodynamic_integration_log_evidence()[0])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0 410 (-4397.2560033105292, 0.44918471141681948)\n", | |
"1 410 (-1046.4683593227637, 7.4815351753807136)\n", | |
"2 410 (-939.94542406160633, 9.4959066821616034)\n", | |
"3 410 (-952.93565515210992, 11.469802405346286)\n", | |
"0 510 (-4397.6793454040953, 0.40973253505489993)\n", | |
"1 510 (-1047.3160213239353, 8.0491423392570596)\n", | |
"2 510 (-941.66433605066152, 9.6985630480652389)\n", | |
"3 510 (-955.08217059421099, 12.582124296094207)\n", | |
"0 610 (-4397.9596953022838, 0.37919697193956381)\n", | |
"1 610 (-1048.0376025386586, 8.4897199923516382)\n", | |
"2 610 (-942.92595681693899, 9.8236085882018642)\n", | |
"3 610 (-956.65961145532879, 13.516930818580931)\n", | |
"0 710 (-4398.1945761284132, 0.35281168432993582)\n", | |
"1 710 (-1048.6882834472437, 8.8220957020687365)\n", | |
"2 710 (-943.98784364111691, 9.9501969794896468)\n", | |
"3 710 (-957.83756672312495, 14.135558317186451)\n", | |
"0 810 (-4398.3967256181213, 0.33012047874217387)\n", | |
"1 810 (-1049.3368576955197, 9.0329401783053527)\n", | |
"2 810 (-944.90031810750895, 10.074995996845018)\n", | |
"3 810 (-958.82377961133204, 14.647967017922838)\n", | |
"0 910 (-4398.5283877147976, 0.31542166970575636)\n", | |
"1 910 (-1049.9134746623272, 9.1783057759282656)\n", | |
"2 910 (-945.70917595371918, 10.176225190078185)\n", | |
"3 910 (-959.67454304128751, 15.120676241524848)\n", | |
"0 1010 (-4398.6317817432455, 0.30344262582366355)\n", | |
"1 1010 (-1050.4668892836764, 9.2678993448282654)\n", | |
"2 1010 (-946.45561122310528, 10.265865299859797)\n", | |
"3 1010 (-960.50625989708055, 15.576003930653883)\n", | |
"0 1110 (-4398.7365426230754, 0.29208846922301746)\n", | |
"1 1110 (-1051.006721293078, 9.3212622555188318)\n", | |
"2 1110 (-947.15669172052594, 10.337691691247301)\n", | |
"3 1110 (-961.2669296071399, 15.994385843707164)\n", | |
"0 1210 (-4398.843301324262, 0.27995088339775975)\n", | |
"1 1210 (-1051.4665881258704, 9.372763350239893)\n", | |
"2 1210 (-947.70042367552696, 10.285647497025138)\n", | |
"3 1210 (-961.97475088305794, 16.398541104237665)\n", | |
"0 1310 (-4398.9267439337, 0.27063312804421003)\n", | |
"1 1310 (-1051.8695938759097, 9.4062550576870763)\n", | |
"2 1310 (-948.12290229289226, 10.178115630579669)\n", | |
"3 1310 (-962.67299781865472, 16.777003427183331)\n", | |
"0 1410 (-4399.0036260521774, 0.26202137877953646)\n", | |
"1 1410 (-1052.2767479562497, 9.4241563923483227)\n", | |
"2 1410 (-948.54271923107467, 10.125763551047612)\n", | |
"3 1410 (-963.29661823518734, 17.10479241831024)\n", | |
"0 1510 (-4399.0765006333149, 0.25400269263082009)\n", | |
"1 1510 (-1052.6521524042705, 9.4278280532398639)\n", | |
"2 1510 (-948.92348959849403, 10.083195522663914)\n", | |
"3 1510 (-963.88823570703426, 17.394351664440819)\n", | |
"0 1610 (-4399.141515858485, 0.2468372792336595)\n", | |
"1 1610 (-1052.9923541331409, 9.423718326379003)\n", | |
"2 1610 (-949.2442946241639, 10.042476609640858)\n", | |
"3 1610 (-964.45730090202721, 17.673802606047616)\n", | |
"0 1710 (-4399.195774085063, 0.24094253244129504)\n", | |
"1 1710 (-1053.318129304917, 9.4141151790629465)\n", | |
"2 1710 (-949.54754436608403, 10.005417921886419)\n", | |
"3 1710 (-964.98900777555787, 17.92882120033164)\n", | |
"0 1810 (-4399.2417890272663, 0.23586072698708449)\n", | |
"1 1810 (-1053.623259202602, 9.4004350987040652)\n", | |
"2 1810 (-949.87576321555957, 10.029504080201264)\n", | |
"3 1810 (-965.4925715460397, 18.151758665935176)\n", | |
"0 1910 (-4399.2771360427232, 0.23213925552045112)\n", | |
"1 1910 (-1053.9053202340979, 9.3831121179487127)\n", | |
"2 1910 (-950.19561548823754, 10.041374424887522)\n", | |
"3 1910 (-965.96998725706817, 18.358786651316223)\n", | |
"0 2010 (-4399.300406624694, 0.22997833960562275)\n", | |
"1 2010 (-1054.1744818659249, 9.3637019802408759)\n", | |
"2 2010 (-950.48270060717118, 10.037358319010536)\n", | |
"3 2010 (-966.44783189467739, 18.523598510719808)\n", | |
"0 2110 (-4399.3188087653571, 0.22827471152231738)\n", | |
"1 2110 (-1054.4271458009343, 9.3410102671191453)\n", | |
"2 2110 (-950.78014284322364, 10.042700923908683)\n", | |
"3 2110 (-966.87840898703723, 18.689471808336521)\n", | |
"0 2210 (-4399.3374998254585, 0.22640657826832467)\n", | |
"1 2210 (-1054.6693862868051, 9.3147736119333331)\n", | |
"2 2210 (-951.08379255239402, 10.063762785431663)\n", | |
"3 2210 (-967.31783185924769, 18.854763150536314)\n", | |
"0 2310 (-4399.3559540748456, 0.22449021963348059)\n", | |
"1 2310 (-1054.9038628174678, 9.2846819740852879)\n", | |
"2 2310 (-951.38424226248958, 10.093324075223904)\n", | |
"3 2310 (-967.76300886987246, 19.020488500822694)\n" | |
] | |
} | |
], | |
"source": [ | |
"# Now lets do the collection run\n", | |
"# set up the Minimizer\n", | |
"for j in range(20):\n", | |
" total_steps += 100\n", | |
" for i in range(4):\n", | |
" # do the sampling\n", | |
" res = mini[i].emcee(burn=burn, steps=100, thin=thin, ntemps=ntemps,\n", | |
" workers=workers, reuse_sampler=True)\n", | |
" # get the evidence\n", | |
" print(i, total_steps, mini[i].sampler.thermodynamic_integration_log_evidence())\n", | |
" log_evidence.append(mini[i].sampler.thermodynamic_integration_log_evidence()[0])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<matplotlib.text.Text at 0x104ed5320>" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZcAAAEPCAYAAACOU4kjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XucFNWZ//HPN6IIikZW4w28T1xQI4iKuZnJmri4+Qma\nYIQYFyMmhgneQmIEkzhJ1HhHjIqJskHI6pKsBmElKBImbrIiXgBRZIPXCKIbUUERlYHn90fVQDsO\nMz0z3VPdPd/369WvqTp1uuopS+aZc07VKUUEZmZmhfSRrAMwM7PK4+RiZmYF5+RiZmYF5+RiZmYF\n5+RiZmYF5+RiZmYFV3LJRVKtpBWSFqafE3K2jZW0XNIyScfnlA+QtCTdNiGbyM3MrEHJJRcggOsi\non/6+QOApL7AqUBfYBBwsySl35kIjIyIKqBK0qAsAjczs0QpJhcANVE2BLgzIjZExAvAM8BASXsC\nPSJiQVpvCnBSx4RpZmZNKdXkco6kxZImSfpoWrYXsCKnzgpg7ybKV6blZmaWkUySi6Q56RhJ489g\nki6u/YF+wCrg2ixiNDOztuuSxUEj4ov51JN0GzAzXV0J9M7Z3IukxbIyXc4tX9nEvjyJmplZG0RE\nU0MVzSq5brF0DKXBycCSdHkGMEzSdpL2B6qABRHxCrBW0sB0gP90YHpT+46Iiv1ccsklmcfg8/P5\ndbZz6wzn11aZtFxacKWkfiR3jT0PnA0QEUsl/RZYCtQDNbHlzGuAyUA3YFZEzO7wqM3MbLO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/plain": [ | |
"<matplotlib.figure.Figure at 0x105394438>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"plt.plot(log_evidence[-4:])\n", | |
"plt.ylabel('Log-evidence')\n", | |
"plt.xlabel('number of peaks')" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The Bayes factor is related to the exponential of the difference between the log-evidence values. Thus, 0 peaks is not very likely compared to 1 peak. But 1 peak is not as good as 2 peaks. 3 peaks is also not as good as 2 peaks" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"r01 = np.exp(log_evidence[-4] - log_evidence[-3])\n", | |
"r12 = np.exp(log_evidence[-3] - log_evidence[-2])\n", | |
"r23 = np.exp(log_evidence[-2] - log_evidence[-1])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"0.0 1.10153937106e-45 12978005.6223\n" | |
] | |
} | |
], | |
"source": [ | |
"print(r01, r12, r23)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"These numbers tell us that zero peaks is 0 times as likely as one peak. Two peaks is 9e44 times more likely than one peak. Two peaks is 1.3e7 times more likely than three peaks. However, caution has to be taken with these values. The log-priors for this sampling are uniform but improper, i.e. they are not normalised properly. Internally the lnprior probability is calculated as 0 if all parameters are within their bounds and `-np.inf` if any parameter is outside the bounds. The `lnprob` function defined above is the log-likelihood alone. Remember, that the log-posterior probability is equal to the sum of the log-prior and log-likelihood probabilities. Extra terms can be added to the lnprob function to calculate the normalised log-probability. These terms would look something like:\n", | |
"\n", | |
"$\\log \\left(\\prod_i \\frac{1}{\\max_i - \\min_i}\\right)$\n", | |
"\n", | |
"where $\\max_i$ and $\\min_i$ are the upper and lower bounds for the parameter, and the prior is a uniform distribution. Other types of prior are possible. For example, you might expect the prior to be Gaussian." | |
] | |
} | |
], | |
"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.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment