-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.functions.R
145 lines (127 loc) · 4.24 KB
/
core.functions.R
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
library(DiceKriging)
# function to compute the three options for bi-objective. Options are different in terms
# of the uncertainty quantification
# - Improvement vs sigma
# - Improvement vs entropy
# - Improvement vs inverse-distance
all.objectives <- function( gp, X.grid, f.min=T ) {
pred <- predict( gp, data.frame(X.grid), "UK", checkNames=F )
# ei
if( f.min ) {
y.best <- min( gp@y )
ei <- y.best - pred$sd
} else {
y.best <- max( gp@y )
ei <- pred$sd - y.best
}
# sigma-uncertainty
u.sigma <- pred$sd
# entropy-uncertainty
#u.H <- 0.5 * log(2*pi*exp(1)*pred$sd^2)
u.H <- numeric(nrow(X.grid) )
for( j in 1:length(u.H) ) {
K_ <- covMatrix(object=gp@covariance,X=as.matrix(c(gp@X,X.grid[j,])),noise.var=gp@noise.var)
u.H[j] <- 0.5 * ( log( det(K_$C) ) + ncol(gp@X) * log(2*pi*exp(1)) )
}
u.H[ which( is.na(u.H) | is.nan(u.H) | is.infinite(u.H) ) ] <- min(u.H,na.rm=T)
if( is.infinite( min(u.H) ) ) {
u.H <- numeric(nrow(X.grid) )
}
# inverse.distance-uncertainty
u.z <- numeric(nrow(X.grid))
for( j in 1:nrow(X.grid) ) {
tmp <- matrix(0,ncol=2,nrow=nrow(gp@X))
for( h in 1:nrow(tmp) )
tmp[h,] <- X.grid[j,]
dists <- sqrt( apply( (gp@X - tmp)^2, 1, sum ) )
if( min(dists) > 10^-8 ) {
u.z[j] <- (2/pi)*atan( 1 / sum( exp(-(dists^2)) / (dists^2) ) )
}
}
return( list( ei=ei, u.sigma=u.sigma, u.H=u.H, u.z=u.z) )
}
# function to identify points on the Pareto efficient frontier
pareto.frontier <- function( obj1, obj2 ) {
stopifnot( length(obj1)==length(obj2) )
ixs <- NULL
for( i in 1:length(obj1) ) {
if( length( which( obj1>obj1[i] & obj2>obj2[i] ) ) == 0 )
ixs <- c( ixs, i )
}
return( cbind(obj1[ixs],obj2[ixs]) )
}
# function to compute the distabce of a point from a Pareto frontier
pareto.dist <- function( psi_, obj1, obj2 ) {
stopifnot( is.numeric(psi_) )
obj1 <- c( psi_[1], obj1 )
obj2 <- c( psi_[2], obj2 )
front <- pareto.frontier( obj1, obj2 )
tmp <- matrix(0,nrow=nrow(front),ncol=2)
for( i in 1:nrow(tmp) )
tmp[i,] <- psi_
d <- min( sqrt( apply( (front - tmp)^2, 1, sum ) ) )
return( d )
}
# pre-fixed grid of points where each test function used in the experiments
grid.for.function <- function( function.name ) {
if( function.name=="ackley" ) {
Xs1 <- seq(-32.768,32.768,length.out=30)
Xs2 <- seq(-32.768,32.768,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="beale" ) {
Xs1 <- seq(-4.5,4.5,length.out=30)
Xs2 <- seq(-4.5,4.5,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="branin" ) {
Xs1 <- seq(-5,10,length.out=30)
Xs2 <- seq(-0,15,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="bukin6" ) {
Xs1 <- seq(-15.5,-5,length.out=30)
Xs2 <- seq(-3,3,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="goldpr" ) {
Xs1 <- seq(-2,2,length.out=30)
Xs2 <- seq(-2,2,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="griewank" ) {
Xs1 <- seq(-600,600,length.out=30)
Xs2 <- seq(-600,600,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="levy" ) {
Xs1 <- seq(-10,10,length.out=30)
Xs2 <- seq(-10,10,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="rastr" ) {
Xs1 <- seq(-5.12,5.12,length.out=30)
Xs2 <- seq(-5.12,5.12,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="schwef" ) {
Xs1 <- seq(-500,500,length.out=30)
Xs2 <- seq(-500,500,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
if( function.name=="stybtang" ) {
Xs1 <- seq(-5,5,length.out=30)
Xs2 <- seq(-5,5,length.out=30)
XX <- cbind( sort(rep(Xs1,length(Xs2))), rep(Xs2,length(Xs1)) )
return( XX )
}
}