1
00:00:00,360 --> 00:00:08,460
Hello and welcome to this lecture, where we are going to work with the deep library to solve the problem

2
00:00:08,460 --> 00:00:11,250
about the transport of products.

3
00:00:11,610 --> 00:00:19,950
The good point is that we will be able to compare the results of the library with the results of our

4
00:00:19,950 --> 00:00:22,200
implementation from scratch.

5
00:00:22,500 --> 00:00:31,020
If you want to know more detail about this library, you can follow this link here to get more information.

6
00:00:31,410 --> 00:00:41,190
We can see a brief description of the library and as we can see here, it includes the following features

7
00:00:41,580 --> 00:00:46,410
genetic algorithms, which is the focus of this class.

8
00:00:46,760 --> 00:00:56,760
However, we can see more features, for example, Evolution Strategies mode, the objective optimization

9
00:00:57,060 --> 00:01:02,190
cooperative and the competitive evolution, and many others.

10
00:01:02,490 --> 00:01:12,180
As we saw in the introduction lecture, the genetic algorithms are just a part of the evolutionary algorithms.

11
00:01:12,480 --> 00:01:22,290
So if you want to know more detail about this topic, I recommend that you go deep into these documentation

12
00:01:22,290 --> 00:01:28,590
here to see and to learn more about all other evolutionary algorithms.

13
00:01:28,920 --> 00:01:33,060
Now let's install the library PIP.

14
00:01:33,990 --> 00:01:37,010
Install the App Room.

15
00:01:37,320 --> 00:01:48,270
This sale of codes we can see here that it is downloading the app version one point three point one.

16
00:01:48,540 --> 00:01:52,350
So we are using this version of the library.

17
00:01:52,710 --> 00:01:58,320
In case you have a different version, you can install these.

18
00:01:58,320 --> 00:02:04,080
A specific one should not have problems with different versions.

19
00:02:04,440 --> 00:02:07,590
You can just type PIP install.

20
00:02:07,980 --> 00:02:17,880
The app equals one point three point one, so the codes we are going to implement will be compatible

21
00:02:17,880 --> 00:02:19,950
with this version here.

22
00:02:20,190 --> 00:02:24,930
Now we need to define the class of products.

23
00:02:25,450 --> 00:02:28,380
We'll just paste this code to here.

24
00:02:28,770 --> 00:02:33,150
This code we implement as before and I will just paste.

25
00:02:33,150 --> 00:02:40,350
It should be more organized than we need to create a list of variables.

26
00:02:40,920 --> 00:02:51,360
I will open a new set of codes and based these other codes we implement, as before, the list of products

27
00:02:51,630 --> 00:02:58,080
we are adding in this list before parting products off our case study.

28
00:02:58,530 --> 00:03:04,500
Then we create this basis prices and names lists.

29
00:03:04,980 --> 00:03:15,060
We have bands the values to each one of then this base limit, population size, mutation probability

30
00:03:15,060 --> 00:03:17,310
and number of generations.

31
00:03:17,730 --> 00:03:22,710
Now we run this so of codes to create these variables.

32
00:03:23,220 --> 00:03:25,860
The next step is to eat birds.

33
00:03:26,220 --> 00:03:31,170
The deep library the first one in part no bite.

34
00:03:31,560 --> 00:03:37,830
This is a scientific library in Python to work with matrices and vectors.

35
00:03:38,070 --> 00:03:39,840
We will use it later.

36
00:03:40,290 --> 00:03:54,020
F-words Random to generate random numbers from deep import base from the imports.

37
00:03:54,420 --> 00:04:04,080
Create third from the import algorithms and finally from the deep library.

38
00:04:04,350 --> 00:04:08,220
Let's import the tools package.

39
00:04:08,430 --> 00:04:13,110
We are going to use them in some means run these codes.

40
00:04:13,440 --> 00:04:20,760
No error was returns, so it means that the installation was made successfully.

41
00:04:20,940 --> 00:04:27,690
Now we need to create the fit in this function, which will be exactly the same.

42
00:04:27,780 --> 00:04:29,580
We implemented before.

43
00:04:29,850 --> 00:04:36,900
So when working with libraries, you must implement the fitness function.

44
00:04:37,410 --> 00:04:42,000
Just a reminder that we have this list here.

45
00:04:42,450 --> 00:04:51,150
Zero means that we are not going to load the product on the truck, and one means that we are going

46
00:04:51,150 --> 00:04:53,700
to load the product in the truck.

