Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f <- function(x){
- return( x[1]^2 + x[2]^2)
- }
- onePlusOnesES <- function(s1,lambda,precision){
- m <- runif(2,min = -5, max=5)
- fm <- f(m)
- dyn = c(fm)
- w <- log (s1 +0.5) - log(1:s1)
- while(abs(fm)>precision){
- children <- array(dim=c(lambda,2))
- fchildren <- c()
- for(i in 1:lambda){
- xprime <- m + rnorm(n=2,mean =0,sd = s1)
- fxprime <- f(xprime)
- children[1,] <- xprime
- fchildren <- c(fchildren,fxprime)
- }
- ind <- order(fchildren)
- m <- c(0,0)
- for(j in 1:s1){
- m <- m + w[j] * children[ind[j],]
- }
- fm <- f(m)
- dyn <- c(dyn,fm)
- }
- return(list(x=m, dyn=u))
- }
- main <- function(){
- res <- onePlusOnesES(0.1,100,10^-3)
- cat(res$x,"\n")
- res1 <- onePlusOnesES(0.1,100,10^-8)
- res2 <- onePlusOnesES(0.1,100,10^-8)
- plot(res$dyn, log="xy", ylim=c(10^-10, 100), xlim=c(1,1000), type="l")
- lines(res1$dyn, col="red")
- lines(res2$dyn, col="blue")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement