Advertisement
Guest User

ftg

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