similarity_measures icon indicating copy to clipboard operation
similarity_measures copied to clipboard

discrete Frechet distance between lists or 1D arrays

Open miladad8 opened this issue 2 years ago • 4 comments

my question might sounds a little dumb. but is it possible to use similaritymeasures.frechet_dist() for lists or 1D arrays? i tried to calculate similarity between a list and other multiple list (which also contains the first list )but the most similar output was not the first argument.which i expect to return it since they are exactly the same.but it works when implemented in real coordinates with lat ,lon like trajectories and the most similar output is the first given argument.i'm trying to use factors other than distance for calculating similarity between two thing and those parametrs are just a numerical values and i'm wondering how can i use this frechet _dist for list arrays.

miladad8 avatar Jul 22 '22 10:07 miladad8

Sorry, this completely missed my radar. If I don't respond, feel free to ping me or send me an email.

I need more information here. What does your list mean? Why are the 1D arrays grouped together in different sets?

You can apply the frechet distance to 1D arrays, and it has an intuitive meaning.

Now collections of 1D arrays is a bit tricky. The meaning of why the data is organized this way is important.

cjekel avatar Aug 06 '22 16:08 cjekel

i have a list, contains speed values in different timestamps for one vehicle(1st list) and have another list(2nd list), consisting of sublists which every sublist is exactly like 1st list .so what i'm going to do here is to compare my 1st list with 2nd list containting multiple sublists, including my 1st list, using frechet distance.what i expect as the most similar index, is my 1st list index from 2nd sublists .but i got other sublist index as the most similar and wonder why? frechet(1st list, 2nd list[a,b,......,1st list,.....x,y...]) here a,b,...,x,y are also list of speed values.but the most similar index won't be 1st list which it should be since it's identical to the first argument given to frechet function but for instance i get x list as the most similar list to 1st list. btw,the reason i grouped together my lists and build a list of lists is because i want to find the most similar list to my 1st list using a for loop. again sorry to bother and really appreciate your respond

miladad8 avatar Aug 07 '22 10:08 miladad8

I think you are going to need to call the frechet distance for each sublist separately.

This is very important, but you are going to need to make sure both input and output are 2d arrays.

In your case, the 1st list must be a 2d array of number of velocity data points x 1. Making it 1 x number of velocity data points is going to give you something else.

cjekel avatar Aug 09 '22 16:08 cjekel

here's the code i use. i use: 1st list=s[:,np.newaxis] for making a 2d array of the 1st list.

then i use a for loop to go through all of sublists: for i in range(len(2ndlist)): ds=frechet0.distance(1st list,2ndlist[i]) here 2ndlist[i] are my sublists.

i'm a little confused.every sublists in 2ndlist should be 2d array to get the correct output?

miladad8 avatar Aug 11 '22 09:08 miladad8

Are you working with velocity magnitudes? Or velocity vectors (velocity x, velocity y, and velocity z)?

If you are working with magnitudes, let's say your first list has 20 data points at a constant velocity of 2.0. This first list should be a matrix that is 20 x 1. (number of data x number of dimensions)

Let's then compute the frechet distance between the first list and another list. Let's say the other list is 15 data points, that start at zero and linearly goes to 3.0

import numpy as np
import similaritymeasures

first = np.ones(20)*2.0

first = first.reshape((-1, 1))
print('The shape of first', first.shape)

second = np.linspace(0., 3., 15)
second = second.reshape((-1, 1))

print('The shape of second', second.shape)

d = similaritymeasures.frechet_dist(first, second)
print(d)

Does that help clear things up?

Yes your for loop to compute the distance for each list looks correct. I would just be sure that each list needs to be a 2D matrix like I show above. The rows is equal to the number of data points. The columns is equal to the number of dimensions.

cjekel avatar Aug 13 '22 19:08 cjekel

Yes, it was really helpful.thanks alot!

miladad8 avatar Aug 17 '22 13:08 miladad8