Mutations and fitness functions

To kick things off, we added a mutation for loop in the crossover function.

 

We shall get back to line 114 later, but that line is related to the restructuring of the chromosome so as to store the fitness value within the first index of the chromosome. So basically in line 114, we are skipping over the fitness value when carrying out mutations. ‘mutRate’ is a small value, around 0.001-0.03. And since the crossover deals with two chromosomes at a time, we can mutate both chromosomes at once. Here, Go really starts to shine through as a language for fast prototyping as long as no serious problems are encountered.

 

 

Now the fitness function:

We will use the fitness proportionate selection, also known as roulette wheel selection for a probabilistic approach to genetic selection of two individuals for mating. The idea here is to allow the individuals with the highest  fitness to be selected more often for mating and thus distribute the good attributes of these individuals to more individuals in the subsequent generations.

This function basically states that a ‘p’ individual’s relative fitness is equal to its ‘f’ fitness divided by the total summated fitness of every individual in the whole population.

This in Go code looks something like this (well partially like this)

As can be seen, the initial fitness function is a maximisation function that does a basic addition of all elements of a chromosome and stores the result as the initial fitness in the first element of the individuals chromosome (line 33).

The argument for adding the fitness value into the chromosome and particularly in the first element of the chromosome is purely one of convenience. In future we will be shipping individuals between populations due to the HFC Model (or Island model) employed. This method allows the individual to carry all of its attributes to the new population and avoids us having to develop a central database to keep track of each individuals fitness values. This saves time and allows for high scalability. The advantage gained from using the first element in the chromosome allows for chromosomes with variable length if that ever becomes a requirement in future.

We have a variable ‘popFitSum’ that holds the summated fitness of the whole population.  And as can be seen on a line 47, the comment states that Go doesn’t like jumping around between ints and floats, this actually broke the application several times but I couldn’t pin point the problem as it disappeared after an eclipse restart. Additionally I can’t get a float out of the operation on line 47, this is proving to be abit of a headache. I may have to change the whole application to use slices of floats instead of ints if no other solution can be found.

 

Comments   

0 #2 Jon Kerridge 2014-01-28 13:18
cast the elements of a division to float32 before dividing and then the result will be a float32 - hopefully.

You know what you are going to do just get on with it!

At this stage I would suggest parallelise first and then test with lots of different functions but we may change our mind.

The method of parallelisation is not fixed, functions or data being transferred and that in itself could be a good experiment before trying with different scenarios.
Quote
0 #1 Jon Kerridge 2014-01-26 21:44
OK so this is real progress well done but you are still struggling with GO not surprising do not forget to go to stack overflow for help!

please could you organise your blog so that the last post is on top at the moment I have to click through all the previous ones, which seems counter intuitive
Quote

Add comment


Security code
Refresh