9.6: Genetic Algorithm: Improved Fitness Function - The Nature of Code

preview_player
Показать описание


Timestamps:
0:00 Hello and welcome back!
0:50 Let's talk about the fitness function.
2:44 Exponential fitness!
3:17 Code! Let's try squared fitness.
4:21 Code! More power!!
4:38 Ideas! Could you improve the smart rockets example?

Рекомендации по теме
Комментарии
Автор

I don't know how I didn't found you earlier, I'm going to watching every single video in your playlists

bryangarcia
Автор

I love you man, you are the best teacher i've known.

tumvoodoo
Автор

So grateful to be looking into Genetic Algorithms now and have your videos available as a reference. Amazing instruction as always! Thank you!

tyfoodsforthought
Автор

I'm kind of proud of myself for thinking of that after watching a few of the previous videos and writing my own algorithm.
I think your videos are amazing! Keep up the good work. 👍

strigido-yt
Автор

While having a bit of a play around I found a fairly efficient fitness function where instead of just using the number of matches, keep track of the number of matching characters in a row and add that instead of 1, resetting to 0 if a mismatch is found. Managed to get my code down to ~85 generations rather than 300-600

Dezzles
Автор

Thank you so much for these video's they're helping me understand so much more about coding and how things work. also love that you tell us to try and do something with the example given it's a really really good exercise

SaintPepsiSanCoca
Автор

Thank you. Genetic Algorithm understood for my next project.

albertdadzie
Автор

these videos are very helpful, thank you

spinLOL
Автор

Good to see this demo. I read about it in some algorithms book 😂

ramkumarr
Автор

I found that if the crossover is based on the weight of the fitness it can perform faster. If for example you want the crossover between .7 and .8 fitness you have a ~.46 chance from the the first and .53 from the second (.7/(.7+.8)). In the loop you can generate a random(1) and check if it is less then this.fitness/sum, then set child genes to this.genes at i.

eppermarshall
Автор

Really interesting. But can you also explain the drawbacks of exponentially increasing the fitness function ?

Dhsoanw
Автор

Simply making the fitness function exponential runs into the same problem as the linear one, except of course at the start of the process rather than at the end. However, it should be noted that this is not at all as big an issue. I'd recommend doing something like this.fitness = pow(this.fitness, 1 + x*averageFitness), where averageFitness is the average of the fitness values of the previous generation, and x is a factor you can change to increase or decrease the effect of the average fitness (I used x=1 in my code). This has the effect of being (almost) linear when the average fitness is low, which is what we want, and growing more and more exponential as the average fitness increases. In essence, this allows you to more finely select breeding pairs once the playing field has been leveled and everyone is roughly equally fit. We are increasing the pressure of selection.

An analogy would be breeding frogs to jump high. At the start we simply select high jumping frogs. However, because of physical limits frogs can only jump so high. After a while almost all frogs will be jumping at almost the same height, and we're essentially picking at random, not making much improvement. Taking the average fitness into account, however, is like using a magnifying glass, turning very small differences in jump height into larger ones, allowing us to better select frogs to breed.

As a final note one might ask why this "averaging out" happens, and why convergence is slow towards the end. In essence, it's because as you get closer to the optimum fewer and fewer mutations are beneficial. This allows the slower of the pack to catch up, making all individuals very close in fitness. This can be seen with this program, where you sometimes get situations were almost everyone is identical, having to randomly mutate only a few letters to get a perfect match.

hannesthorsell
Автор

I am having some trouble with this code. I made one that works in the same way of yours, but in python; and when I add an exponencial function in Fitness it becomes slow, cause of the size of the list that store all that data. How can I solve it? It seens that as I am storing toons of arrays it is filling my memory.
By the way, that is an awesome serie, I am waching all your videos!

pedroferreira
Автор

The problem I'm facing is, regardless of how I square or multiply scores, every set of genes always ends up with a similar score like all the other ones and thing's aren't improving nearly as fast as I want them to. They also aren't really improving in the way I want them to.
Granted, my problem is much more complicated because I don't already know the answer (cuz what would the point be otherwise?) and my application is somewhat of a physics simulation.

DasAntiNaziBroetchen
Автор

Hello!
I ran into a problem that I think you didn't mention in the video. When you take score of an individual and divide it by the length of the target phrase, you always get a numer between zero and one, right? And when you take that value squared, or taken to the fourth power, or whatever, you end up with a smaller number (for example: 0.2^2=0.04). Depending on small that number is across the population, you might end up with no individuals in the mating pool at all, because the fitnesses are so small. And that's what happened to me. Am I missing something? Am I doing something wrong? Thanks!

plinioviniciusalvesdossant
Автор

What is the draw back to using an exponential function as opposed to al linear function? Given the efficiency you demonstrated here, why would anyone use a linear function to reward fitness?

branhoff
Автор

genetic algorithm for hardware software partitioning??

dhaouadibadreddine
Автор

machine learning use about softmax, Can use it to Fitness function?

dysh-tyc-edu-tw
Автор

Hi Dan. Can you do series on Reinforcement Learning too? Thanks.

mctrjalloh
Автор

forecasting with GA is it possible ?

panjersonten