# MATLAB: Best fitness vs mean fitness, initial range

1. Based on the example of Rastrigin's function. At the plot function, if I chose 'best fitness', on the same graph 'mean fitness' will also be plotted. I understand well about 'best fitness' whereby it plots the best function value in each generation versus iteration number. It will reach value zero after some times.

I don't understand about 'mean fitness'in the graph plotted. What do those 'mean fitness' values mean? How does the 'mean fitness' graph help to understand Rastrigin's function?

2. What are the meaning of the term initial population, initial score and initial range? I wish to have a better understanding of these terms.

3. The default value for initial range is `[0,1]`. Does it mean that `0` is the lower bound (`lb`) and `1` is the upper bound (`ub`)? Do these values interfere with the `lb` and `ub` values I set in the constraints?

4. I try to better understand about `lb` and `ub`. If my `lb` is `0` and `ub` is `5`, does it mean that my final point values will be within 0 and 5?

5. If I know the `lb` and `ub` for my problem is between `0` and `5`, do I just set the initial range as `[0,5]` at all times and may I assume that this is the best option for initial range, and I need not try it with any other values?

• welcome to stack overflow. Could you explain what you are talking about? Could you provide a link to Rastrigin's function? – Simon Bergot Nov 28 '12 at 11:13
• Rastrigin's function is a standard benchmark problem for real-valued optimizers. The rest is either genetic algorithm terminology or specific questions about the MATLAB GA toolbox. – deong Nov 28 '12 at 14:15

Genetic algorithms are population-based optimization methods. So you have a population of candidate solutions at any given time.

Suppose you're trying to solve the one-max problem -- a simple problem where the goal is to maximize the number of 1-bits in a binary string of length L. With L=8, each candidate solution looks like

``````00101101  ==> fitness = 4
``````

To solve this problem with a GA, you need to create a population of such individuals at random. Let N=10 be the population size. Then you might get the following 10 individuals (fitness values in [] after the bit strings).

``````11011001 
00100110 
11010110 
10010110 
01010110 
11101100 
01001001 
11001011 
10111101 
01001010 
``````

This is the "initial population". The GA will then select parents from this population, breed them, possibly mutate the offspring, and produce a new population from the offspring, possibly including the existing parent population as well. This process is then iterated until you decide to stop the algorithm, typically at a maximum number of evaluations of the objective function or after a maximum number of generations.

Best fitness refers to either the fitness of the best individual in your current population or the fitness of the best individual you have found so far during the run. Depending on the type of GA you're using, these may or may not be the same thing. For instance, the best fitness for my example population above is 6. However, if the best offspring I create has a fitness of 5 and I don't allow parents to survive more than one generation, then the best fitness in the next generation could be either 5 or 6, depending on how we interpret "best fitness". I'm not that familiar with MATLAB's GA toolbox to be able to tell you which one it means, but my guess is that it's the overall best fitness the algorithm has encountered during the run at any time.

The average fitness is simply the mean of the fitness values across the entire population. Each generation, the population changes and you get a new average population fitness. Generally, you're most interested in the best fitness, as you only need one solution and you'll obviously choose the best one. Average fitness however is useful in showing you what the algorithm is doing. If the average fitness reaches the best fitness, it likely means that the population contains N copies of the best individual and further search is likely to be wasted effort without a restart or large-scale mutation operation.

So what you generally see is that best fitness tends to get better over time, quickly at first, and then slowing down as the algorithm finds better and better solutions that are harder and harder to improve upon. The average fitness will always be no better than the best fitness, and it is typically quite a bit worse, with the difference between the two usually decreasing over time until the algorithm completely converges (the population is uniform, containing N copies of the same "best" individual).

The [ub,lb] questions I can't really answer. I'm guessing it's the allowed range on your input variables, but you'll need to consult the documentation for the toolbox you're using to know for sure what those parameters mean.

• TQ gentleman for your time to answer me in detail. I appreciate it. – Sa Ta Nov 30 '12 at 4:43