GeoRatio_graph: Building GeoRatio Graph

Description Usage Arguments Value Examples

Description

Takes in data, minimum nbhd size, maximum nbhd size, intrinsic dimension, variance threshold and construct a graph for estimating GeoRatio measure

Usage

1
2
GeoRatio_graph(X, k_max = k_M, k_min = k_m, d, thresh = 0.9,
  gmode = "max", distance = NaN)

Arguments

X

Data.

k_max

maximum neighborhood size

k_min

minimum neighborhood size

d

intrinsic dimension

thresh

threshold of proportion of variance explained by d leading eigenvalues in each neighborhood

gmode

graph edge choosing

distance

if data passed in is a distance matrix

Value

a list of GeoRatio dissimilarity, geodesic distance, nbhd adjacency matrix, weighted graph, nbhd size

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
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
############################## example I: V-shape
## package for pam() kmeans clustering
library(cluster)
library(igraph) ## used by GeoRatio_graph

## load data
data(V_shape)

## intrinsic dimension of the data
trueDim = 1

############## correlation dimension estimation
## number of epsilons
num = 50

## pair-wise Euclidean distance
dis = dist(V_shape,method = "euclidean", diag = FALSE, upper = TRUE)

## correlation dimension estimation
est = correDimEst(num,dis)

## plot correlation dimension estimation
par(mfrow=c(1,1))
plot(est$x[2:(length(est$x)-1)],est$deri,type="l",ylim=c(0,10),xlab="log(epsilon)",ylab="est. correlation dimension",
     main="Estimated correlation dimension")
abline(trueDim,0,lty=3,col="gray60",lwd=2)

##### decide k_M (plateau log(epsi) from -4.8 to -2.8)
epsi_s = -4.5
epsi_e = -2.5
epsi_seq = seq(epsi_s,epsi_e,length=5)

dis_L2 = as.matrix(dist(V_shape))

for(i in 1:length(epsi_seq)){
  epsi = epsi_seq[i]
  dist_thre = exp(epsi)
  epsi_nbhd = apply(dis_L2,1,function(x) sum(x<dist_thre))
  avg_epsi_nbhd = mean(epsi_nbhd)
  print(epsi)
  print(avg_epsi_nbhd)
}

## parameters for GeoRatio_graph()
K = 2
k_M = 15
k_m = 3
pca_thre = 0.9

set.seed(100)

V_GR = GeoRatio_graph(V_shape,k_max=k_M,k_min=k_m,trueDim,thresh=pca_thre,gmode="max")

dis_L2 = dist(V_shape)
dis_G = as.dist(V_GR$dis_G)
dis_GR = as.dist(V_GR$dis_GR)

hc_L2 = hclust(dis_L2,method="average")
hc_G = hclust(dis_G,method="average")
hc_GR = hclust(dis_GR,method="average")

indi_KML2 = pam(dis_L2,K,diss=T)$clustering
indi_KMG = pam(dis_G,K,diss=T)$clustering
indi_KMGR = pam(dis_GR,K,diss=T)$clustering
indi_HL2 = cutree(hc_L2,k=K)
indi_HG = cutree(hc_G,k=K)
indi_HGR = cutree(hc_GR,k=K)

lpca_V = kplanes(V_shape,K,trueDim,iter.max=100,thresh=1e-5)
indi_lpca = lpca_V$indicator

par(mfrow=c(3,3))
plot(V_shape,col=indi_HGR,main="HC-GR")
plot(V_shape,col=indi_HG,main="HC-G")
plot(V_shape,col=indi_HL2,main="HC-L2")
plot(V_shape,col=indi_KMGR,main="KMC-GR")
plot(V_shape,col=indi_KMG,main="KMC-G")
plot(V_shape,col=indi_KML2,main="KMC-L2")
plot(V_shape,col=indi_lpca,main="LPCA")

############################## example II: Swiss roll
## package for 3d plot
library(rgl)
## package for pam() kmeans clustering
library(cluster)

library(igraph) ## used by GeoRatio_graph

## load data
data(SwissRoll)

## intrinsic dimension of the data
trueDim = 2

############## correlation dimension estimation
## number of epsilons
num = 50

## pair-wise Euclidean distance
dis = dist(SwissRoll,method = "euclidean", diag = FALSE, upper = TRUE)

## correlation dimension estimation
est = correDimEst(num,dis)

## plot correlation dimension estimation
par(mfrow=c(1,1))
plot(est$x[2:(length(est$x)-1)],est$deri,type="l",ylim=c(0,10),xlab="log(epsilon)",ylab="est. correlation dimension",
     main="Estimated correlation dimension")
abline(trueDim,0,lty=3,col="gray60",lwd=2)

##### decide k_M (plateau log(epsi) from -4.8 to -2.8)
epsi_s = -1.2
epsi_e = 1.8
epsi_seq = seq(epsi_s,epsi_e,length=5)

dis_L2 = as.matrix(dist(SwissRoll))

for(i in 1:length(epsi_seq)){
  epsi = epsi_seq[i]
  dist_thre = exp(epsi)
  epsi_nbhd = apply(dis_L2,1,function(x) sum(x<dist_thre))
  avg_epsi_nbhd = mean(epsi_nbhd)
  print(epsi)
  print(avg_epsi_nbhd)
}

## number of clusters
K = 8
k_M = 15
k_m = 4
pca_thre = 0.9

set.seed(100)

