Mercurial Hosting > traffic-intelligence
changeset 1200:4356065ed3ca
updated simple moving average filter and cleaned tests
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 08 Dec 2022 10:24:22 -0500 |
parents | 6a6a4d5958f7 |
children | a12d126346ff |
files | trafficintelligence/storage.py trafficintelligence/tests/storage.txt trafficintelligence/utils.py |
diffstat | 3 files changed, 8 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/trafficintelligence/storage.py Fri Nov 18 15:55:09 2022 -0500 +++ b/trafficintelligence/storage.py Thu Dec 08 10:24:22 2022 -0500 @@ -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])
--- a/trafficintelligence/tests/storage.txt Fri Nov 18 15:55:09 2022 -0500 +++ b/trafficintelligence/tests/storage.txt Thu Dec 08 10:24:22 2022 -0500 @@ -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)
--- a/trafficintelligence/utils.py Fri Nov 18 15:55:09 2022 -0500 +++ b/trafficintelligence/utils.py Thu Dec 08 10:24:22 2022 -0500 @@ -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