Learn R Programming

RiemBaseExt (version 0.1.2)

rstat.pdist2: Pairwise Distance for Two Sets of Data on Manifolds

Description

For two points \(x,y \in \mathcal{M}\), two modes of distances are available; intrinsic for geodesic distance on the manifold and extrinsic for standard norm after equivariant embedding into Euclidean space. This function differs from rstat.pdist in that it now computes distances between two sets of data.

Usage

rstat.pdist2(input1, input2, type = c("intrinsic", "extrinsic"))

Arguments

input1

a S3 object of riemdata class of \(N\) objects.

input2

a S3 object of riemdata class of \(M\) objects. See riemfactory for more details.

type

type of distance, either "intrinsic" or "extrinsic".

Value

an \((N\times M)\) matrix of pairwise distances.

See Also

rstat.pdist

Examples

Run this code
# NOT RUN {
### Generate 100 data points on Sphere S^2.
#   50 points from near (0,0,1), and
#   50 points from near (0,0,-1)

ndata = 50
theta = seq(from=-0.99,to=0.99,length.out=ndata)*pi
tmpx  = cos(theta)
tmpy  = sin(theta)

### Wrap those as 'riemdata' class
data1 = list()
data2 = list()
for (i in 1:ndata){
  tgt1 = c(tmpx[i],tmpy[i],1)  + stats::rnorm(3,sd=0.1)
  tgt2 = c(tmpx[i],tmpy[i],-1) + stats::rnorm(3,sd=0.1)
  
  data1[[i]] = tgt1/sqrt(sum(tgt1^2)) # projection near (0,0,1)
  data2[[i]] = tgt2/sqrt(sum(tgt2^2)) #                 (0,0,-1)  
}
spdata1 = RiemBase::riemfactory(data1, name="sphere")
spdata2 = RiemBase::riemfactory(data2, name="sphere")

### Compute Two Types of Distances and Visualize
dist.int = rstat.pdist2(spdata1, spdata2, type="intrinsic")
dist.ext = rstat.pdist2(spdata1, spdata2, type="extrinsic")

### Visualize
opar <- par(no.readonly=TRUE)
par(mfrow=c(1,2))
image(dist.int, main="intrinsic")
image(dist.ext, main="extrinsic")
par(opar)

# }

Run the code above in your browser using DataLab