1
00:00:00,270 --> 00:00:08,430
Hello and welcome to this lecture, where we are going to implement and fast they cross over functional,

2
00:00:08,640 --> 00:00:11,190
according to the theoretical lecturer.

3
00:00:11,310 --> 00:00:17,640
And in order to implement crossover, we need two individuals.

4
00:00:17,970 --> 00:00:24,480
And in this part of the codes, we define only individual number one.

5
00:00:24,840 --> 00:00:32,720
So I will copy all these codes, open a new cell based here.

6
00:00:33,090 --> 00:00:38,100
Or we'll just put this first sprints in comments.

7
00:00:39,270 --> 00:00:44,490
Puts a higher tune and less great individual.

8
00:00:44,670 --> 00:00:45,830
No, true.

9
00:00:46,070 --> 00:00:49,080
We will sans the same parameters.

10
00:00:49,380 --> 00:00:53,730
And here we will just change individual.

11
00:00:53,790 --> 00:00:54,220
Sure.

12
00:00:54,900 --> 00:00:59,100
Let's supply the fitness function to individual.

13
00:01:00,000 --> 00:01:01,380
Let's change here.

14
00:01:01,890 --> 00:01:05,520
Individual chore and individual virtue.

15
00:01:05,880 --> 00:01:12,480
Let's run these schools and we have a new individual are Neal solution.

16
00:01:12,840 --> 00:01:21,480
For example, this car is twenty two thousand and this base two point forty one.

17
00:01:21,750 --> 00:01:31,500
And regarding that other solution said that this car was only one since this space occupied by this

18
00:01:31,500 --> 00:01:37,650
products are over the limit so we can run it again.

19
00:01:38,100 --> 00:01:42,670
And Etienne's we can just implements and larger prints.

20
00:01:43,170 --> 00:01:45,270
Choose C D chromosome.

21
00:01:45,870 --> 00:01:48,420
Let's Typekit here in this video.

22
00:01:48,450 --> 00:01:51,000
Once that chromosome.

23
00:01:51,510 --> 00:01:56,400
Copy and paste it here in the video.

24
00:01:56,430 --> 00:01:56,910
Sure.

25
00:01:57,240 --> 00:01:59,640
Let's run this code again.

26
00:02:00,000 --> 00:02:03,630
We have these solution and the chromosome.

27
00:02:04,020 --> 00:02:06,120
Let's run here again.

28
00:02:06,570 --> 00:02:08,070
Another solution.

29
00:02:08,910 --> 00:02:13,440
Twelve thousand and only 10000.

30
00:02:13,620 --> 00:02:17,700
So this second solution is better than the first one.

31
00:02:17,940 --> 00:02:26,010
Now we need to combine these chromosome with these all other chromosome here.

32
00:02:26,220 --> 00:02:32,170
To do that, we can move back to our individual class.

33
00:02:33,330 --> 00:02:44,430
Let's create a new function death cross over self, which is the standard parameter, and we need to

34
00:02:44,430 --> 00:02:55,500
sand's the order in the video because we are going to combine these chromosome here with the chromosome

35
00:02:55,500 --> 00:03:01,470
of these other individual that we are going to stand as a parameter.

36
00:03:01,920 --> 00:03:12,270
The first step is to define the cutoff point, according to these is like the here, we need to randomly

37
00:03:12,270 --> 00:03:14,910
select one of these points.

38
00:03:15,480 --> 00:03:18,630
We can type again random.

39
00:03:18,930 --> 00:03:25,200
It will generate a number in the range from zero to one.

40
00:03:25,680 --> 00:03:31,530
And now we'll multiply by the length of the chromosome.

41
00:03:31,950 --> 00:03:43,320
For example, if our chromosome has four theme positions, it will generate random number from zero

42
00:03:43,320 --> 00:03:44,340
to 14.

43
00:03:44,760 --> 00:03:55,890
If our chromosome has 20 positions or 20 products, when we multiply both values, we're we'll select

44
00:03:55,890 --> 00:04:01,620
a number from zero to 20 just to perform at best.

45
00:04:01,800 --> 00:04:09,570
We can copy and paste this code here, but we don't have the information about the chromosome.

46
00:04:10,140 --> 00:04:13,140
Let's multiply by 14.

47
00:04:13,920 --> 00:04:14,790
See here.

48
00:04:14,790 --> 00:04:17,970
That's every time we run this code.

49
00:04:18,270 --> 00:04:20,580
We have a different number.

50
00:04:20,850 --> 00:04:27,480
So we will use this number to select one of these cutoff points.

51
00:04:28,170 --> 00:04:36,450
We can also rounds this value to have an integer number every time we run.

52
00:04:36,660 --> 00:04:42,560
We get an integer number in the range from zero to 13.

53
00:04:42,810 --> 00:04:45,810
And lots from zero to 14.

54
00:04:46,080 --> 00:04:48,300
Because indexes in Python.

55
00:04:48,510 --> 00:04:50,310
It starts at zero.

56
00:04:50,520 --> 00:04:59,070
So if we have 14 positions, we need to select a number between zero and 13.

