1
00:00:00,330 --> 00:00:07,740
Hello and welcome to this lecture, where you are going to learn how to initialize the population for

2
00:00:07,740 --> 00:00:09,480
the genetic algorithm.

3
00:00:10,170 --> 00:00:14,490
Population is a set of several individuals.

4
00:00:14,850 --> 00:00:25,440
For example, here we can see individual one in the video out show an individual tree and each one has

5
00:00:25,470 --> 00:00:27,300
its own solution.

6
00:00:27,570 --> 00:00:37,650
A set of zeros and ones and the ones means that we are going to load those products on the truck.

7
00:00:38,160 --> 00:00:48,270
So instead of creating just one or two individuals, as we did before, we need to define the number

8
00:00:48,270 --> 00:00:52,560
of individuals that our population will have.

9
00:00:52,830 --> 00:00:58,380
For example, 50 individuals are 100 individuals.

10
00:00:58,680 --> 00:01:07,830
You need to perform some tests in order to see the best sets of individuals that you need to create

11
00:01:08,270 --> 00:01:19,080
will finally implement the first part of the graph, as you can see here, which is great initial population.

12
00:01:19,380 --> 00:01:29,210
So far, we implemented functions related to the individuals, such as the fitness function, the crossover

13
00:01:29,370 --> 00:01:30,730
and mutation.

14
00:01:31,050 --> 00:01:40,200
Now that those functions are ready, we can create the initial population or post off several individuals.

15
00:01:40,710 --> 00:01:46,260
Now let's move back to our Google collab file, which we started the implementation.

16
00:01:46,470 --> 00:01:54,630
And so far we have created the product glass and also there in the video glass.

17
00:01:54,910 --> 00:02:01,320
Now we will create a new glass to represent the genetic algorithm.

18
00:02:01,770 --> 00:02:09,480
Let's open a new set of codes and we'll create the new glass genetic algorithm.

19
00:02:09,570 --> 00:02:19,170
And let's define the init function, which means the constructor of the glass every time you create

20
00:02:19,170 --> 00:02:21,270
an object of this glass.

21
00:02:21,570 --> 00:02:23,910
This function will be executed.

22
00:02:23,920 --> 00:02:33,390
It's let's first specified the default parameter self and we'll specify another parameter, which is

23
00:02:33,390 --> 00:02:35,910
the size of the population.

24
00:02:36,120 --> 00:02:39,120
Now let's create the attributes.

25
00:02:39,510 --> 00:02:51,290
The first one population size equals should the parameter population size the next one, we will create

26
00:02:51,960 --> 00:02:53,280
population.

27
00:02:53,520 --> 00:02:57,300
It will be at the beginning and empty list.

28
00:02:57,660 --> 00:03:09,120
And here we are, going to start each one of the individual objects in each position of this list,

29
00:03:09,480 --> 00:03:12,960
there will be an individual objects.

30
00:03:13,800 --> 00:03:19,530
Another parameter self generation equals zero.

31
00:03:19,790 --> 00:03:23,610
We will start the algorithm with this value.

32
00:03:23,790 --> 00:03:33,120
It's similar to the generation attribute, which defines a year for each in the individual class.

33
00:03:33,390 --> 00:03:44,940
Another parameter, self thought based solution at the beginning, it will be equal to no one in these

34
00:03:44,940 --> 00:03:45,850
attributes.

35
00:03:45,960 --> 00:03:51,390
We will start the best solution considering all generations.

36
00:03:51,600 --> 00:04:02,280
We will see more details later on and also how we will define another attribute list of solutions at

37
00:04:02,280 --> 00:04:03,100
the beginning.

38
00:04:03,120 --> 00:04:05,460
It will be an empty list.

39
00:04:05,790 --> 00:04:09,390
We will use both attributes later on.

40
00:04:09,660 --> 00:04:18,750
Now, let's define a differential to initialize the population, initialize population self.

41
00:04:19,200 --> 00:04:29,590
This standard parameter and it will receive this basis, the prices and also this base limit.

42
00:04:29,940 --> 00:04:36,690
This same parameters we discussed before should generate annual population is quite easy.

