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

Description Usage Arguments Value See Also Examples

View source: R/rstat.pdist2.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
### 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)

RiemBaseExt documentation built on March 26, 2020, 5:52 p.m.