Path: blob/main/Lessons/Lesson 07 - Global Optimization 2/Self_Assess_Soln_07.ipynb
871 views
Self-Assessment: Using Maximization with GA
To maximize, we need to negate the fitness function, because our genetic algorithm only minimizes. Negating the fitness function is simple. You simply add a negative sign before the return variable. Let's set up the same population used in the lesson and get the maximized fitness.
Because our fitness function is so simple, and because we know that we're always using numpy arrays, we could also just pass numpy's sum function directly to our helper function like this, to get the minimization fitnesses.
But, if you try to put a negative sign in front of np.sum, you'll get an error. Numpy, though, has it's own negation function. We could call it like this to turn np.sum into a maximization function.
Self-Assessment: Exploring Tournament Selection
What happens for smaller tournament sizes? You should notice that there is more diversity in the selected population and more high value fitness values get selected. There are fewer repeats in the selected population.
For larger tournament sizes? There is less diversity in the selected population and mostly low value fitness values get selected. There are more repeats in the selected population.
For tournament size 1? This yields the most diverse population with fewest repeats.
For tournament size the same as the population size? The selected population contains only the individual with the lowest fitness value. This means crossover will have no effect since all the individuals are the same. Only the mutation operator will have an effect.
How does tournament size affect the exploration versus exploitation tradeoff?. Small tournament sizes encourage more exploration and less exploitation while larger tournament sizes have the opposite effect.
Self-Assessment: Crossover probability
What happens if
cx_prob = 0
? No mating occurs so there is no sharing of information between individuals. This would result in a population of parallel random local searches.What happens if
cx_prob=1
? Every pair of individuals mates, this means that there is no chance that a very good solution survives more than one generation unless it happens to mate with a copy of itself.
Self-Assessment: Mutation Parameters:
What is the effect of
mut_prob = 1
? Every individual is mutated.What is the effect of
mut_prob = 0
? No individuals are mutated so the genetic algorithm uses only mating to improve the population.What is the effect of increasing
ind_prob
? Larger values mean more changes in the individual.What would happen if you made
sigma
really large? The mutations could result in very large steps which could make the search behave erratically. Mutated individuals might have very little in common with their parents. Large exploration and small exploitation.What would happen if you made
sigma
really small? The steps would be very small so the search remains very local. Small exploration and large exploitation.