{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Modules Imported!\n" ] } ], "source": [ "# loading some libraries\n", "\n", "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import matplotlib.patches as patches\n", "import numpy as np\n", "import scipy as sp\n", "import scipy.stats as st\n", "from math import sqrt\n", "print(\"Modules Imported!\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### A simple Bayesian Network: Conditional and joint distributions\n", "Let us construct a simple network in which Traffic and Charlie influence Bob being on time or not as discussed in class. One of the goals of this excercise is just to get used to Numpy arrays. \n", "\n", "We let" ] }, { "cell_type": "code", "execution_count": 193, "metadata": { "collapsed": true }, "outputs": [], "source": [ "TrafficPD = np.zeros(2)\n", "TrafficPD[0] = .65\n", "TrafficPD[1] = 1 - TrafficPD[0]\n", "\n", "CharliePD = np.zeros(2)\n", "CharliePD[0] = .9\n", "CharliePD[1] = 1 - CharliePD[0]\n", "\n", "BobCPD = np.zeros((2,2,2)) # 1st index Bob, 2nd index Charlie, 3rd index Traffic: BobCPD(i,j,k) = Pr(B=i|C=j,T=k)\n", "BobCPD[1] = [[0.1,1/3],[1/4,1]]\n", "BobCPD[0] = 1 - BobCPD[1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Find the following quantities: \n", "- joint probability distribution for all variables\n", "- $\\Pr(T=1\\mid B=1)$\n", "- $\\Pr(T=1\\mid B=1,C=1)$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "AllPD = np.zeros((2,2,2)) # AllPD(i,j,k) = Pr(B=i,C=j,T=k)\n", "# ..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## MRF denoising\n", "In this excercise, we will use an iterative approach to denoise an image. \n", "\n", "The first code segment below allows us to plot an image that is represented by a square Numpy binary array. Each cell of the array represents a \"pixel\". The second generates and plots such an image. We then add to this image some noise. " ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def draw(A):\n", " n = len(A)\n", " fig,ax = plt.subplots()\n", " ax.set_aspect(\"equal\")\n", " for i in range(n):\n", " for j in range(n):\n", " if A[i,j]==1:\n", " ax.add_patch(\n", " patches.Rectangle(\n", " (i/n, j/n),\n", " 1/n,\n", " 1/n\n", " )\n", " )\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQYAAAD8CAYAAACVSwr3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADMhJREFUeJzt3X+o3fV9x/Hna0kzVtupNLfFJRGzEavZWofeWillsyub\niRmEgn+oZW7SEoRa+qdhsHbgP0oZSPFHCBKk/zT/VLp0pnWjo3XgXHMDaoyi3EVrEgWjFgcWJpe8\n98c9607P5yb3e+P3nJPrng+4cL/f7+fe876XnGe+53u/N0lVIUnDfmvaA0g6/xgGSQ3DIKlhGCQ1\nDIOkhmGQ1Fg2DEn2JXkjyXNnOJ4k30kyn+TZJFf3P6akSepyxvAIsO0sx7cDWwZvu4CH3v9YkqZp\n2TBU1RPA22dZshP4bi16CrgoySV9DShp8tb28Dk2AMeHtk8M9r0+ujDJLhbPKrjggguuueKKK3p4\neI3LkZPvnPX4pzZcOKFJdK4OHz78ZlXNrPTj+ghDZ1W1F9gLMDs7W3Nzc5N8eK3QZbsfO+vxuXt2\nTGgSnaskvziXj+vjpxIngU1D2xsH+yStUn2E4QBw2+CnE9cB71RV8zJC0uqx7EuJJN8DrgfWJzkB\nfAv4EEBV7QEOAjcC88CvgNvHNaykyVg2DFV1yzLHC/habxNJmjrvfJTUMAySGoZBUsMwSGoYBkkN\nwyCpYRgkNQyDpIZhkNQwDJIahkFSwzBIahgGSQ3DIKlhGCQ1DIOkhmGQ1DAMkhqGQVLDMEhqGAZJ\nDcMgqWEYJDUMg6SGYZDUMAySGoZBUsMwSGoYBkkNwyCpYRgkNQ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YPP6ZrPg5Nu4wnOlW6ZWumYSVzvEVFis8LcvOm2QD8CWm/0ttXb63lwMXJ/lp\nksNJbpvYdK0u894PXAm8BhwBvlFVpycz3oqt+Dk20VuiPyiSfIHFMHx+2rMs4z7grqo6vfgX23lt\nLXAN8EXgd4B/T/JUVb003bHO6AbgaeDPgD8A/iXJv1XVf013rH6MOwyr6XbqTnMk+TTwMLC9qt6a\n0GxL6TLvLLB/EIX1wI1JFqrqB5MZ8de6zHoCeKuq3gXeTfIEcBUwjTB0mfd24J5afBE/n+Rl4Arg\n55MZcUVW/hwb80WRtcAxYDP/dxHnD0fW7OA3L4z8fEoXcLrMeimLd3d+bhozrnTekfWPML2Lj12+\nt1cCPxms/TDwHPBH5/G8DwF/P3j/E4Mn2vop/nm4jDNffFzxc2ysZww1vtuppzXrN4GPAQ8O/hZe\nqCn9pl3Hec8LXWatqheS/Bh4FjgNPFxVU/m1/I7f27uBR5IcYfEJd1dVTeXXsZN8D7geWJ/kBPAt\n4ENDs674OeYt0ZIa3vkoqWEYJDUMg6SGYZDUMAySGoZBUsMwSGr8D4y4iH4CwyTKAAAAAElFTkSu\nQmCC\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQYAAAD8CAYAAACVSwr3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEMxJREFUeJzt3X+oZPV5x/H3p6tbGpOqZDfB3l1xW9aorbHoREOQxjRY\ndzWwBPxDDbWRhEXIhvypFJoU8s9KWtDgj+UiWwmF7D+RdNtsYktLasBad7YY111RbtfGvavg9QcW\nDFQu+/SPmZuczHfuzpm55+eczwsu3DPnzMxzzr3zzPN8z3fOKCIwM8v6rboDMLPmcWIws4QTg5kl\nnBjMLOHEYGYJJwYzS0xMDJIOSnpT0ovrrJek70pakvSCpGuLD9PMqpSnYngC2HWO9buBncOfvcBj\nGw/LzOo0MTFExNPAO+fYZA/wvR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8FHg0eG78GrU\n9Em7nPE2Qp5YI+IlST8BXgDOMrhS2Mwfyy87XuDbwBOSjjN4wd0XEbV8HFvS94GbgC2SloFvAedn\nYp36NeYp0WaW8MxHM0s4MZhZwonBzBJODGaWcGIws4QTg5klnBjMLPH/2RckhTqqu7oAAAAASUVO\nRK5CYII=\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "a = 20 # when testing choose a smaller number for a, say a = 6, for faster computation\n", "n = 4*a+1\n", "x = np.zeros((n,n))\n", "x[:,2*a-1:2*a+2] = 1\n", "x[a-1:3*a+2,a-1:a+2] = 1\n", "x[a-1:3*a+2,3*a-1:3*a+2] = 1\n", "x = x + np.transpose(x)\n", "x = x>0\n", "N = st.bernoulli.rvs(0.02,size=(n,n))\n", "y = np.mod(x + N, 2)\n", "\n", "# switching from {0,1} to {-1,+1}\n", "x = 2*x-1\n", "y = 2*y-1\n", "draw(x)\n", "draw(y)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now suppose that the true image and its noisy version have a joint Boltzmann distribution, $\\Pr(x,y)=e^{-E(x,y)}$, with energy function $E(x,y) = -\\sum_{i,j} x_ix_j - 2 \\sum_i x_iy_i$, where the range of the first sum is over adjacent pixels. \n", "\n", "Write a function that denoises the noisy image $y$ as follows. This is done by first setting $\\hat x = y$ and then at each step, a pixel is chosen, i.e., some $\\hat x_i$. The value of $\\hat x_i$ is chosen so that $\\Pr(\\hat x, y)=e^{-E(\\hat x,y)}$ is maximized. The order of pixels that are chosen may be arbitrary but here let us choose them by scanning each row, and go through the whole image a couple of times. Denoise $y$ and plot both $\\hat x$ and $y$." ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def denoise(y):\n", " xhat = np.copy(y) # need to create a copy so that y is not altered. Python is weird that way!\n", " # ...\n", " return xhat" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "scrolled": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANS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uY951oUvWqnomyQ+BJ4E3gfur\naiYvy+94334VeCDJMZYecHdW1Uxejp3k28C1wCVJTgJfAd42knXFjzGXREtquPJRUsNikNSwGCQ1\nLAZJDYtBUsNikNSwGCQ1/h+VpOdEpwVLkwAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "draw(y)\n", "xhat = denoise(y)\n", "draw(xhat)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }