# HG changeset patch # User Nicolas Saunier # Date 1679536872 14400 # Node ID a12d126346ff37907ec0aa94391be4e9be54c4a9 # Parent 7b3384a8e4094fdf65f885e01e9365f9678cd855# Parent 4356065ed3ca20f49f4b1723d31b70a9c86741bd merge diff -r 7b3384a8e409 -r a12d126346ff trafficintelligence/storage.py --- a/trafficintelligence/storage.py Wed Mar 22 15:40:33 2023 -0400 +++ b/trafficintelligence/storage.py Wed Mar 22 22:01:12 2023 -0400 @@ -756,7 +756,7 @@ 'weight': row[7], 'precisions': array(literal_eval(row[8]))}) if len(gmm) > 0: - tmp = mixture.GaussianMixture(len(gmm), covarianceType) + tmp = mixture.GaussianMixture(n_components=len(gmm), covariance_type=covarianceType) tmp.means_ = array([gaussian['mean'] for gaussian in gmm]) tmp.covariances_ = array([gaussian['covar'] for gaussian in gmm]) tmp.weights_ = array([gaussian['weight'] for gaussian in gmm]) diff -r 7b3384a8e409 -r a12d126346ff trafficintelligence/tests/storage.txt --- a/trafficintelligence/tests/storage.txt Wed Mar 22 15:40:33 2023 -0400 +++ b/trafficintelligence/tests/storage.txt Wed Mar 22 22:01:12 2023 -0400 @@ -9,6 +9,7 @@ >>> nonexistentFilename = "nonexistent" >>> loadTrajectoriesFromSqlite(nonexistentFilename, 'feature') +Impossible to load from non-existing file nonexistent [] >>> o1 = MovingObject.generate(2, Point(0.,0.), Point(1.,0.), TimeInterval(0,10)) @@ -116,7 +117,7 @@ >>> from numpy.random import random_sample >>> nPoints = 50 >>> points = random_sample(nPoints*2).reshape(nPoints,2) ->>> gmm = GaussianMixture(4, covariance_type = 'full') +>>> gmm = GaussianMixture(n_components = 4, covariance_type = 'full') >>> tmp = gmm.fit(points) >>> gmmId = 0 >>> savePOIsToSqlite('pois-tmp.sqlite', gmm, 'end', gmmId) diff -r 7b3384a8e409 -r a12d126346ff trafficintelligence/utils.py --- a/trafficintelligence/utils.py Wed Mar 22 15:40:33 2023 -0400 +++ b/trafficintelligence/utils.py Wed Mar 22 22:01:12 2023 -0400 @@ -431,15 +431,13 @@ smoothed[point] = max(set(window_values), key=window_values.count) return smoothed -def filterMovingWindow(inputSignal, halfWidth): +def filterMovingWindow(inputSignal, halfWidth, mode = 'valid'): '''Returns an array obtained after the smoothing of the input by a moving average - The first and last points are copied from the original.''' - width = float(halfWidth*2+1) + The size of the output depends on the mode: 'full', 'same', 'valid' + See https://numpy.org/doc/stable/reference/generated/numpy.convolve.html.''' + width = min(len(inputSignal), int(halfWidth*2+1)) win = ones(width,'d') - result = convolve(win/width,array(inputSignal),'same') - result[:halfWidth] = inputSignal[:halfWidth] - result[-halfWidth:] = inputSignal[-halfWidth:] - return result + return convolve(win/width, array(inputSignal), mode) def linearRegression(x, y, deg = 1, plotData = False): '''returns the least square estimation of the linear regression of y = ax+b