comparison python/moving.py @ 937:b67a784beb69

work started on prototype prediction
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 17 Jul 2017 01:38:06 -0400
parents 56cc8a1f7082
children a2f3f3ca241e
comparison
equal deleted inserted replaced
936:56cc8a1f7082 937:b67a784beb69
862 862
863 def getMaxDistance(self, metric): 863 def getMaxDistance(self, metric):
864 'Returns the maximum distance between points in the trajectory' 864 'Returns the maximum distance between points in the trajectory'
865 positions = self.getPositions().asArray().T 865 positions = self.getPositions().asArray().T
866 return cdist(positions, positions, metric = metric).max() 866 return cdist(positions, positions, metric = metric).max()
867
868 def getClosestPoint(self, p1, maxDist2 = None):
869 '''Returns the instant of the closest position in trajectory to p1 (and the point)
870 if maxDist is not None, will check the distance is smaller
871 TODO: could use cdist for different metrics'''
872 distances2 = []
873 minDist2 = float('inf')
874 i = -1
875 for p2 in self:
876 distances2.append(Point.distanceNorm2(p1, p2))
877 if distances2[-1] < minDist2:
878 minDist2 = distances2[-1]
879 i = len(distances)-1
880 if maxDist2 is None or (maxDist2 is not None and minDist2 < maxDist2):
881 return i
882 else:
883 return None
867 884
868 def similarOrientation(self, refDirection, cosineThreshold, minProportion = 0.5): 885 def similarOrientation(self, refDirection, cosineThreshold, minProportion = 0.5):
869 '''Indicates whether the minProportion (<=1.) (eg half) of the trajectory elements (vectors for velocity) 886 '''Indicates whether the minProportion (<=1.) (eg half) of the trajectory elements (vectors for velocity)
870 have a cosine with refDirection is smaller than cosineThreshold''' 887 have a cosine with refDirection is smaller than cosineThreshold'''
871 count = 0 888 count = 0