57
00:04:59,700 --> 00:05:08,670
We can rounds this number here and after dance, we can generate child.

58
00:05:08,700 --> 00:05:17,100
One equals let's axis all other individual dots chromosome.

59
00:05:17,460 --> 00:05:22,500
And now we will select from all z shows zero.

60
00:05:22,940 --> 00:05:25,800
Sure, they cut off points.

61
00:05:25,950 --> 00:05:38,250
In other words, we are selecting only this part here of the first berries one, zero and one, according.

62
00:05:38,810 --> 00:05:42,650
What we have here was zero zero.

63
00:05:42,680 --> 00:05:54,590
Should the cut off was the usual and then we need to combine with self that chromosome from the cut

64
00:05:54,590 --> 00:05:59,030
off point should the and off the list.

65
00:05:59,240 --> 00:06:03,050
Because of that, we use these two symbols.

66
00:06:03,470 --> 00:06:14,930
So in other words, we are selecting from the parents chew from the cut off position until demands of

67
00:06:14,930 --> 00:06:15,650
the list.

68
00:06:15,980 --> 00:06:23,150
So child one is the composition of the first part of parents one.

69
00:06:23,450 --> 00:06:26,780
And the second part of parents chew.

70
00:06:27,170 --> 00:06:30,320
Now we need to create a child's number.

71
00:06:30,390 --> 00:06:30,770
Sure.

72
00:06:31,060 --> 00:06:34,550
Now we will do something very similar.

73
00:06:34,970 --> 00:06:36,290
Child chew.

74
00:06:36,890 --> 00:06:47,180
Let's access the inverse self chromosome from position zero to the cutoff point.

75
00:06:47,750 --> 00:06:54,050
And how will concatenate with the other individual?

76
00:06:54,470 --> 00:07:03,270
Let's access the chromosome from the cut off points until the end of the list.

77
00:07:03,920 --> 00:07:20,030
We can prints they they off points just to perform the first test and also grants child one and child's

78
00:07:20,030 --> 00:07:20,480
chew.

79
00:07:21,620 --> 00:07:25,640
Let's recreate the individual class.

80
00:07:26,060 --> 00:07:29,000
Now we need to run this code again.

81
00:07:29,990 --> 00:07:36,440
We have another in the video see here that the score equals one.

82
00:07:36,770 --> 00:07:38,600
So let's run it again.

83
00:07:39,490 --> 00:07:41,030
11000.

84
00:07:41,480 --> 00:07:43,610
Let's run in the video.

85
00:07:43,640 --> 00:07:44,050
Sure.

86
00:07:44,530 --> 00:07:46,370
17000.

87
00:07:46,880 --> 00:07:57,380
Now we can combine both individuals in the video one dot crossover, and now we will stand as a barometer

88
00:07:57,650 --> 00:07:59,240
in the video, too.

89
00:07:59,660 --> 00:08:01,410
Let's run this code.

90
00:08:01,790 --> 00:08:06,290
See, that's the cutoff point is 11.

91
00:08:06,620 --> 00:08:10,900
For example, we can take a look at the positions.

92
00:08:11,330 --> 00:08:19,160
Zero one two three four five six seven eight nine 11.

93
00:08:19,460 --> 00:08:23,840
So we are selecting these good off points.

94
00:08:24,170 --> 00:08:27,820
We can take a look at the first child's.

95
00:08:28,140 --> 00:08:34,820
See, that's it is the first part of the chromosome.

96
00:08:35,210 --> 00:08:40,760
And instead of have one, zero and one.

97
00:08:41,150 --> 00:08:50,030
Now we have zero one zero because we are selecting the 11 parts.

98
00:08:50,270 --> 00:09:01,700
So we are combining the first part of this chromosome with the last parts of this order chromosome.

99
00:09:02,150 --> 00:09:14,390
And regarding child number two, we can take a look at the initial part see that these values are exactly

100
00:09:14,390 --> 00:09:18,230
the same, but the and's is different.

101
00:09:18,560 --> 00:09:30,650
We are selecting the first parts of individual one and we are combining with the last parts of individual

102
00:09:30,650 --> 00:09:31,130
two.

103
00:09:31,460 --> 00:09:34,100
We can run this code again.

104
00:09:34,550 --> 00:09:42,740
The cutoff point is this section gene should be easier to see the results we can run again.

105
00:09:43,100 --> 00:09:46,700
The cutoff point now is number nine.

106
00:09:47,090 --> 00:09:55,520
We can see zero one two three four five six seven eight nine.

107
00:09:55,970 --> 00:10:01,880
So now we have the first part of the chromosome.

108
00:10:02,120 --> 00:10:11,630
This part here is combined with the last part of the first individual, as we can see here.

109
00:10:11,930 --> 00:10:18,440
If you want to see more results, you can run this code and check the values.

110
00:10:18,920 --> 00:10:27,530
Finally, we need to go back to our function and we'll put this Bryants in comments.

111
00:10:28,530 --> 00:10:31,410
I will create another variable.

