Learn R Programming

RiemBase (version 0.1.0)

pdist2: Pairwise Geodesic Distances Between Two Sets of Data

Description

Unlike pdist, pdist2 takes two sets of data \(X=\{ x_i \}_{i=1}^m\) and \(Y=\{ y_j \}_{j=1}^m\) and compute \(mn\) number of pairwise distances for all \(i\) and \(j\).

Usage

pdist2(input1, input2, parallel = FALSE)

Arguments

input1

a S3 object of riemdata class, whose $data element is of length \(m\).

input2

a S3 object of riemdata class, whose $data element is of length \(n\).

parallel

a flag for enabling parallel computation.

Value

an \((m\times n)\) matrix of pairwise distances.

Examples

Run this code
# NOT RUN {
### Generate 10 2-frames in R^4 : as grassmann points
ndata = 10
data = array(0,c(4,2,ndata))
for (i in 1:ndata){
  tgt = matrix(rnorm(4*4),nrow=4)
  data[,,i] = qr.Q(qr(tgt))[,1:2]
}

gdata = riemfactory(data, name="grassmann")

## Compute Pairwise Distances using pdist and pdist2
A = pdist(gdata)
B = pdist2(gdata,gdata)

## Visual Comparison in Two Cases
par(mfrow=c(1,2), pty="s")
image(pracma::flipud(A), col=gray((0:100)/100), main="pdist")
image(pracma::flipud(B), col=gray((0:100)/100), main="pdist2")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab