set.seed(123456)
nvert <- 100 #number of vertices in the network
npp <- 5 #number of data point patterns
npts <- 40 #number of points per data point pattern
ln <- delaunayNetwork(runifpoint(nvert)) #create an artificial network
ppnetwork <- runiflpp(npts,ln,nsim = npp)
#simulate npp point patterns with npts points each
plot(ppnetwork[[1]]$domain, cex=0.5, main="")
for (i in 1:npp) {
plot(as.ppp(ppnetwork[[i]]),vpch=1,col=i,add=TRUE)
#plotting the point patterns in different colors
}
res <- netsplit(ln, ppnetwork)
#incorporate data point patterns into the network
#calculating all pairwise distances between vertices
#and creating matrix of vertex-indices of data point patterns
zeta <- sample(res$nvirtual - 1, median(res$dimensions))
#sample random vertex-indices in the network
#taking as cardinality the median of point pattern cardinalities
res2 <- kmeansbarynet(res$network$dpath, zeta, res$ppmatrix, penalty = 0.1)
barycenter <- ppp(res$network$vertices$x[res2$barycenter], res$network$vertices$y[res2$barycenter])
#construct the barycenter pattern based on the index information in res2
points(barycenter,cex = 1.2, lwd = 2, pch = 4, col = "magenta")
#add the computed barycenter as magenta crosses
res2$cost
#[1] 18.35171
sumppdistnet(res$network$dpath, res2$barycenter, res$ppmatrix, penalty=0.1, type="tt", p=1, q=1)
#[1] 18.35171
#attr(,"distances")
#[1] 3.666471 3.774709 3.950079 3.841166 3.119284
Run the code above in your browser using DataLab