Colin
Colin

Reputation: 303

R - genalg package: Get Fittest From Past Generation

I am doing some optimization with the genalg package in R. Is there any way to get the fittest chromosome from past generations? I am looking for other "close enough" solutions, but it seems to me that all information in the rbga object is from the current (final) generation.

For example, can I get the 100 chromosomes returning the lowest evaluation value in generations 400 - 500?

Example

Edit: I suppose I could just run the function

rbga.bin(size=10, popSize=200, iters= , mutationChance=0.01)

for iterations = (400, 401, 402, ..., 498, 499, 500), and pull the best after each additional generation, but that will be extremely slow.

Upvotes: 0

Views: 705

Answers (1)

Christoffer
Christoffer

Reputation: 661

The generations you have iterated over are not saved by the rbga.bin() function, so you can't get the best chromosomes in iteration 400-500 after the algorithms has finished.

However, if you add a monitor function to your rbga.bin() call, you can get the information you want. So, include this monitor function to your script:

monitor <- function(obj) {
  if (obj$iter >= 400) {
    print(paste("GENERATION:", obj$iter))
    print(obj$population[which.min(obj$evaluations), ])
  }
}

and add monitorFunc = monitor in the rbga.bin() like this:

rbga.bin(size=10, popSize=200, iters=500, mutationChance=0.01, monitorFunc = monitor)

If you like, you can save the output instead of just printing it.

Upvotes: 2

Related Questions