{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**Update 1**: A more complete and updated speed comparison can be found [here](http://rlhick.people.wm.edu/posts/comparing-the-speed-of-matlab-versus-pythonnumpy-partii.html).\n", "\n", "**Update 2**: Python and Matlab code edited on 4/5/2015.\n", "\n", "In this short note, we compare the speed of matlab and the scientific computing platform of python for a simple bootstrap of an ordinary least squares model. Bottom line (with caveats): matlab is faster than python with this code. One might be able to further optimize the python code below, but it isn't an obvious or easy process (see for example [advanced optimization techniques](http://scipy-lectures.github.io/advanced/optimizing/)).\n", "\n", "As an aside, this note demonstrates that even if one can't optimize python code significantly enough, it is possible to do computationally expensive calculations in matlab and return results to the ipython notebook. \n", "\n", "## Data Setup\n", "\n", "We will bootstrap the ordinary least squares model (ols) using 1000 replicates. For generating the toy dataset, the true parameter values are\n", "$$\n", "\\beta=\\begin{bmatrix}\n", "10\\\\-.5\\\\.5\n", "\\end{bmatrix}\n", "$$\n", "\n", "We perform the experiment for 3 different sample sizes (\\\$$n = \\begin{bmatrix}1,000 & 10,000 & 100,000 \\end{bmatrix}\\\$$). For each of the observations in the toy dataset, the independent variables are drawn from\n", "\n", "$$\n", "\\mu_x = \\begin{bmatrix} 10\\\\10 \\end{bmatrix}, \\sigma_x = \\begin{bmatrix} 4 & 0 \\\\ 0 & 4 \\end{bmatrix}\n", "$$\n", "\n", "The dependent variable is constructed by drawing a vector of random normal variates from Normal(0,1). Denoting this vector as \\\$$\\epsilon\\\$$ calculate the dependent variable as\n", "$$\n", "\\mathbf{Y=Xb+\\epsilon}\n", "$$\n", "\n", "\n", "## What is timed\n", "\n", "In the code below, the data generation steps described above are not timed. For comparison purposes, we only include the steps required for the bootstrap process. This includes:\n", "\n", "1. Sampling rows of data with replacement\n", "2. Calculating parameter estimates for the OLS model\n", "3. Storing results\n", "\n", "For these steps, we have done some basic code optimization in both python and matlab by preallocating arrays/matrices.\n", "\n", "It is also important to note that we use built-in functions for calculating parameter estimates (ols for matlab and statsmodels.regression.linear_model.OLS for python). If these functions aren't optimized for speed, then these results will obviously be skewed towards that package having the more optimized linear regression model function." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Starting MATLAB on ZMQ socket ipc:///tmp/pymatbridge\n", "Send 'exit' command to kill the server\n", ".MATLAB started and connected!\n" ] } ], "source": [ "%matplotlib inline\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "import numpy as np\n", "import pandas as pd\n", "import statsmodels.api as sm\n", "from timeit import timeit\n", "%load_ext pymatbridge" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "reps, beta, n_array = 1000, [10,-.5,.5], [1000, 10000, 100000]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Run the bootstrap in Matlab" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%%matlab -i reps,beta,n_array -o mat_time,store_beta\n", "\n", "mat_time = zeros(cols(n_array),2);\n", " \n", "for i=1:3\n", "n=n_array(i);\n", "row_id =1:n;\n", "\n", "X = [normrnd(10,4,[n 2]) ones(n,1)]; \n", " \n", "Y = X*beta' + normrnd(0,1,[n 1]);\n", "\n", " store_beta = zeros(reps,3); \n", " tic\n", " for r = 1:reps\n", " this_row = randsample(row_id,n,true);\n", " store_beta(r,:) = (ols(Y(this_row),X(this_row,:)))'; \n", " end\n", " mat_time(i,:) = [n toc];\n", "end" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Here are the Matlab results for n = 100,000\n" ] }, { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
b0b1b2
count 1000.000000 1000.000000 1000.000000
mean 9.999913 -0.501554 0.518378
std 0.000820 0.000785 0.011911
min 9.996906 -0.503905 0.486200
25% 9.999368 -0.502104 0.510149
50% 9.999908 -0.501557 0.518545
75% 10.000502 -0.501017 0.526612
max 10.002367 -0.499192 0.554077
\n", "
" ], "text/plain": [ " b0 b1 b2\n", "count 1000.000000 1000.000000 1000.000000\n", "mean 9.999913 -0.501554 0.518378\n", "std 0.000820 0.000785 0.011911\n", "min 9.996906 -0.503905 0.486200\n", "25% 9.999368 -0.502104 0.510149\n", "50% 9.999908 -0.501557 0.518545\n", "75% 10.000502 -0.501017 0.526612\n", "max 10.002367 -0.499192 0.554077" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "matlab_results = pd.DataFrame(store_beta.copy(),columns=['b0','b1','b2'])\n", "print \"Here are the Matlab results for n = 100,000\"\n", "matlab_results.describe()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Run the bootstrap in python" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def python_boot():\n", " for r in np.arange(reps):\n", " this_sample = np.random.choice(row_id, size=n, replace=True) # gives sampled row numbers\n", " # Define data for this replicate: \n", " X_r = X[this_sample,:]\n", " Y_r = Y[this_sample]\n", " # Estimate model \n", " store_beta[r,:] = sm.regression.linear_model.OLS(Y_r,X_r).fit(disp=0).params " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "python_time = np.zeros((len(n_array),2))\n", "count=0\n", "\n", "for n in n_array:\n", " # Constructs toy data\n", " row_id = range(0,n)\n", " X1 = np.random.normal(10,4,(n,1))\n", " X2 = np.random.normal(10,4,(n,1))\n", " X=np.append(X1,X2,1)\n", " X = np.append(X,np.tile(1,(n,1)),1)\n", " error = np.random.randn(n,1)\n", " Y = np.dot(X,beta).reshape((n,1)) + error\n", " \n", " store_beta = np.zeros((reps,X.shape[1]))\n", " TimeIt = timeit(\"python_boot()\", setup=\"from __main__ import python_boot\", number=1)\n", " python_time[count,:] = [n,TimeIt]\n", " count=count+1" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Here are the results for n = 100,000\n" ] }, { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
b0b1b2
count 1000.000000 1000.000000 1000.000000
mean 10.001015 -0.501155 0.501976
std 0.000806 0.000773 0.011775
min 9.998609 -0.503459 0.461239
25% 10.000454 -0.501663 0.494047
50% 10.000983 -0.501155 0.502325
75% 10.001581 -0.500628 0.509737
max 10.004093 -0.498803 0.546887
\n", "
" ], "text/plain": [ " b0 b1 b2\n", "count 1000.000000 1000.000000 1000.000000\n", "mean 10.001015 -0.501155 0.501976\n", "std 0.000806 0.000773 0.011775\n", "min 9.998609 -0.503459 0.461239\n", "25% 10.000454 -0.501663 0.494047\n", "50% 10.000983 -0.501155 0.502325\n", "75% 10.001581 -0.500628 0.509737\n", "max 10.004093 -0.498803 0.546887" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results = pd.DataFrame(store_beta,columns=['b0','b1','b2'])\n", "print \"Here are the results for n = 100,000\"\n", "results.describe()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Discussion\n", "\n", "Having run the bootstrap for \\\$$n = \\begin{bmatrix}1,000 & 10,000 & 100,000 \\end{bmatrix}\\\$$, we see that \n", "\n", "1. Matlab outperforms python for any sample size.\n", "2. As the sample size increases, the gap between python and matlab increases\n", "\n", "This can be seen in the figure below.\n", "\n", "While running numerical analysis in python does take a performance hit, this short example shows the flexibility of the Ipython Notebook. You can run code in matlab, transfer data in and out and retain all of the advantages of both numerical computing platforms.\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEPCAYAAABFpK+YAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xe4XFW5x/HvJLRQQgolhAAnJHRCUTooC+QiFxQpXhVE\nQRC5VyRIE0WEJaCoFCEIV9B7L71KV8QIcigCUiSI1BB6KCF0Akib+8e7J7PnnD2nzJk9a83s3+d5\nzpPZU9/Z52TNmne/+10gIiIiIiIiIiIiIiIiIiIiIiIiIiIRKwG3Am8Bc4FpyXUnAh+nfnYJFaCI\niDTfesDCwDjgXuDzwAnA7iGDEhGRxiwwgPvMSP79GPgAeDnZLuUSkYiI5GrYAO/3IfAiNuO/M7nu\nDOBN4Cpg6eaHJiIioa0I/A34AjARWAIYBZwFnB0uLBERGYzBpmsOxwb8I1PXTQHOBdbPuP/jwKTG\nQhMRKaRZwOSQAYwHNgIWSQK5F6vg+RSwJDAam/H/X53Hl1sQY8x86AAi4kMHEBkfOoDI+NABRCT3\ncbO/HP8I4HTgVeAm4GrgCuBbwNPAE8AY4LAcY2xnXaEDiEhX6AAi0xU6gMh0hQ6gSPqr6pkFbJhx\n/ddyiEVERDpA0VM9LnQAEXGhA4iMCx1AZFzoACLS9uNm278BEZEWC57jz8ur2JvTT+f8vErfXD+3\nF40LHUBkXOgAimQgZ+7mYTTFOPPXAd2BY2gVfbsTEaD+YKBBovPodyrSHB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yd4BSsW+wb2Idilk7fH+OAE7BFl0ZjM9Lv1Llvp++L/gR/\n/xr4B2YkdoD3GOC25LrZVM82HAu8jzWXm03tyW0rY5/gL1Cbd0uf9JZ+ruHYp/XzTYy/WTYHvoXN\n5m5Ptu/G3kdXcp+i7AuwmF8Crgfexg7urUEx98e6WCPFf2AfgBdj6cCi/T/pOXDn/f5n9/FcMgQj\ngJuxAytpxwDnYTm5E4CzkusnY3+Mq2IHe16k9qDN/tgyjjcDuyfX743lzcdiVUPTc3gfzbYx1Rx/\nkffF/cC/Y3nt87B9UcT9sTKWv56CHei+CvghxdsXPXP8rXj/S2D7fhOs0kcHd5tgG2yGm/7ZnWqZ\n1nvYADgu9ZiDsXze89gBrop1sBzoO1hb68pXvgWwP45Yy9SybEK1qqfI+2Jj7Mz1t7CDcOkSxqLt\nj29jM803sLToYhRrX9xG7Tgxlda9/92wbwuvUj/FJiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIi\nItJc47BWub/C+utcR++2yiIdTU3apIjWxBa4GIedDr9T0GhEWmyB0AGIBPAU8Lvk8h+odjwUKQTN\n+KWI5qUuf4AmQFIwGvhFRApGA78UUc/FMoqw6pOIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIjk\n7f8BHQpiIH/bk3QAAAAASUVORK5CYII=\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Convert to pandas dataframe for plotting:\n", "matlab_data=pd.DataFrame(mat_time,columns=['n','Matlab Time'])\n", "python_data=pd.DataFrame(python_time,columns=['n','Python Time'])\n", "plot_data = pd.concat([matlab_data,python_data['Python Time']], axis=1)\n", "plot_data = plot_data.set_index('n')\n", "plot_data.plot()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Matlab TimePython Time
n
1000 0.257269 1.064270
10000 0.808506 3.776620
100000 7.839279 31.610367
\n", "
" ], "text/plain": [ " Matlab Time Python Time\n", "n \n", "1000 0.257269 1.064270\n", "10000 0.808506 3.776620\n", "100000 7.839279 31.610367" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plot_data.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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.6.0" } }, "nbformat": 4, "nbformat_minor": 0 }