1
00:00:00,620 --> 00:00:07,610
Hello and welcome to this lecture, where we are going to finish the implementation of the genetic algorithm

2
00:00:07,970 --> 00:00:15,500
using the chip library to solve the problem related to the transportation of products.

3
00:00:15,890 --> 00:00:25,430
Last lecture, we registered a lot of components related to the deep library, and now we are able to

4
00:00:25,430 --> 00:00:26,720
run the algorithm.

5
00:00:27,110 --> 00:00:34,880
First, we need to create a new variable population equals to box.

6
00:00:35,410 --> 00:00:46,430
But population C, that's before we registered the population, which will be randomly initialized.

7
00:00:46,760 --> 00:00:56,990
It will be a list and it will be related should the individual class, which is composed of the individual

8
00:00:56,990 --> 00:01:07,400
class that was defined the year, the individuals are represented by Boolean attributes only zeros and

9
00:01:07,400 --> 00:01:17,510
ones, and then are four theme genes which are related to zeros and ones reminding again.

10
00:01:17,810 --> 00:01:25,490
Zero means that we are not going to load the product on the drug and one means that we are going to

11
00:01:25,490 --> 00:01:27,670
load the product on the truck.

12
00:01:28,550 --> 00:01:37,310
There is this parameter and which means the population size, and we will keep the same parameters as

13
00:01:37,310 --> 00:01:39,500
the implementation from scratch.

14
00:01:39,810 --> 00:01:48,650
To compare the results, we can create another parameter crossover probability.

15
00:01:49,580 --> 00:01:51,530
It will be equal to one.

16
00:01:51,830 --> 00:01:59,540
So it means that we will apply across over 100 per cent of the times.

17
00:01:59,960 --> 00:02:04,160
We can also define the number of generations.

18
00:02:04,460 --> 00:02:07,400
It will be equal to 100.

19
00:02:07,850 --> 00:02:10,250
Let's create another variable.

20
00:02:10,790 --> 00:02:19,520
Statistics equals those dots statistics and let's type here.

21
00:02:19,880 --> 00:02:24,830
Key equals lambda that it is a room time zone.

22
00:02:25,460 --> 00:02:37,760
Let's create this variable individual and let's access individual dots fitness dot values.

23
00:02:38,060 --> 00:02:45,230
It means that we are going to access the values of each one of the generations.

24
00:02:45,560 --> 00:02:48,140
In some minutes, we will see the results.

25
00:02:48,590 --> 00:02:52,130
Now we can register a new statistic.

26
00:02:52,730 --> 00:03:03,950
Let's register, for example, if we want to get the max value of the generation we can type marks a

27
00:03:03,950 --> 00:03:14,030
year and then let's axis denote by library we bought before and just type max function.

28
00:03:14,270 --> 00:03:18,350
It will give us the Max number email list.

29
00:03:19,190 --> 00:03:27,890
Then we can type population in full equals less call algorithms.

30
00:03:28,640 --> 00:03:38,900
We bought it from the deep library, as we can see here, and we can also see a list of some evolutionary

31
00:03:38,900 --> 00:03:44,180
algorithms as we are working with genetic algorithms.

32
00:03:44,450 --> 00:03:47,240
We can access this function.

33
00:03:48,110 --> 00:03:55,170
A simple which is related to the genetic algorithm we implement is before.

34
00:03:55,670 --> 00:03:58,220
Now we need to specify some parameters.

35
00:03:58,670 --> 00:04:05,510
The first one is the population, the variable, which defines the ear.

36
00:04:05,960 --> 00:04:09,410
This second one is the toolbox.

37
00:04:10,250 --> 00:04:22,700
Then the cross over a probability, the mutation probability, the number of generations and also the

38
00:04:22,790 --> 00:04:25,970
statistics just see the results.

39
00:04:26,150 --> 00:04:32,150
Now we are ready to run the genetic algorithm and we can see the results.

40
00:04:32,570 --> 00:04:38,960
For example, in the first column, we can see the number of degeneration.

41
00:04:39,230 --> 00:04:41,870
For example, generation zero.

42
00:04:42,200 --> 00:04:52,580
This other column means the population size, which is equal to 20, and the max value, which means

43
00:04:52,580 --> 00:04:57,800
the best solution among these 20 individuals.

44
00:04:58,070 --> 00:04:59,410
And we can see that's.

45
00:04:59,540 --> 00:05:04,970
The results are quite similar to our implementation from scratch.

46
00:05:05,360 --> 00:05:16,880
We can see that the best result is in this generation here 12, 13, 14, 16 and 17, and we can also

47
00:05:16,880 --> 00:05:19,430
get some other statistics.

48
00:05:19,730 --> 00:05:23,360
We can just copy and paste this code.

49
00:05:23,750 --> 00:05:29,930
We can get the minimum value in each one of the generations.

50
00:05:30,290 --> 00:05:36,380
It is related to the worst solution are should be worst in the video.

51
00:05:36,740 --> 00:05:38,930
Let's run this code again.

52
00:05:39,260 --> 00:05:44,390
We can see here that's the best value in generation.

53
00:05:44,420 --> 00:05:50,420
Zero is twenty one thousand and the minimum value equals one.

54
00:05:50,840 --> 00:05:59,330
When this came off, the prices of the products is greater than the available space on the truck.

55
00:05:59,870 --> 00:06:01,610
We can also get.

