python_reference/tutorials/multiprocessing_intro.ipynb

1035 lines
116 KiB
Plaintext
Raw Normal View History

2014-06-19 20:04:42 +00:00
{
"metadata": {
"name": "",
2014-06-19 21:57:31 +00:00
"signature": "sha256:82b19ba527d6db0f573ef2e3b9d7924274ed0bf6d50c7e4f3325a8572b1c54f8"
2014-06-19 20:04:42 +00:00
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
2014-06-19 21:57:31 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Sebastian Raschka](http://sebastianraschka.com) \n",
"\n",
"- [Open in IPython nbviewer](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/tutorials/multiprocessing_intro.ipynb?create=1) \n",
"\n",
"- [Link to this IPython notebook on Github](https://github.com/rasbt/python_reference/blob/master/tutorials/multiprocessing_intro.ipynb) \n",
"\n",
"- [Link to the GitHub Repository python_reference](https://github.com/rasbt/python_reference)\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import time\n",
"print('Last updated: %s' %time.strftime('%d/%m/%Y'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Last updated: 19/06/2014\n"
]
}
],
"prompt_number": 21
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"I would be happy to hear your comments and suggestions. \n",
"Please feel free to drop me a note via\n",
"[twitter](https://twitter.com/rasbt), [email](mailto:bluewoodtree@gmail.com), or [google+](https://plus.google.com/+SebastianRaschka).\n",
"<hr>"
]
},
2014-06-19 20:04:42 +00:00
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Parallel processing via the `multiprocessing` module"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"CPUs with multiple cores have become the standard in the recent development of modern computer architectures, whether it is our desktop machine at home, our laptop, and especially supercomputer facilities. \n",
"\n",
"However, the default Python interpreter's GIL (Global Interpreter Lock) is designed for simplicity, and in order to prevent conflicts between threads, it executes only one statement at a time (so-called serial processing).\n"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"\n",
"Multi-Threading vs. Multi-Processesing\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2014-06-19 21:57:31 +00:00
"Depending on the application, two different approaches in parallel programming are either to run code via threads or multiple processes, respectively. If we submit \"jobs\" to different threads, those jobs can be pictured as \"sub-task\" of a single process and those threads will usually have access to the same memory areas (i.e., shared memory). This approach can easily lead to conflicts in case of improper synchronization, for example, if processes are writing to the same memory location at the same time. \n",
2014-06-19 20:04:42 +00:00
"\n",
"A safer approach (although less efficient due to the communication overhead between separate processes) is to submit multiple processes to completely separate memory locations (i.e., distributed memory): Every process will run completely independent from each other.\n",
"\n",
"Here, we will take a look at Python's [`multiprocessing`](https://docs.python.org/dev/library/multiprocessing.html) module and how we can use it to submit multiple processes that can run independently from each other in order to make best use of our CPU cores."
]
},
2014-06-19 21:57:31 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![](https://github.com/rasbt/python_reference/blob/master/Images/multiprocessing_scheme.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
2014-06-19 20:04:42 +00:00
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Sections"
]
},
2014-06-19 21:57:31 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- [Introduction to the multiprocessing module](#Introduction-to-the-multiprocessing-module)\n",
"\n",
" - [The Process class](#The-Process-class)\n",
" \n",
" - [Defining an own Process class](#Defining-an-own-Process-class)\n",
" \n",
" - [The Pool class](#The-Pool-class)\n",
" \n",
"- [Parzen kernel density estimation as benchmarking function](#Parzen-kernel-density-estimation-as-benchmarking-function)\n",
" \n",
" - [The Parzen-window method in a nutshell](#The-Parzen-window-method-in-a-nutshell)\n",
" \n",
" - [Sample data and timeit benchmarks](#Sample-data-and-timeit-benchmarks)\n",
" \n",
" - [Benchmarking functions](#Benchmarking-functions)\n",
" \n",
" - [Preparing the plotting of the results](#Preparing-the-plotting-of-the-results)\n",
"\n",
"- [Results](#Results)\n",
"\n",
"- [Conclusion](#Conclusion)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
2014-06-19 20:04:42 +00:00
{
"cell_type": "heading",
2014-06-19 21:57:31 +00:00
"level": 1,
2014-06-19 20:04:42 +00:00
"metadata": {},
"source": [
"Introduction to the `multiprocessing` module"
]
},
2014-06-19 21:57:31 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The [multiprocessing](https://docs.python.org/dev/library/multiprocessing.html) module in Python's Standard Libarary has a lot of powerful features. If you want to read about all the nitty-gritty tips, tricks, and details, I would recommend to use the [official documentation](https://docs.python.org/dev/library/multiprocessing.html) as an entry point. \n",
"\n",
"In the following sections, I want to provide a brief overview of different approaches to show how the `multiprocessing` module can be used for prallel programming."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
2014-06-19 20:04:42 +00:00
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"The `Process` class"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2014-06-19 21:57:31 +00:00
"The most basic approach is probably to use the `Process` class from the `multiprocessing` module. \n",
2014-06-19 20:04:42 +00:00
"Here, we will use a simple queue function to compute the cubes for the 6 numbers 1, 2, 3, 4, 5, and 6 in 6 parallel processes."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import multiprocessing as mp\n",
"\n",
"# Define an output queue\n",
"output = mp.Queue()\n",
"\n",
"# define a example function\n",
"def cube(x, output):\n",
" output.put(x**3)\n",
"\n",
"# Setup a list of processes that we want to run\n",
"processes = [mp.Process(target=cube, args=(x, output)) for x in range(1,7)]\n",
"\n",
"# Run processes\n",
"for p in processes:\n",
" p.start()\n",
"\n",
"# Exit the completed processes\n",
"for p in processes:\n",
" p.join()\n",
"\n",
"# Get process results from the output queue\n",
"results = [output.get() for p in processes]\n",
"\n",
"print(results)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[1, 8, 27, 64, 125, 216]\n"
]
}
],
2014-06-19 21:57:31 +00:00
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Defining an own `Process` class"
]
},
2014-06-19 21:57:31 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to top](#Sections)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also define our own `Process` classes based on the `multiprocessing.Process` parent-class. Note that we will define a `run` method, which will be automatically executed when we start a process-instance via `.start()`."
]
},
2014-06-19 20:04:42 +00:00
{
"cell_type": "code",
"collapsed": false,
"input": [
"class CubeProcess(mp.Process):\n",
" def __init__(self, x, output):\n",
" super(mp.Process, self).__init__()\n",
" self.x = x\n",
" self.queue = output\n",
" def run(self):\n",
" self.queue.put(self.x**3)"
],
"language": "python",
"metadata": {},
"outputs": [],
2014-06-19 21:57:31 +00:00
"prompt_number": 2
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Define an output queue\n",
"output = mp.Queue()\n",
"\n",
"# Setup a list of processes that we want to run\n",
"processes = [CubeProcess(x, output) for x in range(1,7)]\n",
"\n",
"# Run processes\n",
"for p in processes:\n",
" p.start()\n",
"\n",
"# Exit the completed processes\n",
"for p in processes:\n",
" p.join()\n",
"\n",
"# Get process results from the output queue\n",
"results = [output.get() for p in processes]\n",
"\n",
"print(results)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[1, 8, 27, 64, 125, 216]\n"
]
}
],
2014-06-19 21:57:31 +00:00
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"The `Pool` class"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2014-06-19 21:57:31 +00:00
"[[back to top](#Sections)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Another and more convenient approach for simple parallel processing tasks is provided by the `Pool` class. \n",
2014-06-19 20:04:42 +00:00
"\n",
"There are four methods that are particularly interesing:\n",
"\n",
" - Pool.apply\n",
" \n",
" - Pool.map\n",
" \n",
" - Pool.apply_async\n",
" \n",
" - Pool.map_async\n",
" \n",
"The `Pool.apply` and `Pool.map` methods are basically equivalents to Python's in-built [`apply`](https://docs.python.org/2/library/functions.html#apply) and [`map`](https://docs.python.org/2/library/functions.html#map) functions."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before we come to the `async` variants of the `Pool` methods, let us take a look at a simple example using `Pool.apply` and `Pool.map`. Here, we will set the number of processes to 4, which means that the `Pool` class will only allow 4 processes running at the same time."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def cube(x):\n",
" return x**3"
],
"language": "python",
"metadata": {},
"outputs": [],
2014-06-19 21:57:31 +00:00
"prompt_number": 4
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"pool = mp.Pool(processes=4)\n",
"results = [pool.apply(cube, args=(x,)) for x in range(1,7)]\n",
"print(results)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[1, 8, 27, 64, 125, 216]\n"
]
}
],
2014-06-19 21:57:31 +00:00
"prompt_number": 6
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"pool = mp.Pool(processes=4)\n",
"results = pool.map(cube, range(1,7))\n",
"print(results)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[1, 8, 27, 64, 125, 216]\n"
]
}
],
2014-06-19 21:57:31 +00:00
"prompt_number": 7
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2014-06-19 21:57:31 +00:00
"The `Pool.map` and `Pool.apply` will lock the main program until all processes are finished and return the results. The `async` variants, in contrast, will submit the processes to be run in the background without locking the main program, which can be quite useful for certain applications. \n",
2014-06-19 20:04:42 +00:00
"However, if we use this asynchronous approach, we need to use the `get` method in order to obtain the `return` values."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"pool = mp.Pool(processes=4)\n",
"results = [pool.apply_async(cube, args=(x,)) for x in range(1,7)]\n",
"output = [p.get() for p in results]\n",
"print(output)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[1, 8, 27, 64, 125, 216]\n"
]
}
],
2014-06-19 21:57:31 +00:00
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "heading",
2014-06-19 21:57:31 +00:00
"level": 1,
2014-06-19 20:04:42 +00:00
"metadata": {},
"source": [
"Parzen kernel density estimation as benchmarking function"
]
},
2014-06-19 21:57:31 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to top](#Sections)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the following approach, I want to do a simple comparison of a serial vs. multiprocessing approach where I will use a slightly more complex function than the `cube` example, which he have been using above. \n",
"\n",
"Here, I define a function for performing a Kernel density estimation for probability density functions using the Parzen-window technique. \n",
"I don't want to go into much detail about the theory of this technique, since we are mostly interested to see how `multiprocessing` can be used for performance improvements, but you are welcome to read my more detailed article about the [Parzen-window method here](http://sebastianraschka.com/Articles/2014_parzen_density_est.html). "
]
},
2014-06-19 20:04:42 +00:00
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"\n",
"def parzen_estimation(x_samples, point_x, h):\n",
2014-06-19 21:57:31 +00:00
" \"\"\"\n",
" Implementation of a hypercube kernel for Parzen-window estimation.\n",
"\n",
" Keyword arguments:\n",
" x_sample:training sample, 'd x 1'-dimensional numpy array\n",
" x: point x for density estimation, 'd x 1'-dimensional numpy array\n",
" h: window width\n",
" \n",
" Returns the predicted pdf as float.\n",
"\n",
" \"\"\"\n",
2014-06-19 20:04:42 +00:00
" k_n = 0\n",
" for row in x_samples:\n",
" x_i = (point_x - row[:,np.newaxis]) / (h)\n",
" for row in x_i:\n",
" if np.abs(row) > (1/2):\n",
" break\n",
" else: # \"completion-else\"*\n",
" k_n += 1\n",
" return (k_n / len(x_samples)) / (h**point_x.shape[1])"
],
"language": "python",
"metadata": {},
"outputs": [],
2014-06-19 21:57:31 +00:00
"prompt_number": 9
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"**A quick note about the \"completion else**\n",
"\n",
"Sometimes I receive comments about whether I used this for-else combination intentionally or if it happened by mistake. That is a legitimate question, since this \"completion-else\" is rarely used (that's what I call it, I am not aware if there is an \"official\" name for this, if so, please let me know). \n",
"I have a more detailed explanation [here](http://sebastianraschka.com/Articles/2014_deep_python.html#else_clauses) in one of my blog-posts, but in a nutshell: In contrast to a conditional else (in combination with if-statements), the \"completion else\" is only executed if the preceding code block (here the `for`-loop) has finished.\n",
"<hr>"
]
},
2014-06-19 21:57:31 +00:00
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"The Parzen-window method in a nutshell"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to top](#Sections)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So what this function does in a nutshell: It counts points in a defined region (the so-called window), and divides the number of those points inside by the number of total points to estimate the probability of a single point being in a certain region.\n",
"\n",
"Below is a simple example where our window is represented by a hypercube centered at the origin, and we want to get an estimate of the probability for a point being in the center of the plot based on the hypercube."
]
},
2014-06-19 20:04:42 +00:00
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline"
],
"language": "python",
"metadata": {},
"outputs": [],
2014-06-19 21:57:31 +00:00
"prompt_number": 10
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from mpl_toolkits.mplot3d import Axes3D\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from itertools import product, combinations\n",
"fig = plt.figure(figsize=(7,7))\n",
"ax = fig.gca(projection='3d')\n",
"ax.set_aspect(\"equal\")\n",
"\n",
"# Plot Points\n",
"\n",
"# samples within the cube\n",
"X_inside = np.array([[0,0,0],[0.2,0.2,0.2],[0.1, -0.1, -0.3]])\n",
"\n",
"X_outside = np.array([[-1.2,0.3,-0.3],[0.8,-0.82,-0.9],[1, 0.6, -0.7],\n",
" [0.8,0.7,0.2],[0.7,-0.8,-0.45],[-0.3, 0.6, 0.9],\n",
" [0.7,-0.6,-0.8]])\n",
"\n",
"for row in X_inside:\n",
" ax.scatter(row[0], row[1], row[2], color=\"r\", s=50, marker='^')\n",
"\n",
"for row in X_outside: \n",
" ax.scatter(row[0], row[1], row[2], color=\"k\", s=50)\n",
"\n",
"# Plot Cube\n",
"h = [-0.5, 0.5]\n",
"for s, e in combinations(np.array(list(product(h,h,h))), 2):\n",
" if np.sum(np.abs(s-e)) == h[1]-h[0]:\n",
" ax.plot3D(*zip(s,e), color=\"g\")\n",
" \n",
"ax.set_xlim(-1.5, 1.5)\n",
"ax.set_ylim(-1.5, 1.5)\n",
"ax.set_zlim(-1.5, 1.5)\n",
"\n",
"plt.show()\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
2014-06-19 21:57:31 +00:00
"png": "iVBORw0KGgoAAAANSUhEUgAAAZQAAAGUCAYAAAASxdSgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzsnXeUVOX9/9/3Tp/ZQpG6LCxNQUXEgCJIEVgWUIkRCwqK\nDdFEjTExNiwYG/zUX+QY2/fYYn5BiFEhAZYOFiKgIUG/iqgUkaZI2d2pt/3+WJ/rnbv3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iIlNtSSKRsH00rxaZLB1SUGnExeXkl1G9+ZAuAizL\nyptPsWeQtXa0YmyxWCztPVY+hgqMMaigFAF6tSXKnxca0LbS5eUGF1chkI2glFOUlbRGFx/5TpHN\nX8uCydaqX0tg4vF4Wnym1AWGCorLyTaal2EYV3YIJliVxeUkmTLIjLRxLwacWK+b6m700tCNHiKU\nVq7y70tdYKiguBi92pJ4PI5UKoVwOJz2AXUTRAiLoWdYoWTKIKMpysVDJkGzWmDIcweDwaIWGCoo\nLkTpylJ+CJXtUyoqKkzPijGr9QoAU1xcxep6UQtMtgrvUrDaWhtmC4yyjxl53Pz583H//ffbf3MF\nQD/JLoPUlhAxIR+uZDKJhoYGBAIBlJWVyadct226ZIYJz/OorKzMW0wync7cds/ZIMH9YDCISCSC\nUCgEj8cjpyhHo1G5qI7OgHGOQlxuRGD8fj9CoRAikYg8QptkYJI0f57nNT/DyhgOy7JYuXJlobdk\nO9RCcRF6Lq5oNCp33rVyNG+hGzXJ4gIgi54ZqE92xSYoatQpynrBX5K+3FpwUwylUIzE2ZQWjPq+\nBUEoSsuVCooLyNQ+hYxE1Wqf
2014-06-19 20:04:42 +00:00
"text": [
2014-06-19 21:57:31 +00:00
"<matplotlib.figure.Figure at 0x109e81f60>"
2014-06-19 20:04:42 +00:00
]
}
],
2014-06-19 21:57:31 +00:00
"prompt_number": 11
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"point_x = np.array([[0],[0],[0]])\n",
"X_all = np.vstack((X_inside,X_outside))\n",
"\n",
"print('p(x) =', parzen_estimation(X_all, point_x, h=1))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"p(x) = 0.3\n"
]
}
],
2014-06-19 21:57:31 +00:00
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Sample data and `timeit` benchmarks"
]
},
2014-06-19 21:57:31 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to top](#Sections)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the section below, we will create a random dataset from a bivariate Gaussian distribution with a mean vector centered at the origin and a identity matrix as covariance matrix. "
]
},
2014-06-19 20:04:42 +00:00
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"\n",
"np.random.seed(123)\n",
"\n",
"# Generate random 2D-patterns\n",
"mu_vec = np.array([0,0])\n",
"cov_mat = np.array([[1,0],[0,1]])\n",
2014-06-19 21:57:31 +00:00
"x_2Dgauss = np.random.multivariate_normal(mu_vec, cov_mat, 10000)"
2014-06-19 20:04:42 +00:00
],
"language": "python",
"metadata": {},
"outputs": [],
2014-06-19 21:57:31 +00:00
"prompt_number": 13
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The expected probability of a point at the center of the distribution is ~ 0.15915 as we can see below. \n",
"And our goal is here to use the Parzen-window approach to predict this density based on the sample data set that we have created above. \n",
"\n",
"\n",
"In order to make a \"good\" prediction via the Parzen-window technique, it is - among other things - crucial to select an appropriate window with. Here, we will use multiple processes to predict the density at the center of the bivariate Gaussian distribution using different window widths."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from scipy.stats import multivariate_normal\n",
"var = multivariate_normal(mean=[0,0], cov=[[1,0],[0,1]])\n",
"print('actual probability density:', var.pdf([0,0]))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"actual probability density: 0.159154943092\n"
]
}
],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Benchmarking functions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to top](#Sections)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Below, we will set up a benchmarking functions for our serial and multiprocessig approach that we can pass to our `timeit` benchmark function."
]
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def serial(samples, x, widths):\n",
" return [parzen_estimation(samples, x, w) for w in widths]\n",
"\n",
"def multiprocess(processes, samples, x, widths):\n",
2014-06-19 21:57:31 +00:00
" pool = mp.Pool(processes=processes)\n",
2014-06-19 20:04:42 +00:00
" return [pool.apply(parzen_estimation, args=(samples, x, w)) for w in widths]"
],
"language": "python",
"metadata": {},
"outputs": [],
2014-06-19 21:57:31 +00:00
"prompt_number": 15
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Just to get an idea what the results would look like (i.e., the predicted densities for different window widths):"
]
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widths = np.arange(0.1, 1.3, 0.1)\n",
"point_x = np.array([[0],[0]])\n",
"results = []\n",
"\n",
2014-06-19 21:57:31 +00:00
"results = multiprocess(4, x_2Dgauss, point_x, widths)\n",
"for w,r in zip(widths, results):\n",
" print('h = %s, p(x) = %s' %(w, r))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"h = 0.1, p(x) = 0.016\n",
"h = 0.2, p(x) = 0.0305\n",
"h = 0.3, p(x) = 0.045\n",
"h = 0.4, p(x) = 0.06175\n",
"h = 0.5, p(x) = 0.078\n",
"h = 0.6, p(x) = 0.0911666666667\n",
"h = 0.7, p(x) = 0.106\n",
"h = 0.8, p(x) = 0.117375\n",
"h = 0.9, p(x) = 0.132666666667\n",
"h = 1.0, p(x) = 0.1445\n",
"h = 1.1, p(x) = 0.157090909091\n",
"h = 1.2, p(x) = 0.1685\n"
]
}
],
"prompt_number": 16
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Based on the results, we can say that the best window-width would be h=1.1, since the estimated result is close to the actual result ~0.15915."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import timeit\n",
"\n",
"mu_vec = np.array([0,0])\n",
"cov_mat = np.array([[1,0],[0,1]])\n",
"n = 100000\n",
"\n",
"x_2Dgauss = np.random.multivariate_normal(mu_vec, cov_mat, n)\n",
"\n",
"benchmarks = []\n",
"\n",
"benchmarks.append(timeit.Timer('serial(x_2Dgauss, point_x, widths)', \n",
2014-06-19 20:04:42 +00:00
" 'from __main__ import serial, x_2Dgauss, point_x, widths').timeit(number=1))\n",
"\n",
2014-06-19 21:57:31 +00:00
"benchmarks.append(timeit.Timer('multiprocess(2, x_2Dgauss, point_x, widths)', \n",
2014-06-19 20:04:42 +00:00
" 'from __main__ import multiprocess, x_2Dgauss, point_x, widths').timeit(number=1))\n",
"\n",
2014-06-19 21:57:31 +00:00
"benchmarks.append(timeit.Timer('multiprocess(3, x_2Dgauss, point_x, widths)', \n",
2014-06-19 20:04:42 +00:00
" 'from __main__ import multiprocess, x_2Dgauss, point_x, widths').timeit(number=1))\n",
"\n",
2014-06-19 21:57:31 +00:00
"benchmarks.append(timeit.Timer('multiprocess(4, x_2Dgauss, point_x, widths)', \n",
2014-06-19 20:04:42 +00:00
" 'from __main__ import multiprocess, x_2Dgauss, point_x, widths').timeit(number=1))\n",
"\n",
2014-06-19 21:57:31 +00:00
"benchmarks.append(timeit.Timer('multiprocess(6, x_2Dgauss, point_x, widths)', \n",
2014-06-19 20:04:42 +00:00
" 'from __main__ import multiprocess, x_2Dgauss, point_x, widths').timeit(number=1))"
],
"language": "python",
"metadata": {},
2014-06-19 21:57:31 +00:00
"outputs": [],
"prompt_number": 17
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Preparing the plotting of the results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to top](#Sections)]"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import platform\n",
"\n",
"def print_sysinfo():\n",
" \n",
" print('\\nPython version :', platform.python_version())\n",
" print('compiler :', platform.python_compiler())\n",
" \n",
" print('\\nsystem :', platform.system())\n",
" print('release :', platform.release())\n",
" print('machine :', platform.machine())\n",
" print('processor :', platform.processor())\n",
" print('CPU count :', mp.cpu_count())\n",
" print('interpreter:', platform.architecture()[0])\n",
" print('\\n\\n')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"\n",
"def plot_results():\n",
" bar_labels = ['serial', '2', '3', '4', '6']\n",
"\n",
" fig = plt.figure(figsize=(10,8))\n",
"\n",
" # plot bars\n",
" y_pos = np.arange(len(benchmarks))\n",
" y_pos = [x for x in y_pos]\n",
" plt.yticks(y_pos, bar_labels, fontsize=16)\n",
" plt.barh(y_pos, benchmarks,\n",
" align='center', alpha=0.4, color='g')\n",
"\n",
" # annotation and labels\n",
" plt.xlabel('time in seconds for n=%s' %n, fontsize=14)\n",
" plt.ylabel('number of processes', fontsize=14)\n",
" t = plt.title('Serial vs. Multiprocessing via Parzen-window estimation', fontsize=18)\n",
" plt.ylim([-1,len(benchmarks)+0.5])\n",
" plt.grid()\n",
"\n",
" plt.show()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<br>\n",
"<br>"
]
},
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[[back to top](#Sections)]"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"plot_results()\n",
"print_sysinfo()"
],
"language": "python",
"metadata": {},
2014-06-19 20:04:42 +00:00
"outputs": [
{
2014-06-19 21:57:31 +00:00
"metadata": {},
"output_type": "display_data",
"png": "iVBORw0KGgoAAAANSUhEUgAAAoIAAAIACAYAAAAWiA3GAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALE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RWVOyjanGl0ul6NqNI1dww6zbds2xcbG5tgESlLJkiW9li1ZskTNmzdX8eLF\nFRERoZtuuinHrUrZM0rffPONWrRooeuuu8797i2nGUHbtjV06FA1btxYpUuXVlhYmBISEtS7d28d\nOXLkqm7f5s2b5XK59Mwzz+R4focOHRQWFqbffvtNkvTzzz+rW7duSkhIUHh4uEqWLKnbb79dU6dO\nvarrv1jXrl119OhRzZkzx2P5pEmTFB8frzZt2nj9TvYsyYoVK7zO82UesEKFClqxYoV7bib7J/vy\ncpoRzF52+PBhderUSXFxcSpSpIjuvPNOffPNNx7rXjyP8/HHH+vmm29WZGSknnrqKfc648ePV716\n9RQZGanrrrtOLVq00OrVq3Osd/ny5WrdurViY2MVERGhypUrq3v37u77J9vHH3+sO+64Q9HR0YqK\nitJtt92mTz/91Ovy5s+fr+TkZJUoUUKRkZFKSEjQ/fffr23btrnX8eU+z2nu6OJl8+bNU/369RUR\nEaEyZcpowIABOnfunFc9n376qW666SZFREQoISFBL730kpYsWeLTSMBzzz0nl8uljRs3ep13/Phx\nRUREqF27du5lOc0ILlq0SA899JAqVaqkyMhIFS9eXC1atMjx8ZVXzZs3lyTt2LEjz9eV/VjetWuX\nHnjgAcXExLi3oly6K/rin0tv37p169SuXTuVKFFC4eHhqlGjhl555RWv+yL7+g4cOKAOHTooJiZG\nUVFRatmypcdj40q6du2qiIgI/f777+5la9eulcvlUmxsrEcD8Pnnn8vlcmnmzJnuZTnNCGYvW7t2\nrZKTk1WkSBHFxcWpR48eOnnypFcNq1at0u23367IyEiVKlVKTz31lDIzM3Os9+TJk3r++edVuXJl\nhYeHq3Tp0urcubP27NnjXuf3339XRESEunTp4vG7PXv2lMvl0l//+leP5Q899JCKFSum8+fP55rX\ntm3b1LFjR/dre8WKFTVgwACdOnXKY73cno+TJ09WamqqpAv3waWPhdyeq5988onq1KmjyMhIValS\nRePHj5ckpaen64EHHlBsbKyio6PVsWNHryy3bNmi3r1764YbbnC/9iQlJWnChAke63Xp0kUvvfSS\nJKlixYruGrOXXe51/fDhw+rTp4/KlSunsLAwlS9fXn379vX6+5f9+8uXL9eIESPc92n16tXz5W+V\nv7FF0GGqVKmiBQsWaPbs2R5/RC7n/fffV69evdSwYUP94x//UFRUlBYtWqQnn3xSO3bs0Ouvv+5e\n17Is7dmzR02bNtWDDz6o9u3bez2xLt5S9fvvv2vEiBF64IEH1K5dO0VFRenrr7/WhAkTtGrVKq1f\nvz7PWzlq1qyp+vXra/r06Ro+fLhH03PixAnNnTtXrVq1UmxsrP744w81a9ZM+/fvV58+fVStWjUd\nP35c3333nVatWqVOnTrl6bovvZ1169ZVnTp1NHHiRD344IOSLuwe+uijj/T4449f1Rac3Hb9jRo1\nSs8//7wOHz6st956y728Zs2auV5Gy5YtFRsbqxdffFEHDhzQ6NGjlZycrLVr1+qGG27wWHfOnDna\ns2ePevfurd69eys6OlrSheZl+PDhuvXWWzVs2DCdOHFC77//vlJSUjR37lzddddd7ssYO3asnnzy\nSZUrV059+vRRQkKC0tPTNW/ePO3bt8+9u/Ef//iHXnnlFd111116+eWX5XK5NGvWLLVv316jR49W\n7969JUlffvml2rZtq9q1a2vgwIG67rrrtG/fPi1dulQ7duxQ1apV83yf55TVggUL9N577+nJJ59U\n9+7dNWfOHI0YMULFixfX888/717v448/VocOHVS1alUNGTJEISEhmjJliv7973/7dF926dJFw4cP\n19SpUzV8+HCP82bMmKHff//d4w94TjNIU6ZM0bFjx9SlSxddf/312rt3r8aPH6+mTZtq+fLluuOO\nO65Yw5VkN1BxcXF5vi7LspSZmank5GTdcccdGjZsmA4dOiTpwmP40iboq6++0ujRo1WqVCn3svnz\n5+u+++5TtWrV1L9/f8XExGjNmjV64YUX9O2332rGjBke13fy5Ek1btxYDRo00LBhw7Rz506NGjVK\n99xzj3744YdcP0TVtGlTTZkyRatXr3Y3JkuXLpXL5dKxY8f0zTffqF69epKkZcuW5di45nSff/vt\nt7r77rvVrVs3PfbYY1q+fLkmTJggl8vl8Yb7P//5j+68804VK1ZMf//731WsWDH9v//3/3J8k3X2\n7Fm1aNFCa9asUfv27fXss8/qp59+0pgxY7Ro0SKtW7dOZcuWVVhYmG6//XYtX77c4/ezb9eyZcvc\ny2zbVlpamho3bpxrVuvXr1dqaqpiYmL05JNPqmzZsvr222/19ttva/Xq1fryyy9VqFAhn56PycnJ\nGjhwoF555RX17NlTjRo1kuS90SKnbOfNm6d//etf6tOnj2JiYjR+/Hg98cQTCgkJ0eDBg9WsWTMN\nGzZMX3/9tSZOnKjw8HCNGzfO/ftffvmlVq5cqbZt26pixYo6efKkZsyYoR49eujXX3/V3//+d0lS\nr169lJGRodmzZ+utt95yPydq16592YyOHz+uhg0baseOHXr88cdVr149bdiwQWPGjNGyZcv09ddf\ne+1lGThwoE6fPq0nn3xSoaGhGjNmjLp06aIqVaqoYcOGV7xPAsqGo6xdu9YODQ21Lcuyq1atanft\n2tUeM2aMvXnzZq919+/fb4eFhdmPPvqo13n9+vWzQ0JC7J07d7qXJSQk2JZl2RMmTPBaf/ny5bZl\nWfaUKVM8lp8+fdpr3QkTJtiW
"text": [
"<matplotlib.figure.Figure at 0x10b49e438>"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"Python version : 3.4.1\n",
"compiler : GCC 4.2.1 (Apple Inc. build 5577)\n",
"\n",
"system : Darwin\n",
"release : 13.2.0\n",
"machine : x86_64\n",
"processor : i386\n",
"CPU count : 4\n",
"interpreter: 64bit\n",
"\n",
"\n",
"\n"
2014-06-19 20:04:42 +00:00
]
}
],
2014-06-19 21:57:31 +00:00
"prompt_number": 20
2014-06-19 20:04:42 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2014-06-19 21:57:31 +00:00
"<br>\n",
"<br>"
2014-06-19 20:04:42 +00:00
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
2014-06-19 21:57:31 +00:00
"Conclusion"
2014-06-19 20:04:42 +00:00
]
},
{
2014-06-19 21:57:31 +00:00
"cell_type": "markdown",
2014-06-19 20:04:42 +00:00
"metadata": {},
"source": [
2014-06-19 21:57:31 +00:00
"[[back to top](#Sections)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that we could speed up the density estimations for our Parzen-window function if we submitted them in parallel.\n",
"However, on my particular machine it didn't make any differences if we submitted 2, 3, 4, or 6 processes in parallel. \n",
"\n",
"In practice, it doesn't make much sense to submit more processes than the CPU supports (e.g., here 6 processes for a 4-core CPU). For larger benchmarks, this would to a slower performace, because of an additional overhead for communicating between the additional processes."
2014-06-19 20:04:42 +00:00
]
}
],
"metadata": {}
}
]
}