Advertisement
Guest User

kdo

a guest
Dec 13th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. f <- function(x){
  2. return( x[1]^2 + x[2]^2)
  3. }
  4.  
  5. onePlusOnesES <- function(s1,lambda,precision){
  6. m <- runif(2,min = -5, max=5)
  7. fm <- f(m)
  8. u <- c(fm).
  9. children <- array(dim=c(lambda,2))
  10. fchildren <- c()
  11.  
  12. while(abs(fm)>precision){
  13. for(i in 1:lambda){
  14. xprime <- m + rnorm(n=2,mean =0,sd = s1)
  15. fxprime <- f(xprime)
  16. children[1,] <- xprime
  17. fchildren <- c(fchildren,fxprime)
  18. }
  19.  
  20. ind <- order(fchildren)
  21. m <- c(0,0)
  22. for(j in 1:si){
  23. m <- m + w[j] * children[ind,j,]
  24. }
  25. }
  26.  
  27. return(list(x=m, dyn=u))
  28. }
  29.  
  30. main <- function(){
  31. res <- onePlusOnesES(0.1,10^-3)
  32. cat(res$x,"\n")
  33. res1 <- onePlusOnesES(0.1,10^-8)
  34. res2 <- onePlusOnesES(0.1,10^-8)
  35. plot(res$dyn, log="xy", ylim=c(10^-10, 100), xlim=c(1,1000), type="l")
  36. lines(res1$dyn, col="red")
  37. lines(res2$dyn, col="blue")
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement