def time_kde_C(): """ Calls kde's pure C implementation. We point to global variables so that we can pull in different test values later. """ global bandwidth, npoints, xmin, xmax, data kde.hat_linear(data, bandwidth = bandwidth, xmin = xmin, xmax = xmax, npoints = npoints, code = 'C')
def test_hat_linear(self): t0 = time() (xgrid, den) = kde.hat_linear( self.data, bandwidth=self.bandwidth, xmin=self.xmin, xmax=self.xmax, npoints=self.npoints, code="python" ) t1 = time() t2 = time() den2 = _kde.hat_linear(self.data, self.bandwidth, self.xmin, self.xmax, self.npoints) t3 = time() print "Pure python {:3.3g} seconds".format(t1 - t0) print "C implementation {:3.3g} seconds".format(t3 - t2) print "Speedup {:3.0f} x".format((t1 - t0) / (t3 - t2)) self.assertTrue(np.linalg.norm(den - den2, np.inf) < 1e-13)
def test_hat_linear(self): t0 = time() den = kde.hat_linear(self.data, bandwidth = self.bandwidth, xmin = self.xmin, xmax = self.xmax, npoints = self.npoints, code = 'python') t1 = time() t2 = time() den2 = _kde.hat_linear(self.data, self.bandwidth, self.xmin, self.xmax, self.npoints) t3 = time() t4 = time() den = kde.hat_linear(self.data, bandwidth = self.bandwidth, xmin = self.xmin, xmax = self.xmax, npoints = self.npoints, code = 'C') t5 = time() print "Pure python {:3.3g} seconds".format(t1-t0) print "C implementation {:3.3g} seconds".format(t3-t2) print "Speedup {:3.0f} x".format((t1-t0)/(t3-t2)) print "C from python {:3.3g} seconds".format(t5-t4) self.assertTrue(np.linalg.norm(den - den2,np.inf)<1e-13)
import kde import _kde import numpy as np from time import time import matplotlib.pyplot as plt data = np.random.rand(1e5) #data = [.5] npoints = 101 bandwidth = 0.1 xmin = 0 xmax = 1 t0 = time() (xgrid, den) = kde.hat_linear(data, bandwidth = bandwidth, xmin=xmin, xmax=xmax, npoints = npoints) t1 = time() print "Elapsed time {}".format(t1-t0) t0 = time() den2 = _kde.hat_linear(data, 0.1, xmin, xmax, npoints) t1 = time() print "Elapsed time {}".format(t1-t0) print "Error {}".format( np.max(den-den2)) print den print den2 fig, ax = plt.subplots()
import _kde import numpy as np from time import time import matplotlib.pyplot as plt data = np.random.rand(1e5) #data = [.5] npoints = 101 bandwidth = 0.1 xmin = 0 xmax = 1 t0 = time() (xgrid, den) = kde.hat_linear(data, bandwidth=bandwidth, xmin=xmin, xmax=xmax, npoints=npoints) t1 = time() print "Elapsed time {}".format(t1 - t0) t0 = time() den2 = _kde.hat_linear(data, 0.1, xmin, xmax, npoints) t1 = time() print "Elapsed time {}".format(t1 - t0) print "Error {}".format(np.max(den - den2)) print den print den2