README.md

gw_distance

This repo contains functions for reproducing results provided in article Gromov–Wasserstein Distances and the Metric Approach to Object Matching. All functions are written in R programming language.

article : Gromov–Wasserstein Distances and the Metric Approach to Object Matching
author  : Facundo Mémoli
year    : 2011

Example

install.packages("devtools")
library(devtools)
# you may need some extra tools (e.g., Xcode for Mac users, and 
# Rtools for Windows users) to install gwDist.
# After installing Rtools run
find_rtools()
# and then install packages gwDist
devtools::install_github("rendrikson/gwDist")
library(gwDist)
# load metric measure spaces of 3D animal data into worksapce
data(mmspaces_3D)
# subset of metric measure spaces
mm_sub <- mmspaces_3D[c(12:16,61:65)]

# compute GW distance between 10 objects selected
gw_mat <- matrix(nrow = length(mm_sub), ncol = length(mm_sub))
for(i in 1:length(mm_sub))
{
      X <- mm_sub[[i]]$points
      d_X <- mm_sub[[i]]$dist
      mu_X <- mm_sub[[i]]$prob
      for(j in i:length(mm_sub))
      {
            Y <- mm_sub[[j]]$points
            d_Y <- mm_sub[[j]]$dist
            mu_Y <- mm_sub[[j]]$prob
            # compute initial values using solve_FLB_Rglpk
            sol <- solve_FLB_Rglpk(X,Y,d_X,d_Y,mu_X,mu_Y)$solution
            # compute Gromov-Wasserstein distance 
            gw_mat[i,j] <- gwDist(sol, d_X, d_Y, mu_X, mu_Y)$optimum
            gw_mat[j,i] <- gw_mat[i,j]
      }
}

rownames(gw_mat) <- colnames(gw_mat) <- names(mm_sub)
heatmap(gw_mat)


rendrikson/gwDist documentation built on May 27, 2019, 4:55 a.m.