Mercurial Hosting > traffic-intelligence
changeset 913:1cd878812529
work in progress
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 28 Jun 2017 17:57:06 -0400 |
parents | fd057a6b04db |
children | f228fd649644 |
files | python/ml.py python/storage.py scripts/learn-poi.py |
diffstat | 3 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/python/ml.py Wed Jun 28 16:51:17 2017 -0400 +++ b/python/ml.py Wed Jun 28 17:57:06 2017 -0400 @@ -266,12 +266,11 @@ print('Mean overall similarity: {}'.format((similarities[cluster][:,cluster].sum()+n)/(n*(n-1)))) # Gaussian Mixture Models -def plotGMMClusters(model, dataset = None, fig = None, colors = utils.colors, nUnitsPerPixel = 1., alpha = 0.3): +def plotGMMClusters(model, labels, dataset = None, fig = None, colors = utils.colors, nUnitsPerPixel = 1., alpha = 0.3): '''plot the ellipse corresponding to the Gaussians and the predicted classes of the instances in the dataset''' if fig is None: fig = plt.figure() - labels = model.predict(dataset) tmpDataset = dataset/nUnitsPerPixel for i in xrange(model.n_components): mean = model.means_[i]/nUnitsPerPixel @@ -289,4 +288,3 @@ ell.set_clip_box(fig.bbox) ell.set_alpha(alpha) fig.axes[0].add_artist(ell) - return labels
--- a/python/storage.py Wed Jun 28 16:51:17 2017 -0400 +++ b/python/storage.py Wed Jun 28 17:57:06 2017 -0400 @@ -59,8 +59,11 @@ def createObjectsTable(cursor): cursor.execute("CREATE TABLE IF NOT EXISTS objects (object_id INTEGER, road_user_type INTEGER, n_objects INTEGER, PRIMARY KEY(object_id))") -def createObjectsFeaturesTable(cursor): - cursor.execute("CREATE TABLE IF NOT EXISTS objects_features (object_id INTEGER, trajectory_id INTEGER, PRIMARY KEY(trajectory_id))") +def createAssignmentTable(cursor, objectType1, objectType2, columnName1, columnName2): + cursor.execute("CREATE TABLE IF NOT EXISTS "+objectType1+"s_"+objectType2+"s ("+columnName1+" INTEGER, "+columnName1+" INTEGER, PRIMARY KEY("+columnName1+","+columnName2+"))") + +def createObjectsFeaturesTable(cursor): # same as + cursor.execute("CREATE TABLE IF NOT EXISTS objects_features (object_id INTEGER, trajectory_id INTEGER, PRIMARY KEY(object_id, trajectory_id))") def createCurvilinearTrajectoryTable(cursor):
--- a/scripts/learn-poi.py Wed Jun 28 16:51:17 2017 -0400 +++ b/scripts/learn-poi.py Wed Jun 28 17:57:06 2017 -0400 @@ -17,6 +17,7 @@ parser.add_argument('-w', dest = 'worldImageFilename', help = 'filename of the world image') parser.add_argument('-u', dest = 'unitsPerPixel', help = 'number of units of distance per pixel', type = float, default = 1.) parser.add_argument('--display', dest = 'display', help = 'display points of interests', action = 'store_true') # default is manhattan distance +parser.add_argument('--assign', dest = 'display', help = 'display points of interests', action = 'store_true') # default is manhattan distance args = parser.parse_args() @@ -37,11 +38,11 @@ gmmId=0 for nClusters, points, gmmType in zip([args.nOriginClusters, nDestinationClusters], - [beginnings, ends], - ['beginning', 'end']): + [beginnings, ends], + ['beginning', 'end']): # estimation gmm = mixture.GaussianMixture(n_components=nClusters, covariance_type = args.covarianceType) - model=gmm.fit(beginnings) + model=gmm.fit(points) if not model.converged_: print('Warning: model for '+gmmType+' points did not converge') # plot @@ -50,12 +51,16 @@ if args.worldImageFilename is not None and args.unitsPerPixel is not None: img = plt.imread(args.worldImageFilename) plt.imshow(img) - labels = ml.plotGMMClusters(model, points, fig, nUnitsPerPixel = args.unitsPerPixel) + labels = model.predict(points) + labels = ml.plotGMMClusters(model, labels, points, fig, nUnitsPerPixel = args.unitsPerPixel) plt.axis('image') plt.title(gmmType) print(gmmType+' Clusters:\n{}'.format(ml.computeClusterSizes(labels, range(model.n_components)))) # save storage.savePOIs(args.databaseFilename, model, gmmType, gmmId) + # save assignments + if args.assign: + pass gmmId += 1 if args.display: