{ "cells": [ { "cell_type": "code", "execution_count": 114, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pandas as pd\n", "import scipy.optimize as sc\n", "import scipy.sparse as sp" ] }, { "cell_type": "code", "execution_count": 115, "metadata": { "collapsed": true }, "outputs": [], "source": [ "data = np.random.poisson(100, (10000,1))" ] }, { "cell_type": "code", "execution_count": 116, "metadata": { "collapsed": true }, "outputs": [], "source": [ "data = sp.csr_matrix(data)" ] }, { "cell_type": "code", "execution_count": 117, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ 0.]\n", "[ 0.00025]\n", "[ 0.0005]\n", "[ 0.00075]\n", "[ 0.00125]\n", "[ 0.00175]\n", "[ 0.00275]\n", "[ 0.00375]\n", "[ 0.00575]\n", "[ 0.00775]\n", "[ 0.01175]\n", "[ 0.01575]\n", "[ 0.02375]\n", "[ 0.03175]\n", "[ 0.04775]\n", "[ 0.06375]\n", "[ 0.09575]\n", "[ 0.12775]\n", "[ 0.19175]\n", "[ 0.25575]\n", "[ 0.38375]\n", "[ 0.51175]\n", "[ 0.76775]\n", "[ 1.02375]\n", "[ 1.53575]\n", "[ 2.04775]\n", "[ 3.07175]\n", "[ 4.09575]\n", "[ 6.14375]\n", "[ 8.19175]\n", "[ 12.28775]\n", "[ 16.38375]\n", "[ 24.57575]\n", "[ 32.76775]\n", "[ 49.15175]\n", "[ 65.53575]\n", "[ 98.30375]\n", "[ 131.07175]\n", "[ 131.07175]\n", "[ 114.68775]\n", "[ 81.91975]\n", "[ 106.49575]\n", "[ 90.11175]\n", "[ 102.39975]\n", "[ 94.20775]\n", "[ 100.35175]\n", "[ 102.39975]\n", "[ 99.32775]\n", "[ 98.30375]\n", "[ 99.83975]\n", "[ 100.35175]\n", "[ 99.58375]\n", "[ 100.09575]\n", "[ 99.71175]\n", "[ 99.58375]\n", "[ 99.77575]\n", "[ 99.83975]\n", "[ 99.74375]\n", "[ 99.80775]\n", "[ 99.75975]\n", "[ 99.74375]\n", "[ 99.76775]\n", "[ 99.77575]\n", "[ 99.76375]\n", "[ 99.77175]\n", "[ 99.76575]\n", "[ 99.76975]\n", "[ 99.76675]\n", "[ 99.76875]\n", "[ 99.76725]\n", "[ 99.76825]\n", "[ 99.7675]\n", "[ 99.76725]\n", "[ 99.767625]\n", "[ 99.76775]\n", "[ 99.7675625]\n", "Optimization terminated successfully.\n", " Current function value: -3594470.473058\n", " Iterations: 38\n", " Function evaluations: 76\n", "[ 99.767625]\n" ] } ], "source": [ "def poiss_loglike(x, data, a):\n", " print x\n", " return -np.sum(data*np.log(x)-x)*a\n", "\n", "\n", "params = sc.fmin(poiss_loglike, 0, args=(data ,1))\n", "print params" ] } ], "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.9" } }, "nbformat": 4, "nbformat_minor": 0 }