Hello and welcome to this lecture, where you were going to learn the intuition and we will implement
another genetic operator, which is mutation, remembering that we are in this part of the image and
after we are going to put all the codes together to build the complete genetic algorithm, mutation
creates diversity by randomly changing the genes of the chromosome.
Here we have the representation of a chromosome or a solution to the problem.
And remember, that's each one and zero is called gene in crossover.
We create a new individual while in mutation, we just randomly change one of the genes.
For example, we can select this gene here and change the value from one to zero.
Or we can select this or other gene here and change the value from zero to one.
These are genetic operator is supplied less often just at its happens in nature.
So crossover is much more frequent than mutation.
We change the genes based on that probability that is usually very small.
For example, one person's two persons are three percent.
Now let's go back to our Google collab file and implement this new genetic operator after a cross over.
We will define a new functional BAFF mutation, and it will receive as a parameter did the full parameter,
which is self.
And also, we will send the here the probability rates, which will indicate the probability of performing
mutation.
How will we implement a far loop for I in range length self?
Let's ex is here the chromosome.
It means that we will go through each one of the genes.
Now we will generate a random number if random, less than the rate than we will.
What BLI mutation, for example.
Let's suppose that's the mutation rate is one person's.
The value would be zero point zero one and then we will generate a random number when we run this code
here.
We will get that number in the range from zero to one.
We can run these codes a couple of times and we will see that the probability of selecting and no less
than zero point zero one is very low.
We can still run in this codes and see that we always get numbers over this value here.
So the probability of mutation is very low.
Now we can implement and if state demands, if self Dot's chromosome, which means these are to report
the year which presents this solution.
If the value of the chromosome or the gene imposition IE equals one, then we need to change this value
to zero.
So self chromosome position ie equals zero.
If the value is one, we change it to zero.
Otherwise, if the value is zero, then we wax as again.
The chromosome in position, i.e. we are accessing the gene equals one.
So if the value is one, the result will be zero.
And if the value of the gene is zero, the result will be one.
Now we can return sales, which means that we will return the object itself because we are changing
all the values here.
You see the results, we can implement a brilliant statement here.
For example, before and let's start here, Self Thoughts chromosome.
And after changing the genes after the for loop, let's wait here after.
And again, self chromosome, let's recreate the individual glass.
And now we will perform some tests.
We are defining the first individual.
This one's in the video.
Here we are, generating the children.
We run this codes again and we can access individual one.
Let's call the object, and now we'll call the mutation.
Let's suppose the probability of mutation is five percent.
So we can type here zero point zero five.
Let's run this codes.
We can see here before mutation and after mutation.
All values are the same.
So it means that when we ran the Randel codes, the values were not lower than zero point zero five.
We can try to run again.
See here that there is one change before this gene.
Here was one.
And after mutation, they value was converted to zero and all other genes keep the same.
We can try to run similar times in this equation.
We can see that's before the value of this gene was zero.
And after applying mutation, this value now is one.
If you want to see more changes, we can put here zero point five.
It means that the probability of mutation is 50 percent.
We can see more changes here.
Zero and one.
One and zero.
And so one, as I told you before, we usually keep a small number here.
IRA commands that you use from one to five percent.
We can try to run again and see the results, and in the next lecture, we are going to continue the
implementation.
See you there.