Mercurial Hosting > traffic-intelligence
diff python/storage.py @ 871:6db83beb5350
work in progress to update gaussian mixtures
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 03 Feb 2017 16:26:18 -0500 |
parents | 2d6249fe905a |
children | c70adaeeddf5 |
line wrap: on
line diff
--- a/python/storage.py Fri Feb 03 16:15:06 2017 -0500 +++ b/python/storage.py Fri Feb 03 16:26:18 2017 -0500 @@ -567,8 +567,8 @@ ######################### def savePOIs(filename, gmm, gmmType, gmmId): - '''Saves a Gaussian mixture model (of class sklearn.mixture.GMM) - gmmType is a type of GMM, learnt either from beginnings or ends of trajectories''' + '''Saves a Gaussian mixture model (of class sklearn.mixture.GaussianMixture) + gmmType is a type of GaussianMixture, learnt either from beginnings or ends of trajectories''' connection = sqlite3.connect(filename) cursor = connection.cursor() if gmmType not in ['beginning', 'end']: @@ -578,7 +578,7 @@ try: cursor.execute('CREATE TABLE IF NOT EXISTS gaussians2d (id INTEGER, type VARCHAR, x_center REAL, y_center REAL, covar00 REAL, covar01 REAL, covar10 REAL, covar11 REAL, covariance_type VARCHAR, weight, mixture_id INTEGER, PRIMARY KEY(id, mixture_id))') for i in xrange(gmm.n_components): - cursor.execute('INSERT INTO gaussians2d VALUES({}, \'{}\', {}, {}, {}, {}, {}, {}, \'{}\', {}, {})'.format(i, gmmType, gmm.means_[i][0], gmm.means_[i][1], gmm.covars_[i][0,0], gmm.covars_[i][0,1], gmm.covars_[i][1,0], gmm.covars_[i][1,1], gmm.covariance_type, gmm.weights_[i], gmmId)) + cursor.execute('INSERT INTO gaussians2d VALUES({}, \'{}\', {}, {}, {}, {}, {}, {}, \'{}\', {}, {})'.format(i, gmmType, gmm.means_[i][0], gmm.means_[i][1], gmm.covariances_[i][0,0], gmm.covariances_[i][0,1], gmm.covariances_[i][1,0], gmm.covariances_[i][1,1], gmm.covariance_type, gmm.weights_[i], gmmId)) connection.commit() except sqlite3.OperationalError as error: printDBError(error) @@ -597,9 +597,9 @@ for row in cursor: if gmmId is None or row[10] != gmmId: if len(gmm) > 0: - tmp = mixture.GMM(len(gmm), covarianceType) + tmp = mixture.GaussianMixture(len(gmm), covarianceType) tmp.means_ = array([gaussian['mean'] for gaussian in gmm]) - tmp.covars_ = array([gaussian['covar'] for gaussian in gmm]) + tmp.covariances_ = array([gaussian['covar'] for gaussian in gmm]) tmp.weights_ = array([gaussian['weight'] for gaussian in gmm]) tmp.gmmTypes = [gaussian['type'] for gaussian in gmm] pois.append(tmp) @@ -616,9 +616,9 @@ 'covar': array(row[4:8]).reshape(2,2), 'weight': row[9]}) if len(gmm) > 0: - tmp = mixture.GMM(len(gmm), covarianceType) + tmp = mixture.GaussianMixture(len(gmm), covarianceType) tmp.means_ = array([gaussian['mean'] for gaussian in gmm]) - tmp.covars_ = array([gaussian['covar'] for gaussian in gmm]) + tmp.covariances_ = array([gaussian['covar'] for gaussian in gmm]) tmp.weights_ = array([gaussian['weight'] for gaussian in gmm]) tmp.gmmTypes = [gaussian['type'] for gaussian in gmm] pois.append(tmp)