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
|
discrepancyCriteria <- function(design, type='all'){
#---------------------------------------
# source code by Jessica FRANCO (2006.10.05)
# modified by Bertrand Iooss (2013.26.12)
#---------------------------------------
# inputs
# - design of experiments
# - type of dicrepancies to be computed
X <- as.matrix(design)
dimension <- dim(X)[2] # dimension
n <- dim(X)[1] # number of points
if ( n < dimension ){
stop('Warning : the number of points is lower than the dimension.')
}
# To check the experimental region
if ( min(X)<0 || max(X)>1 ){
warning("The design is rescaling into the unit cube [0,1]^d.")
M <- apply(X,2,max)
m <- apply(X,2,min)
for (j in 1:dim(X)[2]){
X[,j] <- (X[,j]-m[j])/(M[j]-m[j])
}
}
R <- list()
DisC2 <- FALSE
DisL2 <- FALSE
DisL2star <- FALSE
DisM2 <- FALSE
DisS2 <- FALSE
DisW2 <- FALSE
DisMix2 <- FALSE
if (length(type)==1 && type=='all'){
type <- c('C2','L2','L2star','M2','S2','W2','Mix2')
}
for(i in 1:length(type)){
type_ <- type[i]
switch(type_,
C2 = {DisC2 <- TRUE},
L2 = {DisL2 <- TRUE},
L2star = {DisL2star <- TRUE},
M2 = {DisM2 <- TRUE},
S2 = {DisS2 <- TRUE},
W2 = {DisW2 <- TRUE},
Mix2 = {DisMix2 <- TRUE})
}
# centered L2-discrepancy
#------------------------
if(DisC2 == TRUE){
s1 <- 0; s2 <- 0
for (i in 1:n){
p <- prod((1+0.5*abs(X[i,]-0.5)-0.5*((abs(X[i,]-0.5))^2)))
s1 <- s1+p
for (k in 1:n){
q <- prod((1+0.5*abs(X[i,]-0.5)+0.5*abs(X[k,]-0.5)-0.5*abs(X[i,]-X[k,])))
s2 <- s2+q
}
}
R <- c(R,DisC2 = sqrt(((13/12)^dimension)-((2/n)*s1) + ((1/n^2)*s2)))
}
# L2-discrepancy
#------------------------
if(DisL2 == TRUE){
s1 <- 0; s2 <- 0
for (i in 1:n){
p <- prod(X[i,]*(1-X[i,]))
s1 <- s1+p
for (k in 1:n){
q <- 1
for (j in 1:dimension){
q <- q*(1-max(X[i,j],X[k,j]))*min(X[i,j],X[k,j])
}
s2 <- s2+q
}
}
R <- c(R,DisL2 = sqrt(12^(-dimension) - (((2^(1-dimension))/n)*s1) + ((1/n^2)*s2)))
}
# L2star-discrepancy
#------------------------
if(DisL2star == TRUE){
dL2<-0
for (j in 1:n){
for (i in 1:n){
if(i!=j){
t<-c()
for (l in 1:dimension) t<-c(t,1-max(X[i,l],X[j,l]))
t<-(prod(t))/(n^2)
}
else{
t1<-1-X[i,]
t1<-prod(t1)
t2<-1-X[i,]^2
t2<-prod(t2)
t<-t1/(n^2)-((2^(1-dimension))/n)*t2
}
dL2<-dL2+t}
}
R <- c(R,DisL2star = sqrt(3^(-dimension)+dL2))
}
# modified L2-discrepancy
#------------------------
if(DisM2 == TRUE){
s1 <- 0; s2 <- 0
for (i in 1:n){
p <- 1
p <- prod((3-(X[i,]*X[i,])))
s1 <- s1+p
for (k in 1:n){
q <- 1
for (j in 1:dimension){
q <- q*(2-max(X[i,j],X[k,j]))
}
s2 <- s2+q
}
}
R <- c(R,DisM2 = sqrt(((4/3)^dimension) - (((2^(1-dimension))/n)*s1) + ((1/n^2)*s2)))
}
# symmetric L2-discrepancy
#------------------------
if(DisS2 == TRUE){
s1 <- 0; s2 <- 0
for (i in 1:n){
p <- prod((1+(2*X[i,])-(2*X[i,]*X[i,])))
s1 <- s1+p
for (k in 1:n){
q <- prod((1-abs(X[i,]-X[k,])))
s2 <- s2+q
}
}
R <- c(R,DisS2 = sqrt(((4/3)^dimension) - ((2/n)*s1) + ((2^dimension/n^2)*s2)))
}
# wrap-around L2-discrepancy
#------------------------
if(DisW2 == TRUE){
s1 <- 0
for (i in 1:n){
for (k in 1:n){
p <- prod((1.5-((abs(X[i,]-X[k,]))*(1-abs(X[i,]-X[k,])))))
s1 <- s1+p
}
}
R <- c(R , DisW2 = sqrt((-((4/3)^dimension) + ((1/n^2)*s1))))
}
# mixture L2-discrepancy
#------------------------
if(DisMix2 == TRUE){
s1 <- 0; s2 <- 0
for (i in 1:n){
p <- prod((5/3-0.25*abs(X[i,]-0.5)-0.25*((abs(X[i,]-0.5))^2)))
s1 <- s1+p
for (k in 1:n){
q <- prod((15/8-0.25*abs(X[i,]-0.5)-0.25*abs(X[k,]-0.5)-0.75*abs(X[i,]-X[k,])+0.5*((abs(X[i,]-X[k,]))^2)))
s2 <- s2+q
}
}
R <- c(R,DisMix2 = sqrt(((19/12)^dimension)-((2/n)*s1) + ((1/n^2)*s2)))
}
return(R)
}
|