47
00:04:54,150 --> 00:04:56,100
We can create this function.

48
00:04:56,520 --> 00:04:58,310
Death Fitness.

49
00:04:58,530 --> 00:04:59,850
It will receive.

50
00:04:59,940 --> 00:05:07,750
As a barometer, a solution or a chromosome, now we can create the cost variable.

51
00:05:08,070 --> 00:05:15,510
We are going to return to this variable, which will be equal to this sum of all prizes.

52
00:05:15,760 --> 00:05:22,470
Lest lecturer, we used a different terminology to represent this variable.

53
00:05:22,800 --> 00:05:32,340
But it's important to know that when you work with genetic algorithms, it is common to see these word

54
00:05:32,460 --> 00:05:36,960
cost, which means the results of the fitness function.

55
00:05:38,100 --> 00:05:42,240
Let's create some space equals zero.

56
00:05:42,600 --> 00:05:51,360
Now we need to go through each one of the zeros and ones off the solution.

57
00:05:51,720 --> 00:05:59,880
For I in range length solution, we are going through each one of the zeros and ones.

58
00:06:00,300 --> 00:06:06,630
Let's check if Solution Position II equals one.

59
00:06:07,200 --> 00:06:18,600
Then let's increment the cost plus equal prices position, i.e. we are accessing this list here.

60
00:06:19,080 --> 00:06:22,410
Then we need to add space.

61
00:06:22,800 --> 00:06:28,890
Some space plus equal spaces position i.

62
00:06:29,310 --> 00:06:33,450
It is this list of spaces here.

63
00:06:33,960 --> 00:06:44,970
Then when these short verify after default, look, if some space greater than the limits, the cost

64
00:06:45,150 --> 00:06:46,920
will be equal to one.

65
00:06:47,370 --> 00:06:50,280
And then let's return the cost.

66
00:06:50,610 --> 00:07:00,510
Something different when implement the genetic algorithms using deep library is that we needs to put

67
00:07:00,510 --> 00:07:04,660
this comma here in the next set of calls.

68
00:07:04,680 --> 00:07:07,960
You will understand why we need it.

69
00:07:08,370 --> 00:07:17,250
Let's create the fitness function and now to create some objects related to the deep library.

70
00:07:17,670 --> 00:07:27,300
The first one, let's create the two blocks variable, which will be equal to Bayes dot two blocks.

71
00:07:27,540 --> 00:07:36,690
We need to create two blocks from the base package to initialize the genetic algorithm.

72
00:07:37,080 --> 00:07:39,690
Then let's go creator.

73
00:07:40,020 --> 00:07:42,690
We imported this package here.

74
00:07:43,230 --> 00:07:49,800
Dots create as we have a maximization problem.

75
00:07:50,130 --> 00:07:52,020
We need supports here.

76
00:07:52,800 --> 00:07:58,920
Fit in this max bayes dots fitness.

77
00:07:59,220 --> 00:08:09,780
It is related to the fitness function and now there is another parameter quote weights equals one and

78
00:08:10,050 --> 00:08:11,220
comma here.

79
00:08:11,520 --> 00:08:19,050
See that we have this comma after the value, according should this part here.

80
00:08:19,290 --> 00:08:25,560
When you work with the app, you can return more than one value.

81
00:08:25,680 --> 00:08:35,190
For example, if you had another variable here that you once to optimize your code returns, show variables

82
00:08:35,190 --> 00:08:35,700
here.

83
00:08:36,000 --> 00:08:42,960
For this reason, we need this goal Mahere in this particular case study.

84
00:08:43,200 --> 00:08:53,250
We are returning only the cost, which is the sum of the total price, and this cost is associated with

85
00:08:53,250 --> 00:08:54,390
this value.

86
00:08:54,750 --> 00:09:00,600
One means that the results will be in the range from zero to one.

87
00:09:00,930 --> 00:09:11,580
Then we need to create the individual creator thoughts create and I will type here the name of the glass.

88
00:09:12,000 --> 00:09:14,820
It is related to the deep library.

89
00:09:15,030 --> 00:09:23,550
In the video, we want to generate a list of individuals and now let's type.

90
00:09:23,970 --> 00:09:39,120
Fitness equals creator again thought fitness max, which means that was to maximize the profit or maximize

91
00:09:39,120 --> 00:09:39,930
the cost.

92
00:09:40,350 --> 00:09:43,050
We can run this sale of codes.

93
00:09:43,440 --> 00:09:47,280
Now we needs to register some other objects.

