##
##
# first generate candidate set
set.seed(123) # setting seed so that you get the same thing I do!
test.df <- matrix( runif( 600), ncol=3)
test1.des<-cover.design(R=test.df,nd=10)
summary( test1.des)
plot( test1.des)
#
candidates<- make.surface.grid( list( seq( 0,5,,20), seq(0,5,,20)))
out<- cover.design( candidates, 15)
# find 10 more points keeping this original design fixed
out3<-cover.design( candidates, 10,fixed=out$best.id)
# see what happened
plot( candidates[,1:2], pch=".")
points( out$design, pch="x")
points( out3$design, pch="o")
# here is a strange graph illustrating the swapping history for the
# the first design. Arrows show the swapping
#at each pass through the design.
h<- out$history
cd<- candidates
plot( cd[,1:2], pch=".")
points( out$design, pch="O", col=2)
points( out$start.design, pch="x", col=5)
arrows(
cd[h[,2],1],
cd[h[,2],2],
cd[h[,3],1],
cd[h[,3],2],length=.1)
text( cd[h[,2],1],
cd[h[,2],2], h[,1], cex=1.0 )
#
# try this out using "Manhattan distance"
# ( distance following a grid of city streets)
dist.man<- function(x1,x2) {
d<- ncol( x1)
temp<- abs(outer( x1[,1], x2[,1],'-'))
for ( k in 2:d){
temp<- temp+abs(outer( x1[,k], x2[,k],'-'))
}
temp }
# use the design from the Euclidean distance as the starting
#configuration.
cover.design( candidates, 15, DIST=dist.man, start= out3$best.id)-> out2
# this takes a while ...
plot( out2$design)
points( out3$design, col=2)
# find a design on the sphere
#
candidates<- make.surface.grid( list( x=seq( -180,180,,20), y= seq( -85,
85,,20)))
out4<-cover.design( candidates, 15, DIST=rdist.earth)
# this takes a while
plot( candidates, pch=".")
points(out4$design, pch="o", col=3)
# covering based on correlation for 153 ozone stations
#
data( ozone2)
cor.mat<-cor( ozone2$y, use="pairwise")
cor.dist<- function( x1,x2)
{matrix( 1-cor.mat[ x1,x2], ncol=length(x2))}
#
# find 25 points out of the 153
# here the "locations" are just the index but the distance is
# determined by the correlation function.
#
out5<-cover.design(cbind(1:153),25, DIST= cor.dist, scale.type="unscaled")
plot( ozone2$lon.lat, pch=".")
points( ozone2$lon.lat[out5$best.id,],pch="O", col=4)
#
# this seems a bit strange probably due some funny correlation values
#
# reset panel
set.panel(1,1)
Run the code above in your browser using DataLab