# NOT RUN {
# }
# NOT RUN {
# 20+20-point sequential minimax design on the hypercube [0,1]^2
Nini <- 20
Nseq <- 20
Dini <- matrix(runif(Nini*2),ncol=2) # random initial design
Dseq <- minimax.seq(Dini,Nseq) # sequential minimax design
plot(NULL,xlim=c(0,1),ylim=c(0,1),xlab="x1",ylab="x2") #set up plot
polygon(c(0,0,1,1),c(0,1,1,0),col="gray") #design space
points(Dini,xlim=c(0,1),ylim=c(0,1),xlab="x1",ylab="x2",pch=16) #original design
points(Dseq,xlim=c(0,1),ylim=c(0,1),xlab="x1",ylab="x2",pch=16,col="blue") #sequential design
# 20+20-point sequential minimax design on active subspace
set.seed(1)
library(rstiefel)
library(geometry)
p.full <- 10 #full dimension
p.as <- 2 #active subspace dimension
Nini <- 20
Nseq <- 20
Dini <- matrix(runif(Nini*p.full),ncol=p.full) # random initial design
A <- rustiefel(p.full,p.as) # random active subspace
Dini <- t(t(A)%*%t(Dini)) # initial design projected on active subspace
# sequential minimax design
Dseq <- minimax.seq(Dini,Nseq=20,region="subspace",subsp=A,wt.subsp=TRUE)
# Compute active subspace polygon
Nplot <- 1e5
plot.pts <- matrix(runif(Nplot*p.full),ncol=p.full)
plot.pts <- t(t(A)%*%t(plot.pts))
hull <- convhulln(plot.pts)
for (i in 2:nrow(hull)){
newidx <- setdiff(c(which(hull[,2]==hull[i-1,2]),which(hull[,1]==hull[i-1,2])),i-1)
if (hull[newidx,1]==hull[i-1,2]){
tmp <- hull[newidx,]
hull[newidx,] <- hull[i,]
hull[i,] <- tmp
}else{
tmp <- rev(hull[newidx,])
hull[newidx,] <- hull[i,]
hull[i,] <- tmp
}
}
# Visualize
plot(NULL,xlim=c(-2,2),ylim=c(-2,2),xlab="x1",ylab="x2") #set up plot
polygon(plot.pts[hull[,1],],lwd=2,col="gray") #plot active subspace
points(Dini,xlab="x1",ylab="x2",pch=16) #original design
points(Dseq,xlab="x1",ylab="x2",pch=16,col="blue") #sequential design
# }
Run the code above in your browser using DataLab