Mercurial Hosting > traffic-intelligence
diff python/events.py @ 746:e7ff0f60fef8
merged new developments (indicator and trajectory clustering)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 10 Sep 2015 15:52:45 -0400 |
parents | 0e875a7f5759 |
children | 8ba82b371eea |
line wrap: on
line diff
--- a/python/events.py Mon Aug 10 01:06:59 2015 -0400 +++ b/python/events.py Thu Sep 10 15:52:45 2015 -0400 @@ -2,7 +2,7 @@ '''Libraries for events Interactions, pedestrian crossing...''' -import moving, prediction, indicators, utils, cvutils +import moving, prediction, indicators, utils, cvutils, ml from base import VideoFilenameAddable import numpy as np @@ -295,49 +295,8 @@ print('unknown type of point: '+pointType) return allPoints -def prototypeCluster(interactions, similarityMatrix, alignmentMatrix, indicatorName, minSimilarity): - '''Finds exemplar indicator time series for all interactions - Returns the prototype indices (in the interaction list) and the label of each indicator (interaction) - - if an indicator profile (time series) is different enough (<minSimilarity), - it will become a new prototype. - Non-prototype interactions will be assigned to an existing prototype''' - - # sort indicators based on length - indices = range(similarityMatrix.shape[0]) - def compare(i, j): - if len(interactions[i].getIndicator(indicatorName)) > len(interactions[j].getIndicator(indicatorName)): - return -1 - elif len(interactions[i].getIndicator(indicatorName)) == len(interactions[j].getIndicator(indicatorName)): - return 0 - else: - return 1 - indices.sort(compare) - # go through all indicators - prototypeIndices = [indices[0]] - for i in indices[1:]: - if similarityMatrix[i][prototypeIndices].max() < minSimilarity: - prototypeIndices.append(i) - - # assignment - labels = [-1]*similarityMatrix.shape[0] - indices = [i for i in range(similarityMatrix.shape[0]) if i not in prototypeIndices] - for i in prototypeIndices: - labels[i] = i - for i in indices: - prototypeIndex = similarityMatrix[i][prototypeIndices].argmax() - labels[i] = prototypeIndices[prototypeIndex] - - return prototypeIndices, labels - -def prototypeMultivariateCluster(interactions, similarityMatrics, indicatorNames, minSimilarities, minClusterSize): - '''Finds exmaple indicator time series (several indicators) for all interactions - - if any interaction indicator time series is different enough (<minSimilarity), - it will become a new prototype. - Non-prototype interactions will be assigned to an existing prototype if all indicators are similar enough''' - pass - +def prototypeCluster(interactions, similarities, indicatorName, minSimilarity, similarityFunc = None, minClusterSize = None, randomInitialization = False): + return ml.prototypeCluster([inter.getIndicator(indicatorName) for inter in interactions], similarities, minSimilarity, similarityFunc, minClusterSize, randomInitialization) class Crossing(moving.STObject): '''Class for the event of a street crossing