wildart / Evolutionary.jl

Evolutionary & genetic algorithms for Julia
Other
324 stars 59 forks source link

Plotting interim results #5

Closed datawookie closed 9 years ago

datawookie commented 9 years ago

Hi Art,

I've spent another few hours playing with Evolutionary and I'm completely sold. This is really great! I love the fact that so much can be achieved through such a deceptively simple interface!

I have previously worked quite a lot with R's GA package. One of the features that I really enjoyed there was the fact that you can plot the convergence of the optimal and average fitness of the population. Something like this: http://imgur.com/v8Krt1Z. Would it be possible to implement something similar with Evolutionary? I realise that this would require you to store interim results for each generation, but I think that in terms of understanding the performance of the GA and being able to compare different crossover/mutation algorithms this would be very valuable.

Best regards, Andrew.

wildart commented 9 years ago

Good idea, I added new boolean parameter iterim to enable an algorithm state collection.

x = ga(fitness, 7, interim=true);

The result will have a dictionary of all collected variables.

datawookie commented 9 years ago

Thank you, that's brilliant. :-)

A question though: am I missing something or is the content of the :curGenFitness and :bestFitness fields the same?

Also, do you think it might make more sense to present these data in consistent units? At present the :curGenFitness/:bestFitness fields and the :fitness field are given in reciprocal units. The former have been passed through objfun(). My feeling is that it would make more sense to have these all in units which are consistent with the second return parameter, bestFitness.

Again, your responsiveness with this is really appreciated.

I am currently writing a series of articles about Julia as I gradually get my head around the language (http://www.exegetic.biz/blog/tag/monthofjulia/). I am in the process of putting together a post about Evolutionary for Day 33 of the series.

wildart commented 9 years ago

Yes, :curGenFitness is a duplicate of :bestFitness. The difference in the values that fitness of the population is computed as an inverse of the objective function that is reported as best fitness.

datawookie commented 9 years ago

Hi Art,

I back on my Evolutionary project and I've been looking at those history data. I am not sure that it's working quite right. Or perhaps I am misunderstanding the way that it's working.

I'm running the model as follows:

best, invbestfit, generations, tolerance, history = ga(
    x -> 1 / objective(x),                  # Function to MINIMISE
    9,                                      # Length of chromosome
    initPopulation = collect(randbool(9)),
    selection = roulette,                   # Options: sus
    mutation = inversion,                   # Options:
    crossover = singlepoint,                # Options:
    mutationRate = 0.2,
    crossoverRate = 0.5,
    ɛ = 0.1,                                # Elitism
    debug = false,
    verbose = false,
    iterations = 200,
    populationSize = 50,
    interim = true);

The history result is then a dictionary with two fields. The :bestFitness field has the best fitness achieved in each iteration. This appears to be working perfectly.

The :fitness field is an array of 200 elements (one for each iteration). Each of these elements is in turn an array with 50 elements (one for each member of the population). My expectation was that each of the 200 arrays should differ as the population evolves, but strangely they seem to be all precisely the same. I first uncovered this when I made an average of each iteration... these were all the same. I then went and checked the first (1) and last (200) elements in the array and found that they contained the same 50 element vector.

I have had a look at the code and I cannot immediately spot what the problem might be, but I am pretty sure that the :fitness field is not actually capturing the fitness for each iteration.

Thanks!

Best regards, Andrew.

wildart commented 9 years ago

My bad, I should have done state copy at every iteration. Checkout master, it works as supposed to be - population fitness values for each iteration.

datawookie commented 9 years ago

Immaculate. :-) Thank you!