112
00:10:31,830 --> 00:10:35,780
Children equals in the form of a list.

113
00:10:36,120 --> 00:10:46,800
We have only the chromosomes here, but we need to generate anew individual because each individual

114
00:10:47,100 --> 00:10:56,810
must to have all these information here so we can now create a new individual object.

115
00:10:57,090 --> 00:11:07,860
And let's sans added parameters, self thought spaces, self thought prices, self thoughts, space

116
00:11:07,980 --> 00:11:16,320
limits and finally, self thought generation plus one.

117
00:11:16,770 --> 00:11:27,030
So we are defining the next generation when we create the new generation, which sets the initial value

118
00:11:27,030 --> 00:11:31,080
to zero when we create a new individual.

119
00:11:31,290 --> 00:11:41,880
We increment the number of generations and now we can define exactly the same for the other individual.

120
00:11:42,450 --> 00:11:47,280
I can just copy and paste the codes.

121
00:11:47,700 --> 00:11:49,800
It will be exactly the same.

122
00:11:50,130 --> 00:11:54,210
And now we need to fill this parameter here.

123
00:11:54,510 --> 00:12:04,650
The chromosome for each one of the individuals as we have a buy on the list here, we can access each

124
00:12:04,650 --> 00:12:06,240
one of the positions.

125
00:12:06,870 --> 00:12:09,450
Children positions zero.

126
00:12:10,080 --> 00:12:17,460
Let's specify the chromosome, which will be equal to child one.

127
00:12:18,090 --> 00:12:22,610
I will access children in position one.

128
00:12:23,130 --> 00:12:25,650
This is position zero.

129
00:12:26,040 --> 00:12:28,740
And this is position one.

130
00:12:29,100 --> 00:12:32,190
Let's access the chromosome.

131
00:12:32,760 --> 00:12:36,420
It will be equal to child and number two.

132
00:12:36,810 --> 00:12:44,970
And finally, we will return the children then list with the new individuals.

133
00:12:45,480 --> 00:12:49,080
Let's recreate that in the video class.

134
00:12:49,950 --> 00:12:53,700
And now we can perform one last test.

135
00:12:54,090 --> 00:13:00,450
I will create a new in the video, see that the value is a sad thing.

136
00:13:00,450 --> 00:13:03,390
The limits are we will run it again.

137
00:13:04,050 --> 00:13:06,130
Let's create in the video.

138
00:13:06,330 --> 00:13:06,900
Number.

139
00:13:07,830 --> 00:13:17,940
We need to run it again because they value exactly the available space in the truck run again.

140
00:13:18,360 --> 00:13:29,340
Now we can combine them, see that it was returns, at least in the video one and in the video to just

141
00:13:29,340 --> 00:13:30,210
shoot fast.

142
00:13:30,450 --> 00:13:34,260
We can create the children variable.

143
00:13:34,710 --> 00:13:41,440
And now we can access each one of the positions, for example, sample position.

144
00:13:41,460 --> 00:13:42,210
Zero.

145
00:13:42,780 --> 00:13:51,570
And in order to get the values, we can access this core evaluation.

146
00:13:52,890 --> 00:14:01,710
See that this variable is not defined since there is a typo here in the definition of the glass.

147
00:14:02,140 --> 00:14:06,000
I will just change here and create again.

148
00:14:06,690 --> 00:14:09,090
Now we can run this code again.

149
00:14:09,690 --> 00:14:13,800
And we also needs to correct the here.

150
00:14:14,130 --> 00:14:19,890
Let's create the glass again when we run these other codes.

151
00:14:20,220 --> 00:14:26,610
There's a typo here because we need to correct his quiet evaluation.

152
00:14:28,140 --> 00:14:29,040
This code?

153
00:14:29,400 --> 00:14:34,500
We also needs to correct a score evaluation.

154
00:14:36,220 --> 00:14:48,340
Let's generate the children now we can see that this quiet equals zero because we first needs to evaluate

155
00:14:48,670 --> 00:14:59,890
so we can access children zero thoughts fitness, let's call this function see that the value is for

156
00:14:59,890 --> 00:15:01,110
the thousands.

157
00:15:01,240 --> 00:15:03,220
We can also take a look.

158
00:15:03,940 --> 00:15:05,260
That's the solution.

159
00:15:05,730 --> 00:15:14,560
Children zero dot chromosome run these codes we can see here the results.

160
00:15:15,040 --> 00:15:16,690
We can just brands.

161
00:15:17,720 --> 00:15:22,640
Both lines should see the violence run again.

162
00:15:23,210 --> 00:15:27,320
Now we can copy and paste this code.

163
00:15:27,470 --> 00:15:34,610
Let's change to children, no virtual and now we can compare the results.

164
00:15:34,940 --> 00:15:40,490
This is one combination and this is another combination.

165
00:15:40,760 --> 00:15:49,540
We will use the cross over function to generate a new population later on in the implementations and

166
00:15:49,550 --> 00:15:56,630
in the next lecture, you are going to implement the new facial, genetic or breakthrough.

167
00:15:57,110 --> 00:15:57,770
See you there!
