R/ES.update.R

ES.update <-
function(para,fitness,cutoff){
  sur<-vector()
  ind<-order(fitness,decreasing=TRUE)
  
  for(i in 1:cutoff){
    sur<-rbind(sur,para[ind[i],])
  }
  ### now, sur would be the 1/4 best parameter we have
  
  for(j in 1:(cutoff/2)){
    indc<-sample(1:13,size=6,replace=FALSE)
    v1<-sur[j,]
    v1[indc]<-sur[j+cutoff/2,][indc]
    v2<-sur[j+cutoff/2,]
    v2[indc]<-sur[j,][indc]
    sur<-rbind(sur,v1,v2)
    
    if(sum(is.na(sur>0))){
      stop(paste("there is error",j))
    }
    
  }
  ### now, we have 1/2 size population, where we have crossovers from the relatively good parameters
  v3<-random_parameter(cutoff)
  for(p in 1:cutoff){
    indc<-sample(1:13,size=sample(1:12,size=1),replace=FALSE)
    v3[p,][indc]<-sur[p,][indc]
  }
  sur<-rbind(sur,v3)
  
  for(i in 1:cutoff){
    indp1<-sample(1:13,replace=FALSE,size=6)
    v1<-sur[i,]
    v1[indp1]<-sur[i,][indp1]+sample(1:5,size=6,replace=TRUE)
    sur<-rbind(sur,v1)
  }
  ### this is adding perturbation to the parameters, notice there are many other ways we can do it.
  return(sur)
  
}

Try the alineR package in your browser

Any scripts or data that you put into this service are public.

alineR documentation built on May 2, 2019, 11:26 a.m.