43
00:04:37,020 --> 00:04:39,990
We just need to implement a for loop.

44
00:04:40,590 --> 00:04:47,460
For I in range self thoughts, population size.

45
00:04:47,670 --> 00:04:55,380
We run this far loop according to this parameter that we are going to use sands to the class.

46
00:04:55,830 --> 00:04:59,910
Now let's access our population.

47
00:05:00,740 --> 00:05:02,310
Lots of bands.

48
00:05:02,330 --> 00:05:12,140
It means we will have bands, objects should this list here and now we can create the individual objects

49
00:05:12,470 --> 00:05:19,750
and I will send spaces, prices and space limits.

50
00:05:20,180 --> 00:05:29,240
Just to recap, we are creating objects of this glass here and we are going to sans these parameters.

51
00:05:29,660 --> 00:05:30,860
Take a look here.

52
00:05:30,890 --> 00:05:35,200
That's when we run this in its metals.

53
00:05:35,480 --> 00:05:46,790
We are initialize each one of these attributes, and we are also running this code here to initialize

54
00:05:46,790 --> 00:05:50,390
the chromosome with at random solution.

55
00:05:50,630 --> 00:05:59,090
And after initially using the population, we can access the attributes best solution.

56
00:05:59,450 --> 00:06:05,150
It will be equal to cell population in position zero.

57
00:06:05,510 --> 00:06:13,640
We are going to see more details about IDs in the next lecture, and we need to specify which is the

58
00:06:13,640 --> 00:06:22,910
best in the video that was generated and we are sitting at position number zero off the list.

59
00:06:23,180 --> 00:06:30,950
Of course, this is just to initialize this attribute and we will see more details later.

60
00:06:31,070 --> 00:06:33,380
Let's create this class.

61
00:06:33,650 --> 00:06:35,960
Now we can go back here.

62
00:06:36,260 --> 00:06:39,260
I will open a new cell of code.

63
00:06:39,530 --> 00:06:47,270
I will create a new variable population size, for example, 20 individuals.

64
00:06:47,600 --> 00:06:59,000
Let's create the genetic algorithm quali the glass genetic algorithm, and I will set here the population

65
00:06:59,000 --> 00:07:02,150
size variable we defined here.

66
00:07:02,390 --> 00:07:08,870
It means that we will initialize the algorithm using 20 in these blocks.

67
00:07:09,290 --> 00:07:20,020
Now we can call our function genetic algorithm initialize population, and let's send here this basis

68
00:07:20,750 --> 00:07:23,150
if prices and limits.

69
00:07:23,600 --> 00:07:25,310
Let's run this code.

70
00:07:25,820 --> 00:07:29,540
Now we can access our genetic algorithm.

71
00:07:29,870 --> 00:07:35,000
The population tributes run this code.

72
00:07:35,270 --> 00:07:42,560
See that in each one of the positions, we can find an individual object.

73
00:07:43,010 --> 00:07:47,180
Let's check this size length population.

74
00:07:47,360 --> 00:07:49,730
It is equal to 20.

75
00:07:49,940 --> 00:07:52,730
This same number we defined here.

76
00:07:53,000 --> 00:08:01,220
So it means that there are 20 random individuals in our genetic algorithm object.

77
00:08:01,520 --> 00:08:07,100
We can take a look at some of them population position zero.

78
00:08:07,310 --> 00:08:13,310
This is the first objects are a solution in the genetic algorithm.

79
00:08:13,640 --> 00:08:22,430
Let's take a look at the chromosome run this quote we can see a random solution.

80
00:08:23,090 --> 00:08:26,960
We can also open a new cell of code.

81
00:08:27,320 --> 00:08:30,740
Let's take a look at the sequence in the video.

82
00:08:31,300 --> 00:08:34,370
Here we can see the solution and so on.

83
00:08:34,580 --> 00:08:43,670
And now the implementation of the first step of the genetic algorithm is ready, and in the next lecture,

84
00:08:43,880 --> 00:08:47,360
we are going to evaluate the population.

85
00:08:47,780 --> 00:08:48,440
See you there.
