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. 👍
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
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
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.
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.
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.
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!
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?
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!
Thank you for this channel, I have a strong problem concerning optimization by genetic algorithm, can you help me? Because no one that I know can solve this problem. Rgrds.
I know this might be nitpicky, but technically any fitness function that has a power in it could be called polynomial and it might make more sense. The 2^N function would be exponential, although exponentials can be represented as polynomial functions (a pretty example is of course www.wolframalpha.com/input/?i=e%5Ex+expansion) these are only approximations that take infinitely many polynomials to converge. I'm new to these kind of algorithms so take that lightly. Also a question: is it possible that a higher order (polynomial, exponential) functions negatively effect the genetic algorithm's speed? My guess is that there is a point that the function jumps too quickly and the variation of mutations becomes a limiting factor.
Not nitpicky at all, important and helpful clarification! (If you have a minute to see how it is described in natureofcode.com chapter 10 and file any corrections here github.com/shiffman/The-Nature-of-Code/issues I'd love that!)
i have problem in generating my fitness function using both PSNR and NCC parameter. The aim is to find the most optimize or best solution for my image watermarking scaling factor (using genetic algorithm) Hopefully, you guys can help me. Thank you
The matingPool Algorithm is good but when I am selecting the top 2 fittest and mating them population.length times that is giving me results better than the Shakespeare Example of yours
If the top two dont have some sequence of characters by chance then its better to include other low scoring members than letting mutation fix it right?
A higher degree polynomial is closer to an exponential fn than a linear fn in this case. The goal is to have a function that increases more steeply as we go to the right...
As you increase the power, you are effectively just increasing the chances of choosing the elements with the higher fitness. In the end you rapidly approach what is effectively choosing only the best element of the population to populate the next generation. This can lead to problems in the populations variation; if say one element has a large part of the solution while another has a smaller different part of the solution, it would result in the 2nd element being discarded. This means you can quickly be reduced to an algorithm which takes the best element of a generation and simply tries to improve on that single element through only mutations in its DNA i.e. in the video's example it would take the best phrase then swaps some letters randomly in the next generation. While not as slow as simple random guessing it can lead to many more generations required till the solution is found when compared to the standard genetic algorithm.
I don't know how I didn't found you earlier, I'm going to watching every single video in your playlists
I love you man, you are the best teacher i've known.
Thanks for the nice feedback!
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. 👍
So grateful to be looking into Genetic Algorithms now and have your videos available as a reference. Amazing instruction as always! Thank you!
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
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
So glad to hear, thanks!
Thank you. Genetic Algorithm understood for my next project.
Good to see this demo. I read about it in some algorithms book 😂
So fun to watch! great video thanks!
Really interesting. But can you also explain the drawbacks of exponentially increasing the fitness function ?
Aman Ag Your mating pool array will take up more memory.
I'd guess there would be a higher chance of getting stuck at a local maximum.
gifted teacher
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.
these videos are very helpful, thank you
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.
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.
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!
You're so entertaining, I watch on 1.25x speed
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?
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!
Another problem that I just realized is that the fitness is decreasing instead of increasing =/
Hi Dan. Can you do series on Reinforcement Learning too? Thanks.
0:44 The first phrase of the list XD
Maybe you could use a genetic algorithm to help choose the fitness function ;-)
Thank you for this channel,
I have a strong problem concerning optimization by genetic algorithm, can you help me? Because no one that I know can solve this problem.
Rgrds.
You are the best. Is there anything related to Honeybee mating optimization?
machine learning use about softmax, Can use it to Fitness function?
I know this might be nitpicky, but technically any fitness function that has a power in it could be called polynomial and it might make more sense. The 2^N function would be exponential, although exponentials can be represented as polynomial functions (a pretty example is of course www.wolframalpha.com/input/?i=e%5Ex+expansion) these are only approximations that take infinitely many polynomials to converge. I'm new to these kind of algorithms so take that lightly. Also a question: is it possible that a higher order (polynomial, exponential) functions negatively effect the genetic algorithm's speed? My guess is that there is a point that the function jumps too quickly and the variation of mutations becomes a limiting factor.
Not nitpicky at all, important and helpful clarification! (If you have a minute to see how it is described in natureofcode.com chapter 10 and file any corrections here github.com/shiffman/The-Nature-of-Code/issues I'd love that!)
i have problem in generating my fitness function using both PSNR and NCC parameter. The aim is to find the most optimize or best solution for my image watermarking scaling factor (using genetic algorithm)
Hopefully, you guys can help me. Thank you
The matingPool Algorithm is good but when I am selecting the top 2 fittest and mating them population.length times that is giving me results better than the Shakespeare Example of yours
If the top two dont have some sequence of characters by chance then its better to include other low scoring members than letting mutation fix it right?
Why does the average fitness go down when we use an exponential fitness function?
it's just a higher degree polynomial fitness function, not an exponential one
A higher degree polynomial is closer to an exponential fn than a linear fn in this case. The goal is to have a function that increases more steeply as we go to the right...
Sir,according to you is macbook air 2016 good for developing games mostly in unity,unreal engine4 & cryengine
not really.... you will need a decent gpu for that stuff
genetic algorithm for hardware software partitioning??
forecasting with GA is it possible ?
could you provide the source code for this example .. I couldn't find it in your repo. I am interested in understanding how the code works
What is the reason for why you don't just pick the two best children from the previous generation to be the parents of the new generation?
Could one use this technique to solve RSA?
What? How should that work?!
Why don't you just take the fitness to a power of lets say 20?
Are there some consequences?
As you increase the power, you are effectively just increasing the chances of choosing the elements with the higher fitness. In the end you rapidly approach what is effectively choosing only the best element of the population to populate the next generation. This can lead to problems in the populations variation; if say one element has a large part of the solution while another has a smaller different part of the solution, it would result in the 2nd element being discarded. This means you can quickly be reduced to an algorithm which takes the best element of a generation and simply tries to improve on that single element through only mutations in its DNA i.e. in the video's example it would take the best phrase then swaps some letters randomly in the next generation. While not as slow as simple random guessing it can lead to many more generations required till the solution is found when compared to the standard genetic algorithm.
+Joshua Spaul such a great explanation thank you!!!
how ur typing speed is so good??
.
plz give some tips.
.
I am saying this after watching snake video game
( may u not reply it so 1st comment)
6th grade typing class!
pretty much faster then my algoritme, i used 11 hour for "hello world, and the rest of the universe"
but was a pretty simple algoritme.
i fucking hate this. why the fuck did i pick this module holy shit i made a mistake
somewhat annoying that hes constantly on speed
What will it cost you to say Thank you. Ingratitude.