hausdorff: Hausdorff Distance

Description Usage Examples

View source: R/geo_hausdorff.R

Description

Hausdorff Distance

Usage

1
hausdorff(dxy)

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
33
34
35
36
37
38
39
40
## Not run: 
## create two datasets from bivariate normal
## let's try to see the evolution of Hausdorff distance
nmax = 1000
X = matrix(rnorm(nmax*2),ncol=2) # obs. for X
Y = matrix(rnorm(nmax*2),ncol=2) # obs. for Y

## compute cross-distance between X and Y
dXY = array(0,c(nmax,nmax))
for (i in 1:nmax){
  vx = as.vector(X[i,])
  for (j in 1:nmax){
    vy  = as.vector(Y[j,])
    dXY[i,j] = sqrt(sum((vx-vy)^2))
  }
}

## compute
ndraw = 500
xgrid = 2:ndraw
ygrid = rep(0,ndraw-1)
for (i in 1:(ndraw-1)){
  ytmps = rep(0,10)
  for (j in 1:10){
    id1 = base::sample(1:nmax, i+1)
    id2 = base::sample(1:nmax, i+1)
    pXY = dXY[id1,id2]
    ytmps[j] = hausdorff(pXY)$distance
  }
  ygrid[i] = base::mean(ytmps)
  print(paste("Iteration ",i+1,"/",ndraw," Complete..",sep=""))
}

## visualize
opar <- par(pty="s")
plot(xgrid, ygrid, "b", lwd=1, main="Evolution of Average Hausdorff Distance from 10 Runs",
     xlab="number of samples", ylab="distance", pch=18)
par(opar)

## End(Not run)

kisungyou/DAS documentation built on Jan. 6, 2020, 7:09 a.m.