1
00:00:00,880 --> 00:00:08,050
Hello and welcome to this lecture, where you were going to learn the intuition and we will implement

2
00:00:08,080 --> 00:00:18,070
another genetic operator, which is mutation, remembering that we are in this part of the image and

3
00:00:18,070 --> 00:00:27,130
after we are going to put all the codes together to build the complete genetic algorithm, mutation

4
00:00:27,430 --> 00:00:33,970
creates diversity by randomly changing the genes of the chromosome.

5
00:00:34,510 --> 00:00:40,900
Here we have the representation of a chromosome or a solution to the problem.

6
00:00:41,410 --> 00:00:48,400
And remember, that's each one and zero is called gene in crossover.

7
00:00:48,580 --> 00:00:57,790
We create a new individual while in mutation, we just randomly change one of the genes.

8
00:00:58,150 --> 00:01:06,610
For example, we can select this gene here and change the value from one to zero.

9
00:01:06,940 --> 00:01:15,700
Or we can select this or other gene here and change the value from zero to one.

10
00:01:16,300 --> 00:01:24,370
These are genetic operator is supplied less often just at its happens in nature.

11
00:01:24,640 --> 00:01:30,040
So crossover is much more frequent than mutation.

12
00:01:30,580 --> 00:01:37,360
We change the genes based on that probability that is usually very small.

13
00:01:37,630 --> 00:01:42,580
For example, one person's two persons are three percent.

14
00:01:43,270 --> 00:01:53,530
Now let's go back to our Google collab file and implement this new genetic operator after a cross over.

15
00:01:54,340 --> 00:02:04,480
We will define a new functional BAFF mutation, and it will receive as a parameter did the full parameter,

16
00:02:04,480 --> 00:02:05,800
which is self.

17
00:02:06,190 --> 00:02:16,780
And also, we will send the here the probability rates, which will indicate the probability of performing

18
00:02:16,810 --> 00:02:17,800
mutation.

19
00:02:18,490 --> 00:02:26,590
How will we implement a far loop for I in range length self?

20
00:02:27,010 --> 00:02:30,460
Let's ex is here the chromosome.

21
00:02:30,790 --> 00:02:35,440
It means that we will go through each one of the genes.

22
00:02:36,010 --> 00:02:46,420
Now we will generate a random number if random, less than the rate than we will.

23
00:02:46,420 --> 00:02:49,150
What BLI mutation, for example.

24
00:02:49,330 --> 00:02:54,310
Let's suppose that's the mutation rate is one person's.

25
00:02:54,670 --> 00:03:05,430
The value would be zero point zero one and then we will generate a random number when we run this code

26
00:03:05,440 --> 00:03:05,950
here.

27
00:03:06,190 --> 00:03:10,740
We will get that number in the range from zero to one.

28
00:03:11,170 --> 00:03:22,150
We can run these codes a couple of times and we will see that the probability of selecting and no less

29
00:03:22,150 --> 00:03:26,380
than zero point zero one is very low.

30
00:03:26,650 --> 00:03:35,560
We can still run in this codes and see that we always get numbers over this value here.

31
00:03:35,860 --> 00:03:39,730
So the probability of mutation is very low.

32
00:03:40,180 --> 00:03:50,320
Now we can implement and if state demands, if self Dot's chromosome, which means these are to report

33
00:03:50,320 --> 00:03:53,560
the year which presents this solution.

34
00:03:54,070 --> 00:04:06,040
If the value of the chromosome or the gene imposition IE equals one, then we need to change this value

35
00:04:06,040 --> 00:04:06,850
to zero.

36
00:04:07,210 --> 00:04:14,190
So self chromosome position ie equals zero.

37
00:04:14,470 --> 00:04:19,210
If the value is one, we change it to zero.

38
00:04:19,580 --> 00:04:26,260
Otherwise, if the value is zero, then we wax as again.

39
00:04:26,260 --> 00:04:33,760
The chromosome in position, i.e. we are accessing the gene equals one.

40
00:04:34,030 --> 00:04:39,310
So if the value is one, the result will be zero.

41
00:04:39,520 --> 00:04:45,910
And if the value of the gene is zero, the result will be one.

42
00:04:46,300 --> 00:04:58,030
Now we can return sales, which means that we will return the object itself because we are changing

43
00:04:58,030 --> 00:05:00,050
all the values here.

44
00:05:00,400 --> 00:05:06,340
You see the results, we can implement a brilliant statement here.

45
00:05:06,700 --> 00:05:15,640
For example, before and let's start here, Self Thoughts chromosome.

46
00:05:15,970 --> 00:05:22,870
And after changing the genes after the for loop, let's wait here after.

47
00:05:23,200 --> 00:05:31,660
And again, self chromosome, let's recreate the individual glass.

48
00:05:31,930 --> 00:05:35,350
And now we will perform some tests.

49
00:05:35,590 --> 00:05:39,460
We are defining the first individual.

50
00:05:40,270 --> 00:05:42,580
This one's in the video.

51
00:05:42,880 --> 00:05:46,090
Here we are, generating the children.

52
00:05:46,610 --> 00:05:52,030
We run this codes again and we can access individual one.

53
00:05:52,570 --> 00:05:58,510
Let's call the object, and now we'll call the mutation.

54
00:05:58,810 --> 00:06:04,540
Let's suppose the probability of mutation is five percent.

55
00:06:04,870 --> 00:06:09,160
So we can type here zero point zero five.

56
00:06:09,550 --> 00:06:11,290
Let's run this codes.

57
00:06:11,680 --> 00:06:17,470
We can see here before mutation and after mutation.

58
00:06:17,890 --> 00:06:20,620
All values are the same.

59
00:06:20,920 --> 00:06:32,560
So it means that when we ran the Randel codes, the values were not lower than zero point zero five.

60
00:06:32,800 --> 00:06:34,840
We can try to run again.

61
00:06:35,350 --> 00:06:41,020
See here that there is one change before this gene.

62
00:06:41,020 --> 00:06:42,850
Here was one.

63
00:06:43,120 --> 00:06:52,270
And after mutation, they value was converted to zero and all other genes keep the same.

64
00:06:52,660 --> 00:06:57,680
We can try to run similar times in this equation.

65
00:06:57,700 --> 00:07:04,180
We can see that's before the value of this gene was zero.

66
00:07:04,420 --> 00:07:09,220
And after applying mutation, this value now is one.

67
00:07:09,730 --> 00:07:15,580
If you want to see more changes, we can put here zero point five.

68
00:07:15,910 --> 00:07:21,220
It means that the probability of mutation is 50 percent.

69
00:07:21,490 --> 00:07:23,920
We can see more changes here.

70
00:07:24,250 --> 00:07:26,170
Zero and one.

71
00:07:26,470 --> 00:07:27,960
One and zero.

72
00:07:27,970 --> 00:07:35,080
And so one, as I told you before, we usually keep a small number here.

73
00:07:35,350 --> 00:07:40,570
IRA commands that you use from one to five percent.

74
00:07:40,900 --> 00:07:48,190
We can try to run again and see the results, and in the next lecture, we are going to continue the

75
00:07:48,190 --> 00:07:49,120
implementation.

76
00:07:49,570 --> 00:07:50,290
See you there.
