comparison trafficintelligence/utils.py @ 1124:91faf679e898

minor
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 29 Nov 2019 00:59:46 -0500
parents e62c2f5e25e6
children 342701cdac30
comparison
equal deleted inserted replaced
1123:0548a78852b8 1124:91faf679e898
10 10
11 from scipy.stats import rv_continuous, kruskal, shapiro, lognorm, norm, t 11 from scipy.stats import rv_continuous, kruskal, shapiro, lognorm, norm, t
12 from scipy.spatial import distance 12 from scipy.spatial import distance
13 from scipy.sparse import dok_matrix 13 from scipy.sparse import dok_matrix
14 from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, mean, median, percentile, isnan, ones, convolve, dtype, isnan, NaN, ma, isinf, savez, load as npload, log, polyfit, float as npfloat 14 from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, mean, median, percentile, isnan, ones, convolve, dtype, isnan, NaN, ma, isinf, savez, load as npload, log, polyfit, float as npfloat
15 from numpy.random import permutation as nppermutation 15 from numpy.random import random_sample, permutation as nppermutation
16 from pandas import DataFrame, concat 16 from pandas import DataFrame, concat
17 import matplotlib.pyplot as plt 17 import matplotlib.pyplot as plt
18 18
19 datetimeFormat = "%Y-%m-%d %H:%M:%S" 19 datetimeFormat = "%Y-%m-%d %H:%M:%S"
20 20
302 # if sum(weights)>0: 302 # if sum(weights)>0:
303 # smoothed[i] = sum(weights*Y)/sum(weights) 303 # smoothed[i] = sum(weights*Y)/sum(weights)
304 # else: 304 # else:
305 # smoothed[i] = 0 305 # smoothed[i] = 0
306 # return smoothed 306 # return smoothed
307
308 def generateData(nrows, nvariables, scale):
309 x = random_sample(nrows*nvariables).reshape(nrows,nvariables)*scale
310 return DataFrame(x, columns=['x{}'.format(i+1) for i in range(nvariables)])
307 311
308 def kernelSmoothing(x, X, Y, weightFunc, halfwidth): 312 def kernelSmoothing(x, X, Y, weightFunc, halfwidth):
309 '''Returns the smoothed estimate of (X,Y) at x 313 '''Returns the smoothed estimate of (X,Y) at x
310 Sum_x weight(sample_x,x) * y(x)''' 314 Sum_x weight(sample_x,x) * y(x)'''
311 weights = array([weightFunc(x,observedx, halfwidth) for observedx in X]) 315 weights = array([weightFunc(x,observedx, halfwidth) for observedx in X])