94
00:09:47,610 --> 00:09:59,630
Let's access our toolbox variable, but register now it needs to specify the type of our soldiers.

95
00:09:59,710 --> 00:10:08,170
Washing or that type of the chromosome, let's type A, B, D, R, which means attributes.

96
00:10:08,770 --> 00:10:09,240
Boom.

97
00:10:09,550 --> 00:10:19,630
We are defining a Boolean attributes, which means this solution r d chromosome is composed only of

98
00:10:19,630 --> 00:10:21,580
zeros and ones.

99
00:10:22,090 --> 00:10:28,390
Then we need to specify how we are going to initialize the chromosome.

100
00:10:28,930 --> 00:10:38,440
We will use the transient function as we implement as before, and this solution is composed only of

101
00:10:38,980 --> 00:10:40,750
zeros and ones.

102
00:10:41,170 --> 00:10:50,620
This part here means that this solution will be generated this way here only zeros and ones.

103
00:10:50,860 --> 00:10:54,040
Let's register another component.

104
00:10:54,370 --> 00:11:01,420
The box, but registered the next one is the individual.

105
00:11:01,810 --> 00:11:05,170
Those thoughts it needs.

106
00:11:05,590 --> 00:11:07,000
Repeat it.

107
00:11:07,000 --> 00:11:11,200
The means that we are going to generate random solutions.

108
00:11:11,650 --> 00:11:15,310
Creator but individual.

109
00:11:15,580 --> 00:11:19,120
It is the name of this glass here.

110
00:11:19,510 --> 00:11:32,980
Then we need to specify the box a our bool and this size and equals 14 because there are 14 products

111
00:11:32,980 --> 00:11:34,750
in our case study.

112
00:11:34,930 --> 00:11:44,140
These two lines of code are registering the individuals which are composed of Boolean attributes.

113
00:11:44,590 --> 00:11:48,790
Now we can register the population.

114
00:11:49,150 --> 00:11:52,270
Let's type here, population.

115
00:11:52,570 --> 00:12:03,160
Those dots init repeats to generate a random population, then type the population will be a list.

116
00:12:03,610 --> 00:12:09,730
And now we need to specify the barometer in the video.

117
00:12:09,940 --> 00:12:16,180
So we are creating a population associated with this glass here.

118
00:12:16,540 --> 00:12:28,630
The next step, the box that register evaluates how we are going to evaluate the population using the

119
00:12:28,630 --> 00:12:40,630
fitness function we defined the year, then we need to specify how we are going to apply the crossover.

120
00:12:41,170 --> 00:12:52,030
It is related should the maid's parameter, and then we can access those C x worm lines.

121
00:12:52,420 --> 00:13:00,250
It is the crossover we implement as before, when we have only one cutoff point.

122
00:13:00,550 --> 00:13:06,820
We can see here more options if you was to go deep into this library.

123
00:13:07,090 --> 00:13:17,010
You can see these c x at the beginning means different types of cross over that you can apply.

124
00:13:17,230 --> 00:13:20,620
Let's register another parameter.

125
00:13:21,160 --> 00:13:23,550
It will be the mutation.

126
00:13:24,100 --> 00:13:28,960
Those dots must flip the bit.

127
00:13:29,080 --> 00:13:33,070
It is the mutation we implemented from scratch.

128
00:13:33,370 --> 00:13:42,160
When the number is zero, it is changing the G1 and when the number is one, it is changes to zero.

129
00:13:42,340 --> 00:13:48,280
And the last parameter AI and beep beep beep beep means probability.

130
00:13:48,730 --> 00:13:58,810
We will specify when persons of probability to execute the mutation and the last parameter, the box

131
00:13:59,500 --> 00:14:07,870
thought register how we are going to select the individuals are the best in the videos.

132
00:14:08,560 --> 00:14:15,840
Those dots sale roulette, which is the one we implement as before.

133
00:14:16,150 --> 00:14:23,580
You can see here more options if you want to go deep into genetic algorithms theory.

134
00:14:23,740 --> 00:14:26,350
Let's select the roulette methods.

135
00:14:26,680 --> 00:14:29,320
Now we can read these codes.

136
00:14:29,680 --> 00:14:39,820
There is one error here just correct this typo run again, and the basic structure of the genetic algorithm

137
00:14:39,820 --> 00:14:46,210
is already implemented, and in the next lecture, we are going to finish the implementation.

138
00:14:46,540 --> 00:14:47,230
See you there!
