# NOT RUN {
# define objective function
funGauss <- function (x) {
gauss <- function(par) {
y <- c(0.0009, 0.0044, 0.0175, 0.0540, 0.1295, 0.2420, 0.3521, 0.3989,
0.3521, 0.2420, 0.1295, 0.0540, 0.0175, 0.0044, 0.0009)
m <- 15
x1 <- par[1]
x2 <- par[2]
x3 <- par[3]
fsum <- 0
for (i in 1:m) {
ti <- (8 - i) * 0.5
f <- x1 * exp(-0.5 * x2 * (ti - x3) ^ 2) - y[i]
fsum <- fsum + f * f
}
return(fsum)
}
matrix(apply(x, # matrix
1, # margin (apply over rows)
gauss),
, 1) # number of columns
}
# define starting point
x1 <- matrix(c(1,1,1),1,)
funGauss(x1)
# define boundaries
lower = c(-0.001,-0.007,-0.003)
upper = c(0.5,1.0,1.1)
res <- spot(,funGauss, lower=lower, upper=upper, control=list(funEvals=15))
control = list(scale=TRUE) #pca control list, # scale the variables
plotPCA(res$x, control=control) # plot first two PCAs
# }
Run the code above in your browser using DataLab