Hello and welcome to this lecture, where we are going to finish the implementation of the genetic algorithm
using the chip library to solve the problem related to the transportation of products.
Last lecture, we registered a lot of components related to the deep library, and now we are able to
run the algorithm.
First, we need to create a new variable population equals to box.
But population C, that's before we registered the population, which will be randomly initialized.
It will be a list and it will be related should the individual class, which is composed of the individual
class that was defined the year, the individuals are represented by Boolean attributes only zeros and
ones, and then are four theme genes which are related to zeros and ones reminding again.
Zero means that we are not going to load the product on the drug and one means that we are going to
load the product on the truck.
There is this parameter and which means the population size, and we will keep the same parameters as
the implementation from scratch.
To compare the results, we can create another parameter crossover probability.
It will be equal to one.
So it means that we will apply across over 100 per cent of the times.
We can also define the number of generations.
It will be equal to 100.
Let's create another variable.
Statistics equals those dots statistics and let's type here.
Key equals lambda that it is a room time zone.
Let's create this variable individual and let's access individual dots fitness dot values.
It means that we are going to access the values of each one of the generations.
In some minutes, we will see the results.
Now we can register a new statistic.
Let's register, for example, if we want to get the max value of the generation we can type marks a
year and then let's axis denote by library we bought before and just type max function.
It will give us the Max number email list.
Then we can type population in full equals less call algorithms.
We bought it from the deep library, as we can see here, and we can also see a list of some evolutionary
algorithms as we are working with genetic algorithms.
We can access this function.
A simple which is related to the genetic algorithm we implement is before.
Now we need to specify some parameters.
The first one is the population, the variable, which defines the ear.
This second one is the toolbox.
Then the cross over a probability, the mutation probability, the number of generations and also the
statistics just see the results.
Now we are ready to run the genetic algorithm and we can see the results.
For example, in the first column, we can see the number of degeneration.
For example, generation zero.
This other column means the population size, which is equal to 20, and the max value, which means
the best solution among these 20 individuals.
And we can see that's.
The results are quite similar to our implementation from scratch.
We can see that the best result is in this generation here 12, 13, 14, 16 and 17, and we can also
get some other statistics.
We can just copy and paste this code.
We can get the minimum value in each one of the generations.
It is related to the worst solution are should be worst in the video.
Let's run this code again.
We can see here that's the best value in generation.
Zero is twenty one thousand and the minimum value equals one.
When this came off, the prices of the products is greater than the available space on the truck.
We can also get.
The average we can type here, Mads, let's start now by dots mean and also if you want to know more
statistical information, we can type ask did they which mean standard deviation?
Let's run this code again, and we can see all of the information regarding each one of the generations.
We can see that the standard deviation in this first generation is six thousand when we run these codes.
We have all this information regarding of each one of the generations.
However, we can get only the best solutions.
Less great than the other variable based solutions equals those dots.
Cell best.
Just select the best one.
And we'll just put the population variable here and you can define the K value, which means the number
of best solutions you want to get.
For example, the top three best solutions, then we can go through these variable for individual ian
based solutions.
Let's sprints the individual and also lets brands defeat the miss value so we can access.
This trip would fit the mishear here.
Let's run these codes.
We can see that the results are the same.
We can't, for example, try to get the top band results.
Again, we have this same results, and it happens because this problem is quite simple.
If you have more data, you bands to get only one based in this video.
Let's change here to get only the best in the video.
We can see the value when it 1000s in our implementation from scratch.
We got a higher value here.
It is this same as discussed before.
You need to run this code a couple of times to get the best result.
See, that's now the best.
One is only nice.
Then let's try to run this code again.
The best result is twenty two thousand.
Just see the products we can implement.
Another far loop for I in range land in the video.
Let's go through each one of the genes of the chromosome.
If individual position I equals one.
Then we can brand the name of the product.
Let's access the names list and also the price of the product prices position.
I run this code.
And finally, we have here the results.
Considering the best solution we obtained with Deep Library, we would loads on the truck refrigerator,
a B cell phone, all the TV's load bulk ventilator and so on.
And the last implementation, we can't see this variable that was defined the year in full.
As the name suggests, we have information about the results we can Skype in full.
Run this code, we can see the number of the generation, the max, minimum values, standard deviation
and so on.
We can select only the Max are the best value less like Max.
Here we can see the results considering each one of the generations.
So now we can generate a graph or plot line.
Thoughts X-Press Aspects.
Let's create your B x dot line in the x axis.
Let's type range from zero to 100 and when it will go from zero to 100 and in the y axis info dot select
Max.
And the title of the graph genetic algorithm results, let's show the figure.
Run this code and we have here the results considering each one of the generations, for example, you
generation zero only 16 hundreds, we can see the best values in generations 15 and seven, then twenty
three thousand.
And you can see all the results here to see how the algorithm is performing in each one of the generations.
And that's it for this lecture that we implement its genetic algorithms using the app library.
See you next time.