56
00:06:02,630 --> 00:06:13,490
The average we can type here, Mads, let's start now by dots mean and also if you want to know more

57
00:06:13,490 --> 00:06:21,260
statistical information, we can type ask did they which mean standard deviation?

58
00:06:21,680 --> 00:06:29,660
Let's run this code again, and we can see all of the information regarding each one of the generations.

59
00:06:30,050 --> 00:06:39,260
We can see that the standard deviation in this first generation is six thousand when we run these codes.

60
00:06:39,500 --> 00:06:44,660
We have all this information regarding of each one of the generations.

61
00:06:44,780 --> 00:06:48,650
However, we can get only the best solutions.

62
00:06:48,980 --> 00:06:56,570
Less great than the other variable based solutions equals those dots.

63
00:06:57,320 --> 00:06:59,030
Cell best.

64
00:06:59,210 --> 00:07:01,370
Just select the best one.

65
00:07:01,850 --> 00:07:13,040
And we'll just put the population variable here and you can define the K value, which means the number

66
00:07:13,040 --> 00:07:16,080
of best solutions you want to get.

67
00:07:16,310 --> 00:07:26,060
For example, the top three best solutions, then we can go through these variable for individual ian

68
00:07:26,480 --> 00:07:29,090
based solutions.

69
00:07:29,450 --> 00:07:40,160
Let's sprints the individual and also lets brands defeat the miss value so we can access.

70
00:07:40,160 --> 00:07:42,800
This trip would fit the mishear here.

71
00:07:43,280 --> 00:07:45,500
Let's run these codes.

72
00:07:45,770 --> 00:07:49,160
We can see that the results are the same.

73
00:07:49,640 --> 00:07:54,830
We can't, for example, try to get the top band results.

74
00:07:55,220 --> 00:08:02,810
Again, we have this same results, and it happens because this problem is quite simple.

75
00:08:02,990 --> 00:08:08,960
If you have more data, you bands to get only one based in this video.

76
00:08:09,350 --> 00:08:14,450
Let's change here to get only the best in the video.

77
00:08:14,840 --> 00:08:22,220
We can see the value when it 1000s in our implementation from scratch.

78
00:08:22,280 --> 00:08:24,830
We got a higher value here.

79
00:08:25,070 --> 00:08:28,250
It is this same as discussed before.

80
00:08:28,700 --> 00:08:35,000
You need to run this code a couple of times to get the best result.

81
00:08:35,330 --> 00:08:36,800
See, that's now the best.

82
00:08:36,800 --> 00:08:38,450
One is only nice.

83
00:08:38,450 --> 00:08:41,990
Then let's try to run this code again.

84
00:08:42,620 --> 00:08:46,580
The best result is twenty two thousand.

85
00:08:46,670 --> 00:08:50,810
Just see the products we can implement.

86
00:08:50,810 --> 00:08:57,770
Another far loop for I in range land in the video.

87
00:08:57,950 --> 00:09:03,260
Let's go through each one of the genes of the chromosome.

88
00:09:03,830 --> 00:09:09,110
If individual position I equals one.

89
00:09:09,560 --> 00:09:13,880
Then we can brand the name of the product.

90
00:09:14,270 --> 00:09:24,610
Let's access the names list and also the price of the product prices position.

91
00:09:24,620 --> 00:09:26,840
I run this code.

92
00:09:27,050 --> 00:09:30,110
And finally, we have here the results.

93
00:09:30,620 --> 00:09:39,490
Considering the best solution we obtained with Deep Library, we would loads on the truck refrigerator,

94
00:09:39,500 --> 00:09:45,860
a B cell phone, all the TV's load bulk ventilator and so on.

95
00:09:46,250 --> 00:09:54,020
And the last implementation, we can't see this variable that was defined the year in full.

96
00:09:54,260 --> 00:10:01,440
As the name suggests, we have information about the results we can Skype in full.

97
00:10:01,940 --> 00:10:11,090
Run this code, we can see the number of the generation, the max, minimum values, standard deviation

98
00:10:11,090 --> 00:10:11,930
and so on.

99
00:10:12,260 --> 00:10:18,830
We can select only the Max are the best value less like Max.

100
00:10:18,860 --> 00:10:24,770
Here we can see the results considering each one of the generations.

101
00:10:25,100 --> 00:10:30,200
So now we can generate a graph or plot line.

102
00:10:30,860 --> 00:10:35,220
Thoughts X-Press Aspects.

103
00:10:36,300 --> 00:10:43,760
Let's create your B x dot line in the x axis.

104
00:10:44,450 --> 00:10:59,570
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

105
00:11:00,290 --> 00:11:01,040
Max.

106
00:11:01,910 --> 00:11:11,260
And the title of the graph genetic algorithm results, let's show the figure.

107
00:11:12,410 --> 00:11:21,620
Run this code and we have here the results considering each one of the generations, for example, you

108
00:11:21,620 --> 00:11:33,500
generation zero only 16 hundreds, we can see the best values in generations 15 and seven, then twenty

109
00:11:33,500 --> 00:11:34,590
three thousand.

110
00:11:34,640 --> 00:11:43,820
And you can see all the results here to see how the algorithm is performing in each one of the generations.

111
00:11:44,060 --> 00:11:51,050
And that's it for this lecture that we implement its genetic algorithms using the app library.

112
00:11:51,260 --> 00:11:52,400
See you next time.
