Created
October 27, 2020 12:25
-
-
Save LuxXx/b134d6456ad2d79b91f03ca387d664ce to your computer and use it in GitHub Desktop.
Metropolis Hastings Algorithm
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": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import matplotlib.pyplot as plt\n", | |
"from scipy.integrate import quad" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# may be unnormalized\n", | |
"def target(x):\n", | |
" if x < 0:\n", | |
" return 0\n", | |
" return np.exp(-x)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# may be unnormalized\n", | |
"def target(x):\n", | |
" return 1/(np.sqrt(2*np.pi)) * np.exp(-x**2 / 2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# may be unnormalized\n", | |
"def target(x):\n", | |
" return np.exp(-x**2 / 2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# may be unnormalized\n", | |
"def target(x):\n", | |
" return np.sin(x)**2 * np.sin(2*x)**2 * np.exp(-x**2 / 2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"x = np.zeros(10000)\n", | |
"x[0] = 3\n", | |
"for i in range(1, len(x)):\n", | |
" curr_x = x[i-1]\n", | |
" prop_x = curr_x + np.random.normal(0, 1)\n", | |
" a = target(prop_x) / target(curr_x)\n", | |
" if np.random.uniform() < a:\n", | |
" x[i] = prop_x\n", | |
" else:\n", | |
" x[i] = curr_x" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.5840424474631826" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"N = quad(target, -np.inf, np.inf)[0]\n", | |
"N" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[<matplotlib.lines.Line2D at 0x194f8310>]" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3XmYXHWV8PHvqeruJN3pTtJLNhLoAAEJiDBGFlEGFccwanAfcJlxRmV8X2HcxpkgyoyoMwz4uiC4oDI6iDKIiIFEA8ouAZNAgISAJDEknXSS3qv37qo67x/3VnWl00t19626S5/P8/CkqvrWvccyOXX6/JYrqooxxphoifkdgDHGGO9ZcjfGmAiy5G6MMRFkyd0YYyLIkrsxxkSQJXdjjIkgS+7GGBNBltyNMSaCLLkbY0wElfh14draWq2vr/fr8sYYE0pbtmxpVtW68Y7LK7mLyCrgW0Ac+KGqXjvs598A3uA+LQfmq+rcsc5ZX1/P5s2b87m8McYYl4i8nM9x4yZ3EYkDNwFvBhqATSKyVlWfzxyjqp/OOf4K4MwJR2yMMcYz+fTczwJ2qupuVR0AbgcuHuP4S4GfexGcMcaYycknuR8D7Mt53uC+dhQROQ5YBjww9dCMMcZMVj7JXUZ4bbR9g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Kq9oBOR2cAvgU8N++3VN6qactujS4CzROQ0v2MSkbcBh1V1hDul+O48Vf0LnLbkJ0TE9zu/F307RVW9MM9DfwasA/6tgOFkjReXiPwd8DbgTcVefTuBz8xP+WxTYYYRkVKcxH6bqt7ldzzDqWq7iDyEM2bh94D0ecBqEflrYCZQJSI/VVXf95BW1QPun4dF5Fc4bUpfx8EC1ZYRkeU5T1cDL/gVSy4RWQX8K7BaVXv8jieg8tmmwuQQEcFZ3b1DVb/udzwZIlKXmREmIrOACwnAv0VVvVJVl6hqPc7frweCkNhFpEJEKjOPgb/C/y/CYCV34Fq33fAszgcUiKlhwI1AJXC/O9Xpe34HlCEi7xSRBuBcYJ2IbPAjDnfAObNNxQ7gDlXd7kcsw4nIz4GNwMki0iAiH/E7Jtd5wIeAN7p/r7a6VanfFgEPuv8ON+H03AMz7TCAFgCPicgzwB+Bdar6W59jshWqxhgTRUGr3I0xxnjAkrsxxkSQJXdjjIkgS+7GGBNBltyNMSaCLLkbY0wEWXI3xpgIsuRujDER9P8BtSd1JqHhvXsAAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<Figure size 432x288 with 1 Axes>" | |
] | |
}, | |
"metadata": { | |
"needs_background": "light" | |
}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"plt.hist(x, bins=100, density=True)\n", | |
"f = np.vectorize(target)(np.linspace(np.min(x), np.max(x), 1000)) / N\n", | |
"plt.plot(np.linspace(np.min(x), np.max(x), 1000), f)" | |
] | |
} | |
], | |
"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.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment