RiemGrassmann (version 0.1.0)

gr.pdist: Pairwise Distance for Data on Grassmann Manifold

Description

For data on grassmann manifold \(x_1,x_2,\ldots,x_N \in Gr(k,n)\), compute pairwise distances \(d(x_i,x_j)\) via several metrics. The distance type "intrinsic" corresponds to geodesic distance while "extrinsic" is equivalent to "chordal" distance.

Usage

gr.pdist(
  input,
  type = c("Intrinsic", "Extrinsic", "Asimov", "Binet-Cauchy", "Chordal",
    "Fubini-Study", "Martin", "Procrustes", "Projection", "Spectral"),
  as.dist = TRUE,
  useR = FALSE
)

Arguments

input

either an array of size \((n\times k\times N)\) or a list of length \(N\) whose elements are \((n\times k)\) orthonormal basis (ONB) on Grassmann manifold.

type

type of distance measure. Name of each type is Case Insensitive and hyphen can be omitted.

as.dist

a logical; TRUE to return a dist object or FALSE to return an \((N\times N)\) symmetric matrix.

useR

a logical; TRUE to use R computations while FALSE goes everything in C++.

Value

a dist object or \((N\times N)\) symmetric matrix depending on as.dist.

Examples

Run this code
# NOT RUN {
## generate a dataset with two types of Grassmann elements
#  group1 : first four columns of (8x8) identity matrix + noise
#  group2 : last  four columns of (8x8) identity matrix + noise

mydata = list()
sdval  = 0.25
diag8  = diag(8)
for (i in 1:10){
  mydata[[i]] = qr.Q(qr(diag8[,1:4] + matrix(rnorm(8*4,sd=sdval),ncol=4)))
}
for (i in 11:20){
  mydata[[i]] = qr.Q(qr(diag8[,5:8] + matrix(rnorm(8*4,sd=sdval),ncol=4)))
}

## try 'intrinsic' distance using C++ implementation
dmat = gr.pdist(mydata, type="intrinsic", as.dist=FALSE)
opar = par(no.readonly=TRUE)
par(pty="s")
image(dmat, main="intrinsic distance")
par(opar)

# }
# NOT RUN {
## compute and visualize distances for all types
#  we will iterate over all measures
alltypes = c("intrinsic","extrinsic","asimov","binet-cauchy",
"chordal","fubini-study","martin","procrustes","projection","spectral")
ntypes   = length(alltypes)

opar <- par(no.readonly=TRUE)
par(mfrow=c(2,5), pty="s")
for (i in 1:ntypes){
  dmat = gr.pdist(mydata, type=alltypes[i], as.dist=FALSE)
  image(dmat[,20:1], main=alltypes[i])
}
par(opar)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab