mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-27 14:01:15 +00:00
removed temp cython files
This commit is contained in:
parent
f5e08cde14
commit
ad32c82ee9
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:a091baac3cb82ac71775c03f73be1925fefe2d659bb7359de4bb88887fbe7d24"
|
||||
"signature": "sha256:379319350ffd7e7539cf8f11b3a7c15b6f1d1013bcb445b55714c76bf0855fa2"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -714,7 +714,30 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 15
|
||||
"prompt_number": 2
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"%%cython\n",
|
||||
"import numpy as np\n",
|
||||
"import scipy.stats\n",
|
||||
"cimport numpy as np\n",
|
||||
"\n",
|
||||
"def cy_lin_lstsqr_mat2(x, y):\n",
|
||||
" \"\"\" Computes the least-squares solution to a linear matrix equation. \"\"\"\n",
|
||||
" cdef double x_avg = sum(x)/len(x)\n",
|
||||
" cdef double y_avg = sum(y)/len(y)\n",
|
||||
" cdef double var_x = sum([(x_i - x_avg)**2 for x_i in x])\n",
|
||||
" cdef double cov_xy = sum([(x_i - x_avg)*(y_i - y_avg) for x_i,y_i in zip(x,y)])\n",
|
||||
" cdef double slope = cov_xy / var_x\n",
|
||||
" cdef double y_interc = y_avg - slope*x_avg\n",
|
||||
" return (slope, y_interc)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
@ -740,6 +763,16 @@
|
|||
" y_interc = y_avg - slope*x_avg\n",
|
||||
" return (slope, y_interc)\n",
|
||||
"\n",
|
||||
"def cy_lin_lstsqr_mat2(x, y):\n",
|
||||
" \"\"\" Computes the least-squares solution to a linear matrix equation. \"\"\"\n",
|
||||
" cdef double x_avg = sum(x)/len(x)\n",
|
||||
" cdef double y_avg = sum(y)/len(y)\n",
|
||||
" cdef double var_x = sum([(x_i - x_avg)**2 for x_i in x])\n",
|
||||
" cdef double cov_xy = sum([(x_i - x_avg)*(y_i - y_avg) for x_i,y_i in zip(x,y)])\n",
|
||||
" cdef double slope = cov_xy / var_x\n",
|
||||
" cdef double y_interc = y_avg - slope*x_avg\n",
|
||||
" return (slope, y_interc)\n",
|
||||
"\n",
|
||||
"def cy_numpy_lstsqr(x, y):\n",
|
||||
" \"\"\" Computes the least-squares solution to a linear matrix equation. \"\"\"\n",
|
||||
" X = np.vstack([x, np.ones(len(x))]).T\n",
|
||||
|
@ -752,7 +785,27 @@
|
|||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 16
|
||||
"prompt_number": 3
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"import timeit\n",
|
||||
"\n",
|
||||
"for lab,appr in zip([\"matrix approach\",\"classic approach\",\n",
|
||||
" \"numpy function\",\"scipy function\"],\n",
|
||||
" [(lin_lstsqr_mat, cy_lin_lstsqr_mat), \n",
|
||||
" (classic_lstsqr, cy_classic_lstsqr),\n",
|
||||
" (cy_lin_lstsqr_mat2, cy_lin_lstsqr_mat2),\n",
|
||||
" (scipy_lstsqr, cy_scipy_lstsqr)]):\n",
|
||||
" print(\"\\n\\n{}: \".format(lab))\n",
|
||||
" %timeit appr[0](x, y)\n",
|
||||
" %timeit appr[1](x, y)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +0,0 @@
|
|||
|
||||
def ccy_classic_lstsqr(x, y):
|
||||
""" Computes the least-squares solution to a linear matrix equation. """
|
||||
x_avg = sum(x)/len(x)
|
||||
y_avg = sum(y)/len(y)
|
||||
var_x = sum([(x_i - x_avg)**2 for x_i in x])
|
||||
cov_xy = sum([(x_i - x_avg)*(y_i - y_avg) for x_i,y_i in zip(x,y)])
|
||||
slope = cov_xy / var_x
|
||||
y_interc = y_avg - slope*x_avg
|
||||
return (slope, y_interc)
|
File diff suppressed because one or more lines are too long
|
@ -1359,4 +1359,4 @@
|
|||
"metadata": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
from distutils.core import setup
|
||||
from distutils.extension import Extension
|
||||
from Cython.Distutils import build_ext
|
||||
|
||||
setup(
|
||||
cmdclass = {'build_ext': build_ext},
|
||||
ext_modules = [Extension("ccy_classic_lstsqr", ["ccy_classic_lstsqr.pyx"])]
|
||||
)
|
Loading…
Reference in New Issue
Block a user