 So just like we were dealing with simulated annealing. We can also use something known as a genetic algorithm and the entire ideas again We're thinking about this as something known as a biologically inspired Algorithm or AI, you know the the important part it algorithm rhythm Is that it's biologically inspired if we take the idea of evolution for a moment, right? Evolution is this concept where it's survival of the fittest whoever has the best genes gets to live on Into the next sort of generation and create children and then those whoever's a survival of the fittest of those Gets to move on and so they may we may be able to find our configuration remember again the configuration is our goal figuration as Our main goal and bypassing those local maximas So what we're looking at here is again trying to find some potential State that we're working off of and we'll start to dig a little deeper into these but just to kind of get everyone Excited about them. There is a link that I'll be posted in the Description below, but I always like to sort of recommend taking a look at this one Just to pull it up for a second and the entire idea is Well, we happen to have a car that is just Well, it got stuck and died and so someone else is coming along it not as big but it didn't make it notice The big point here was we're now in generation. Oh, we're still in the same generation We're in generation two and what happened in generation one whoever got the farthest was the survivor They got to move on and create the next generation and you can start to see as these are going on They all start to mirror that first one ever so slightly big old wheels Sort of a bigger body, but sort of clunky at the same time and Again, you are welcome to have this running for like an hour and you'll see, you know You'll get some really nice results this one Almost made it anyways back to our Learning how to do this part so the way you could think about this right is if we're dealing with sort of that same kind of concept We could look at that car design as having some different Chromosomes right or genes going on there Those wheels for example, we might be wanting to say oh well We're gonna control the wheels and you know the the wheels are now a variable that we're working off of There's also some distances between the center and the edge pieces So that's something we might want to control and there may be some distances between the corner pieces again Just sort of working off of this little toy example here And if we were to assign a value to each one of these again What we could generate out is something called a population big old fancy five dollar word there but it's just here we take all of the possible candidates that we're working off of and We just assign them their values when we're looking at any individual in that population we start to sort of refer to the configuration of that person as a chromosome and Then we're looking at say the individual elements or numerical values. We start to refer to them as genes again. We're just sort of Finding similarities and using terms that are similar from evolution Into our sort of biologically inspired meta heuristic algorithm. Yeah So again, we take these we can assign them some type of F score some type of fitness Now if we're working off of the game, you know, the fitness value was how far The cars were able to travel or something like that I'm arbitrarily just giving them some numbers so that they have numbers attached to them So we can decide who's better and who's worse. And so again, if you're starting to look at that, all right Well, I had my five cars a1 a2 a3 a4 a5 They all got generated onto that track and here's how far each one was able to make it Well, again, now we look at the idea of evolution saying survival of the fittest who was the best and what we can do is we Can say well those top performers they get to make the next generation they get to make the can't they the offspring For the next generation's population, but that's only one approach, right? That's only focusing on top performers You may not want top performers or you may want just one of the top performers, right? Maybe instead. I'm saying 20 here, but it could have been 23 again what we're just looking at is a top a top performer and Some random person again, that's just your how you select your necks who your parents are effectively and so Here's the talk you see when one car and another car love each other very much they may Have a crossover point and what that is is essentially when we're dealing with the idea of well now that I have a top former and someone I have two Potential candidates of generating the next path the next population How do I make their offspring? So with the crossover point that's effectively deciding Where which genes come from which parent and so if I thought about something as just having a crossover point of Two as my example, right working off of a three and a four as my my parents Two of the genes the first two genes come from a three. You can see that again. Here's two Here's four those came from a three But again since that's the crossover point now Everything else is coming from a four and so we do see some slight changes now again You can see a four had a seven in its first gene. Maybe again We can treat that like it's one of the wheel sizes. Well again you look like your father if My cars had whatever My point here is again, maybe now that big wheel that a four had well a three didn't have it so a trunk and You can see that that's just how we can generate all of our possible offsprings in this case Instead of it being a crossover point of two just working off of a crossover point of five How you generate out this number Random you can generate it as a random approach You could have crossover points of all of them My point being is you know again We're just trying to generate out the next population Which means that it's perfectly fine that we have twins It's actually perfectly fine that some of the cars do not survive their invalid configurations for whatever reason whatever your problem happens to be working off of again We only care about sort of survival of the fittest But there's one last little piece that we need to deal with and that's the idea of something known as the mutation Now again, this was a crossover point where we're dealing with a crossover of a four this time, but at position 7 so at this index, I think this is 012345 at index 7 or at position 7 or index 6 whatever You make a coin flip effectively you do that same Big ol fancy word You randomly decide whether or not the gene mutates in some way or if the chromosome Mutates in some way and if it does again, how do you mutate it? Maybe you say that it has to be Something between the two of them so it could be three five or four or in this case I'm just arbitrarily saying oh well, you know what we're just going to make it up some new random number again You're just tweaking things a little bit more so to allow your your Population to potentially break through any local maximas that you're currently operating with One last thing you can do is build out elites So an elite child again is this idea that you know a four Maybe it was the best that we ever got to see and we want to sort of carry that on as The generations occur so in that case, you know one of my children may be a direct copy of Whatever that top performer was again These are just methods to help stabilize or control your your algorithm So you get better results and so with that in mind We have pseudo code that we can take a look at and you'll see that the first little part Part here is again just working off of the idea that this could run forever You know humans don't have an expiration date. Well knock on wood You know we can just technically run forever My point being is this search this this giant loop of Constantly optimizing our configuration can just run forever or If you happen to have some best Individual you you hit some threshold, you know Our car reaches the end of the window of the map or something is fit enough So you hit some kind of threshold that this is a good enough Configuration we move on from there in a prior video. I talked about how NASA had built use genetic algorithms to Build satellites and well again. It had hit a point where it was fit enough to be in space It's a pretty fit enough Individual Either way my point being is at that point you jump into your new population, right? You start with a completely empty set. It is completely just or list, you know set list Collection whatever, you know data term you want to refer to as just empty collection of Individuals we haven't built any yet. So again, how many do we build? You pick I picked five for you know my slides because that would make it easier for me to Convey everything But you could make 20,000 or two or 20 again that all sort of just depends on your little sake and then this is something I was talking about how do I select my parents x and y maybe x is the top performer maybe My why is just some random person again. This is just how you decide How to figure them out. So again, it just sort of works that way Then the next thing is again this idea of a child is created again How do you make that decision? Well again? This is where you randomly select random crossover crossover point or you establish it again, this is just Sort of walking through the the grand state of how a genetic algorithm sort of operates. So again, you create that child Then you look at some mutation rates. So again this idea that maybe I have a mutation rate of point Not 50 it will say a point zero five so a five percent chance of being random That should be the other way around so I'm just gonna do this rather than re-record this video There we go. So if random is less than our mutation rate congratulations. We mutate the child again and then finally You did let me move it then you move that child into your new population Once you've done all of this then that becomes your new population again That's you walking through the entire algorithm You should know who your top performer is and you can keep on going with it Just to kind of see this in a little action again You could take the genetic algorithm and you could apply it to the linear assignment problem that we talked about in our prior video One of the things you could also do is you can play around with this This is now just sort of spitballing what you can do with this approach. Maybe there's some kind of Extra synergy that's going on there. So, you know, again red is really good when they work with green And you know, we're allowed to have more than one person being in a particular task So suddenly the fitness gets a bonus or orange and purple don't work together So if they're working together, you have some detriments again That's just an approach that you could work off of same kind of concept can go on there You could say well, what happens if M is less than in so you have again now you're only dealing with sort of four genes In your configurations instead of five and so hopefully, you know, you you've taken this and you can go Oh, I get now how genetic algorithms work