## Not run:
# ## Load data
# data(COSha10)
# data(COSha10map)
# data(lalib)
#
# ## Calculate the sample variogram for data, generate the variogram model and
# ## fit ranges and/or sills from the variogram model to the sample variogram
# ve <- variogram(CorT~ 1, loc=~x+y, data=COSha10, width = 230.3647)
# PSI <- 0.0005346756; RAN <- 1012.6411; NUG <- 0.0005137079
# m.esf <- vgm(PSI, "Sph", RAN, NUG)
# (m.f.esf <- fit.variogram(ve, m.esf))
#
# ## Optimize the location of the first additional point
# ## Only 15 generations are evaluated in this example (using ordinary kriging)
# ## Users can visualize how the location of the additional point is optimized
# ## if plotMap is set to TRUE
# old.par <- par(no.readonly = TRUE)
# par(ask=FALSE)
# optpt <- seqPtsOptNet(CorT~ 1, loc=~x+y, COSha10, m.f.esf, popSize=30,
# generations=15, xmin=bbox(lalib)[1], ymin=bbox(lalib)[2], xmax=bbox(lalib)[3],
# ymax=bbox(lalib)[4], plotMap=TRUE, spMap=lalib)
# par(old.par)
#
# ## Summary of the genetic algorithm results
# summary(optpt, echo=TRUE)
#
# ## Graph of best and mean evaluation value of the objective function
# ## (average standard error) along generations
# plot(optpt)
#
# ## Find and plot the best set of additional points (best chromosome) in
# ## the population in the last generation
# (bnet1 <- bestnet(optpt))
# l1 = list("sp.polygons", lalib)
# l2 = list("sp.points", bnet1, col="green", pch="*", cex=5)
# spplot(COSha10map, "var1.pred", main="Location of the optimized point",
# col.regions=bpy.colors(100), scales = list(draw =TRUE), xlab ="East (m)",
# ylab = "North (m)", sp.layout=list(l1,l2))
#
# ## Average standard error of the optimized sequential point
# min(optpt$evaluations)
#
# ## Optimize the location of the second sequential point, taking into account
# ## the first one
# plot(lalib)
# old.par <- par(no.readonly = TRUE)
# par(ask=FALSE)
# optpt2 <- seqPtsOptNet(CorT~ 1, loc=~x+y, COSha10, m.f.esf, prevSeqs=bnet1,
# popSize=30, generations=15, xmin=bbox(lalib)[1], ymin=bbox(lalib)[2],
# xmax=bbox(lalib)[3], ymax=bbox(lalib)[4], plotMap=TRUE, spMap=lalib)
# par(old.par)
#
# ## Find the second optimal sequential point and use it, along with the first
# ## one, to find another optimal sequential point, and so on iteratively
#
# bnet2 <- bestnet(optpt2)
# bnet <- rbind(bnet1, bnet2)
#
# old.par <- par(no.readonly = TRUE)
# par(ask=FALSE)
# optpt3 <- seqPtsOptNet(CorT~ 1, loc=~x+y, COSha10, m.f.esf, prevSeqs=bnet,
# popSize=30, generations=25, xmin=bbox(lalib)[1], ymin=bbox(lalib)[2],
# xmax=bbox(lalib)[3], ymax=bbox(lalib)[4], plotMap=TRUE, spMap=lalib)
# par(old.par)
# ## End(Not run)
## Multivariate prediction is also enabled:
## Not run:
# ve <- variogram(CorT~ DA10, loc=~x+y, data=COSha10, width = 230.3647)
# (m.f.esf <- fit.variogram(ve, m.esf))
#
# optptMP <- seqPtsOptNet(CorT~ DA10, loc=~x+y, COSha10, m.f.esf, popSize=30,
# generations=25, xmin=bbox(lalib)[1], ymin=bbox(lalib)[2], xmax=bbox(lalib)[3],
# ymax=bbox(lalib)[4], plotMap=TRUE, spMap=lalib)
# ## End(Not run)
Run the code above in your browser using DataLab