Seth-Park / MultimodalExplanations

Code release for Park et al. Multimodal Multimodal Explanations: Justifying Decisions and Pointing to the Evidence. in CVPR, 2018
BSD 2-Clause "Simplified" License
49 stars 10 forks source link

Help with EMD details #10

Closed fariquelme closed 5 years ago

fariquelme commented 5 years ago

Hello Seth, I am using pyemd as you posted, but I have some doubts about the EMD calculation. Did you use emd or emd_samples ?. If it is emd, what distance matrix did you use?, and if it is emd_samples, how many bins ?

Thanks!

Seth-Park commented 5 years ago

Hi,

I used emd and the distance matrix was calculated to reflect euclidean distance. I simply created a NxN matrix as in the following:

    distance_matrix = np.zeros((N**2,N**2))
    for x1 in range(N):
      for y1 in range(N):
        for x2 in range(N):
          for y2 in range(N):
            d = distance_fnc((x1, y1), (x2,y2))
            X = x1*N + y1
            Y = x2*N + y2
            distance_matrix[X,Y] = d
    assert np.sum(distance_matrix - distance_matrix.T) == 0 #distance matrix should be symmetric

The distance_fnc in the code snippet computes the euclidean distance between the two points, but you can change it into any metric you want (i.e. manhattan, squared, etc.).

fariquelme commented 5 years ago

Thanks, i will try to replicate the results!