Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f <- function(x){
- return( x[1]^2 + x[2]^2)
- }
- MUES <- function(mu,s1,lambda,precision){
- m <- runif(2,min = -5, max=5)
- fm <- f(m)
- u <- c(fm)
- w <- log(mu+0.5) - log(1:mu)
- w<-w/sum(w)
- 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:mu){
- m <- m + w[j] * children[ind[j],]
- }
- fm <- f(m)
- u <- c(u,fm)
- }
- return(list(x=m, dyn=u))
- }
- main <- function(){
- res <- MUES(10,0.1,100,10^-3)
- cat(res$x,"\n")
- plot(res$dyn, log="xy", ylim=c(10^-10, 100), xlim=c(1,1000), type="l")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement