The function gromovdist calculates the matched Gromov-\(\ell^p\) distances of two metrics on a finite space \(X\):
$$D_p(\rho_1,\rho_2)=\inf\{\|(|d(\phi_1(x),\phi_2(x))|)_{x \in X}\|_p\}.$$
There, the infimum is taken over all isometric embeddings \(\phi_1\) of \((X,\rho_1)\), \(\phi_2\) of \((X,\rho_2)\) into a common metric space \((Y,d)\). Only \(1\le p\le \infty\) is considered.
At the basis is the reformulation of the metric as value of a convex program, see Liebscher (2015).
Methods for various classes are provided:
dist,dissimilarity which are distance matrices.
matrix for matrices containing the individual distances of the elements of \(X\).
igraph for connected graphs. The metric on the nodes or just the leaves (nodes of degree 1) of the graph is the length of the shortest path.
phylo for phylogenetic trees. Again the metric is induced by the graph.
gromovdist(d1,d2=NULL,type="l1",p=NULL,...)# S3 method for list
gromovdist(d1,d2=NULL,type="l1",p=NULL,...)
# S3 method for multiPhylo
gromovdist(d1,d2=NULL,type="l1",p=NULL,...)
# S3 method for phylo
gromovdist(d1,d2=NULL,type="l1",p=NULL,...)
# S3 method for dist
gromovdist(d1,d2=NULL,type="l1",p=NULL,...)
# S3 method for dissimilarity
gromovdist(d1,d2=NULL,type="l1",p=NULL,...)
# S3 method for matrix
gromovdist(d1,d2=NULL,type="l1",p=NULL,...)
# S3 method for igraph
gromovdist(d1,d2=NULL,type="l1",p=NULL,leavesonly=TRUE,...)
type of metric to use
distance object(s).
if type="lp" the value of \(p\). If not supplied, \(p=2\) is used.
compute the distances between the leaves of the graph/tree only?
further parameters
The distance (one numeric) or a distance matrix for the list and multiPhylo methods
type="l1" yields \(p=1\)
type="l2" yields \(p=2\)
type="linfinity" yields \(p=\infty\)
type="lp" is for (not so efficient) computation using constrOptim for arbitrary \(1\le p<\infty\)
If d1 is a list, the distance matrix between all elements of the list is computed. It is represented as an object of class dissimiliarity, see dissimilarity.object.
The distance is only computed for that part of the objects where the labels are present in both objects. If there are no labels the elements are numbered consecutively.
V.Liebscher, Gromov meets Phylogenetics - new Animals for the Zoo of Metrics on Tree Space. preprint 2015 arXiv:1504.05795
dist, dissimilarity.object,phangorn-package, igraph-package,constrOptim.
# NOT RUN {
library("ape")
tr1<-rtree(n=10)
tr2<-rtree(n=10)
gromovdist(tr1,tr2,"l1")
gromovdist(tr1,tr2,"l2")
#thesame, but slower
gromovdist(d1=tr1,d2=tr2,type="lp",p=2)
gromovdist(tr1,tr2,"linf")
# }
Run the code above in your browser using DataLab