SwissRoll_GR = GeoRatio_graph(SwissRoll,k_max=k_M,k_min=k_m,trueDim,thresh=pca_thre,gmode="max")

dis_L2 = dist(SwissRoll)
dis_G = as.dist(SwissRoll_GR$dis_G)
dis_GR = as.dist(SwissRoll_GR$dis_GR)

hc_L2 = hclust(dis_L2,method="average")
hc_G = hclust(dis_G,method="average")
hc_GR = hclust(dis_GR,method="average")

indi_KML2 = pam(SwissRoll,K)$clustering
indi_KMG = pam(dis_G,K,diss=T)$clustering
indi_KMGR = pam(dis_GR,K,diss=T)$clustering
indi_HL2 = cutree(hc_L2,k=K)
indi_HG = cutree(hc_G,k=K)
indi_HGR = cutree(hc_GR,k=K)

lpca_V = kplanes(SwissRoll,K,trueDim,iter.max=100,thresh=1e-5)
indi_lpca = lpca_V$indicator

open3d()
plot3d(SwissRoll,col=indi_HGR,main="HC-GR")
open3d()
plot3d(SwissRoll,col=indi_HG,main="HC-G")
open3d()
plot3d(SwissRoll,col=indi_HL2,main="HC-L2")
open3d()
plot3d(SwissRoll,col=indi_KMGR,main="KMC-GR")
open3d()
plot3d(SwissRoll,col=indi_KMG,main="KMC-G")
open3d()
plot3d(SwissRoll,col=indi_KML2,main="KMC-L2")
open3d()
plot3d(SwissRoll,col=indi_lpca,main="LPCA")

############################## example III: Open box
## package for 3d plot
library(rgl)
## package for pam() kmeans clustering
library(cluster)
library(igraph) ## used by GeoRatio_graph

## load data
data(OpenBox)

## intrinsic dimension of the data
trueDim = 2

############## correlation dimension estimation
## number of epsilons
num = 50

## pair-wise Euclidean distance
dis = dist(OpenBox,method = "euclidean", diag = FALSE, upper = TRUE)

## correlation dimension estimation
est = correDimEst(num,dis)

## plot correlation dimension estimation
par(mfrow=c(1,1))
plot(est$x[2:(length(est$x)-1)],est$deri,type="l",ylim=c(0,10),xlab="log(epsilon)",ylab="est. correlation dimension",
     main="Estimated correlation dimension")
abline(trueDim,0,lty=3,col="gray60",lwd=2)

##### decide k_M (plateau log(epsi) from -4.8 to -2.8)
epsi_s = -3.5
epsi_e = 0
epsi_seq = seq(epsi_s,epsi_e,length=5)

dis_L2 = as.matrix(dist(OpenBox))

for(i in 1:length(epsi_seq)){
  epsi = epsi_seq[i]
  dist_thre = exp(epsi)
  epsi_nbhd = apply(dis_L2,1,function(x) sum(x<dist_thre))
  avg_epsi_nbhd = mean(epsi_nbhd)
  print(epsi)
  print(avg_epsi_nbhd)
}

## number of clusters
K = 6
k_M = 20
k_m = 4
pca_thre = 0.9

set.seed(100)

OpenBox_GR = GeoRatio_graph(OpenBox,k_max=k_M,k_min=k_m,trueDim,thresh=pca_thre,gmode="max")

dis_L2 = dist(OpenBox)
dis_G = as.dist(OpenBox_GR$dis_G)
dis_GR = as.dist(OpenBox_GR$dis_GR)

hc_L2 = hclust(dis_L2,method="average")
hc_G = hclust(dis_G,method="average")
hc_GR = hclust(dis_GR,method="average")

indi_KML2 = pam(dis_L2,K,diss=T)$clustering
indi_KMG = pam(dis_G,K,diss=T)$clustering
indi_KMGR = pam(dis_GR,K,diss=T)$clustering
indi_HL2 = cutree(hc_L2,k=K)
indi_HG = cutree(hc_G,k=K)
indi_HGR = cutree(hc_GR,k=K)

lpca_V = kplanes(OpenBox,K,trueDim,iter.max=100,thresh=1e-5)
indi_lpca = lpca_V$indicator

open3d()
plot3d(OpenBox,col=indi_HGR,main="HC-GR",xlim=c(0,2),ylim=c(0,2),zlim=c(0,2))
open3d()
plot3d(OpenBox,col=indi_HG,main="HC-G",xlim=c(0,2),ylim=c(0,2),zlim=c(0,2))
open3d()
plot3d(OpenBox,col=indi_HL2,main="HC-L2",xlim=c(0,2),ylim=c(0,2),zlim=c(0,2))
open3d()
plot3d(OpenBox,col=indi_KMGR,main="KMC-GR",xlim=c(0,2),ylim=c(0,2),zlim=c(0,2))
open3d()
plot3d(OpenBox,col=indi_KMG,main="KMC-G",xlim=c(0,2),ylim=c(0,2),zlim=c(0,2))
open3d()
plot3d(OpenBox,col=indi_KML2,main="KMC-L2",xlim=c(0,2),ylim=c(0,2),zlim=c(0,2))
open3d()
plot3d(OpenBox,col=indi_lpca,main="LPCA",xlim=c(0,2),ylim=c(0,2),zlim=c(0,2))

Yanhao29/GeoRatio documentation built on May 10, 2019, 12:05 a.m.