from DiscreteFrechetDistance import * # Define two paths: P = numpy.array([[0.0, 1.0, 1.0], [1.0, 1.0, 1.0], [2.0, 1.0, 1.0], [3.0, 1.0, 1.0], [4.0, 1.0, 1.0], [5.0, 0.0, 1.0], [6.0, 1.0, 1.0], [7.0, 1.0, 1.0], [8.0, 1.0, 1.0], [9.0, 1.0, 1.0]]) Q = numpy.array([[0.0, 2.0, 1.0], [1.0, 2.0, 1.0], [2.0, 2.0, 1.0], [3.0, 2.0, 1.0], [4.0, 2.0, 1.0], [5.0, 3.0, 1.0], [6.0, 2.0, 1.0], [7.0, 2.0, 1.0], [8.0, 2.0, 1.0], [9.0, 2.0, 1.0]]) # Calculate the discrete Frechet distance FD = DiscreteFrechetDistance(P, Q) cm = FD.getCouplingMeasure() # Get the coupling sequence cm_seq = FD.getCouplingSequence() # Print the coupling sequence and the distance between points # Note: points in the sequence are number from 1 to p for path P, and 1 to q for path Q. print '' print 'Coupling sequence: ' print ' Path P Path Q Distance ' for i in range(0, len(cm_seq)): u = P[(cm_seq[i, 0] - 1), :] # minus one because P is indexed from zero v = Q[(cm_seq[i, 1] - 1), :] # minus one because Q is indexed from zero dist = numpy.sqrt(numpy.sum((u - v)**2)) print ' %2i %2i %f ' % (cm_seq[i, 0], cm_seq[i, 1], dist)
[1.0, 2.0, 1.0], [2.0, 2.0, 1.0], [3.0, 2.0, 1.0], [4.0, 2.0, 1.0], [5.0, 3.0, 1.0], [6.0, 2.0, 1.0], [7.0, 2.0, 1.0], [8.0, 2.0, 1.0], [9.0, 2.0, 1.0]]); # Calculate the discrete Frechet distance: # Using DiscreteFrechetDistance class: t0 = time.time() FD = DiscreteFrechetDistance(P, Q) cm1 = FD.getCouplingMeasure() t = (time.time() - t0) print '' print 'Using own function' print 'Frechet distance = ', cm1 print 'elapsed time = ', t print '\n' # Using function from the MDAnalysis library t0 = time.time() cm2 = MDAnalysis.analysis.psa.discrete_frechet(P, Q) t = (time.time() - t0) print 'Using MDAnalysis library' print 'Frechet distance = ', cm2 print 'elapsed time = ', t
[8.0, 1.0, 1.0], [9.0, 1.0, 1.0]]); Q = numpy.array([[0.0, 2.0, 1.0], [1.0, 2.0, 1.0], [2.0, 2.0, 1.0], [3.0, 2.0, 1.0], [4.0, 2.0, 1.0], [5.0, 3.0, 1.0], [6.0, 2.0, 1.0], [7.0, 2.0, 1.0], [8.0, 2.0, 1.0], [9.0, 2.0, 1.0]]); # Calculate the discrete Frechet distance FD = DiscreteFrechetDistance(P, Q) cm = FD.getCouplingMeasure() # Get the coupling sequence cm_seq = FD.getCouplingSequence() # Print the coupling sequence and the distance between points # Note: points in the sequence are number from 1 to p for path P, and 1 to q for path Q. print '' print 'Coupling sequence: ' print ' Path P Path Q Distance ' for i in range (0, len(cm_seq)): u = P[(cm_seq[i,0]-1),:] # minus one because P is indexed from zero v = Q[(cm_seq[i,1]-1),:] # minus one because Q is indexed from zero dist = numpy.sqrt(numpy.sum((u-v)**2)) print ' %2i %2i %f ' % (cm_seq[i,0], cm_seq[i,1], dist)