1
00:00:10,000 --> 00:00:11,000
Hello, friends.

2
00:00:11,000 --> 00:00:17,000
Today I will tell you how to apply algorithm in life.

3
00:00:17,000 --> 00:00:18,000
You.

4
00:00:19,000 --> 00:00:20,000
For that purpose.

5
00:00:20,000 --> 00:00:35,000
I have a problem that in which our function is ten and 2x1 minus one squared plus 20 x two minus two,

6
00:00:35,000 --> 00:00:40,000
all squared plus 30 and 2x3 minus three all squared.

7
00:00:41,000 --> 00:00:50,000
And the objective function used for minimization, I use this so using particle swarm optimization.

8
00:00:51,000 --> 00:00:52,000
I have to.

9
00:00:53,000 --> 00:00:54,000
Optimize this.

10
00:00:55,000 --> 00:00:56,000
Function.

11
00:00:56,000 --> 00:01:00,000
So in this function we use VSO.

12
00:01:01,000 --> 00:01:04,000
That is a meta heuristic algorithm.

13
00:01:04,000 --> 00:01:06,000
All we know that.

14
00:01:06,000 --> 00:01:11,000
In which population based stochastic search.

15
00:01:11,000 --> 00:01:15,000
We can also call it population based stochastic search.

16
00:01:16,000 --> 00:01:29,000
It is based on birds flocking means in which our you can say how the birds fly in a pattern.

17
00:01:30,000 --> 00:01:37,000
To search out food or to go from one place to another place.

18
00:01:39,000 --> 00:01:41,000
Search for optimum value.

19
00:01:42,000 --> 00:01:44,000
And or here.

20
00:01:45,000 --> 00:01:50,000
And so that is particles from optimization.

21
00:01:50,000 --> 00:01:59,000
Swarm means population of moving particles and flock means moving together in a crowd.

22
00:02:00,000 --> 00:02:01,000
In the.

23
00:02:01,000 --> 00:02:04,000
So we also use search space.

24
00:02:06,000 --> 00:02:13,000
The third space is the range in which the algorithm computes the optimal control variable.

25
00:02:13,000 --> 00:02:14,000
So just.

26
00:02:15,000 --> 00:02:17,000
Go to our function.

27
00:02:17,000 --> 00:02:20,000
So let's say over here.

28
00:02:21,000 --> 00:02:22,000
And to solve this problem.

29
00:02:22,000 --> 00:02:27,000
As you see over here, we have three variables x1x2x3.

30
00:02:27,000 --> 00:02:40,000
So a number of variables M is three population size, let's say 58wx is 0.9 and W mean is 0.4 and acceleration

31
00:02:40,000 --> 00:02:41,000
factor.

32
00:02:41,000 --> 00:02:47,000
I just choose C one and C two is equal to two and the maximum iteration size is 50.

33
00:02:48,000 --> 00:02:48,000
Okay.

34
00:02:48,000 --> 00:02:53,000
So how we can implement this function in lab view?

35
00:02:54,000 --> 00:02:57,000
So for that purpose I just create.

36
00:02:58,000 --> 00:02:59,000
Or here.

37
00:02:59,000 --> 00:03:01,000
This is a code.

38
00:03:02,000 --> 00:03:03,000
For MATLAB.

39
00:03:03,000 --> 00:03:11,000
As you see, the lower bound is 000 and upper boundaries and 1010 means.

40
00:03:11,000 --> 00:03:21,000
Using this loop, we can generate a three course five matrix which contains integer values from 0 to

41
00:03:21,000 --> 00:03:22,000
10.

42
00:03:22,000 --> 00:03:30,000
As you see over here, I got 8919613, five, ten, ten, two, ten, ten, five, eight.

43
00:03:30,000 --> 00:03:35,000
So let's just create a variable.

44
00:03:37,000 --> 00:03:41,000
Add a variable or here, just put this value inside this.

45
00:03:42,000 --> 00:03:45,000
So 891 first value is.

46
00:03:47,000 --> 00:03:48,000
Eight nine.

47
00:03:48,000 --> 00:03:50,000
One second value is.

48
00:03:51,000 --> 00:03:52,000
961.

49
00:03:53,000 --> 00:03:55,000
Then over here.

50
00:03:56,000 --> 00:03:59,000
This is my 961.

51
00:04:00,000 --> 00:04:06,000
Right now I'm just using the values of this PDF only.

52
00:04:07,000 --> 00:04:12,000
After that I also tell you how you can compute another values also.

53
00:04:13,000 --> 00:04:16,000
So right now I'm just using these fixed values.

54
00:04:16,000 --> 00:04:17,000
Fixed values.

55
00:04:17,000 --> 00:04:18,000
Three, five, ten.

56
00:04:19,000 --> 00:04:22,000
Then we have three.

57
00:04:22,000 --> 00:04:23,000
Five.

58
00:04:25,000 --> 00:04:29,000
Then after that, I just use 10 to 10.

59
00:04:32,000 --> 00:04:38,000
10 to 10, and my last row is ten, five, eight.

60
00:04:40,000 --> 00:04:43,000
NW five and eight.

61
00:04:43,000 --> 00:04:47,000
So we can generate this function.

62
00:04:47,000 --> 00:04:49,000
Or you can say this.

63
00:04:49,000 --> 00:05:01,000
Five cores, three metrics using the random number in this function or here, as you see around is used

64
00:05:02,000 --> 00:05:08,000
with RAND command around because Rand command is generate values from 0 to 1.

65
00:05:08,000 --> 00:05:17,000
And over here the limit for this Rand command is from 0 to 10 and using round it will round up my values.

66
00:05:17,000 --> 00:05:23,000
Like if I got 8.153 it will generate only eight.

67
00:05:23,000 --> 00:05:33,000
So over here right now in the lab view, as you see over here, I just create visual positions.

68
00:05:34,000 --> 00:05:37,000
After that I wouldn't want to put.

69
00:05:40,000 --> 00:05:43,000
I want to go to next step over here.

70
00:05:44,000 --> 00:05:45,000
Initialize.

71
00:05:45,000 --> 00:05:46,000
Wait.

72
00:05:47,000 --> 00:05:51,000
So to initialize it, we have to right now.

73
00:05:51,000 --> 00:05:56,000
In this function, we require initial population size.

74
00:05:57,000 --> 00:06:05,000
So initial population is Midas 891 the initial matrix and I want to create initial velocity from it

75
00:06:05,000 --> 00:06:11,000
and we can generate initial velocity using this formula we 2.1 into.

76
00:06:12,000 --> 00:06:17,000
This matrix, you can multiply point two, point three on the basis of your requirement.

77
00:06:18,000 --> 00:06:19,000
Okay.

78
00:06:19,000 --> 00:06:22,000
Right now I'm just using these 2.1.

79
00:06:22,000 --> 00:06:25,000
So I just go to my VA.

80
00:06:26,000 --> 00:06:28,000
In the second step.

81
00:06:31,000 --> 00:06:33,000
I already fixed this.

82
00:06:33,000 --> 00:06:37,000
As you see over here, this is my initial position.

83
00:06:37,000 --> 00:06:39,000
Or you can say initial population.

84
00:06:40,000 --> 00:06:42,000
Then I multiply it with point one.

85
00:06:43,000 --> 00:06:47,000
It will generate my metrics, initial velocity or here.

86
00:06:47,000 --> 00:06:52,000
So when I hit on run button, as you see, I got initial velocity then.

87
00:06:53,000 --> 00:07:00,000
When I got initial velocity, as you see in 2.1 with my initial five into three metrics.

88
00:07:01,000 --> 00:07:04,000
And over here this is my variable x1x2x3.

89
00:07:04,000 --> 00:07:13,000
So I want to generate current position and my current position is x one is called to initial position

90
00:07:13,000 --> 00:07:20,000
with initial velocity like eight plus point eight, it will give me 8.8.

91
00:07:21,000 --> 00:07:29,000
So as you see in the lab view, also I got 8.8 over here, my value is nine nine plus point nine.

92
00:07:29,000 --> 00:07:33,000
I got my current position as you see over here.

93
00:07:34,000 --> 00:07:35,000
Next step.

94
00:07:37,000 --> 00:07:38,000
In the next step.

95
00:07:39,000 --> 00:07:44,000
Over here we have initial population and initial velocity.

96
00:07:45,000 --> 00:07:46,000
Then.

97
00:07:47,000 --> 00:07:48,000
We have to.

98
00:07:52,000 --> 00:08:02,000
Apply our objective function that is used for minimization, that is is to turn into x minus x one all

99
00:08:02,000 --> 00:08:05,000
squared plus 20 2x2 minus.

100
00:08:06,000 --> 00:08:06,000
Two.

101
00:08:06,000 --> 00:08:08,000
All square plus 13.

102
00:08:08,000 --> 00:08:09,000
Two x.

103
00:08:10,000 --> 00:08:11,000
Three minus three.

104
00:08:11,000 --> 00:08:12,000
All square.

105
00:08:12,000 --> 00:08:19,000
So just go to our library function or here, as you see.

106
00:08:19,000 --> 00:08:22,000
Here is my x one variable.

107
00:08:22,000 --> 00:08:23,000
I just separated.

108
00:08:23,000 --> 00:08:26,000
So let's check how we can separate it.

109
00:08:26,000 --> 00:08:29,000
So over here, this is my initial velocity.

110
00:08:29,000 --> 00:08:31,000
And over here, I got my.

111
00:08:32,000 --> 00:08:34,000
Final value that is.

112
00:08:34,000 --> 00:08:35,000
Current position.

113
00:08:35,000 --> 00:08:37,000
This is my current position.

114
00:08:38,000 --> 00:08:44,000
And so using index as a function, I just separate from zeroth column.

115
00:08:44,000 --> 00:08:49,000
I got x one from one column I got x two for.

116
00:08:50,000 --> 00:08:52,000
Second column, I got x three.

117
00:08:52,000 --> 00:08:56,000
So as you see over here, this is my x1x2x3.

118
00:08:56,000 --> 00:09:01,000
So right now I want to put this A, b, c.

119
00:09:02,000 --> 00:09:04,000
And these ABC.

120
00:09:05,000 --> 00:09:06,000
Comes from.

121
00:09:08,000 --> 00:09:09,000
Or here.

122
00:09:09,000 --> 00:09:11,000
So let's put.

123
00:09:13,000 --> 00:09:19,000
This ABC and this ABC are 1020 and 30.

124
00:09:19,000 --> 00:09:21,000
These are these are these constants.

125
00:09:22,000 --> 00:09:33,000
So let's say this is ten, 20 and 30 based on these values, I got the fitness value.

126
00:09:33,000 --> 00:09:39,000
So the fitness value is 91964.9.

127
00:09:39,000 --> 00:09:41,000
Let's check for this function as you see.

128
00:09:41,000 --> 00:09:44,000
1.9649.

129
00:09:45,000 --> 00:09:47,000
It is n.

130
00:09:48,000 --> 00:09:50,000
Multiplication of ten factor.

131
00:09:50,000 --> 00:09:55,000
So over here, if you want to change it 1.9 divided by.

132
00:09:56,000 --> 00:09:57,000
1000 only.

133
00:09:58,000 --> 00:10:00,000
So as you see over here, the values are the same.

134
00:10:01,000 --> 00:10:03,000
Second value is 1.3 to 6.

135
00:10:05,000 --> 00:10:11,000
Or here I got one 3 to 6 basically in the MATLAB.

136
00:10:11,000 --> 00:10:17,000
It is this value scores 1.9649 in two.

137
00:10:18,000 --> 00:10:20,000
Ten plus ten.

138
00:10:22,000 --> 00:10:24,000
E as you see or hear.

139
00:10:25,000 --> 00:10:32,000
1.96 49e +03 E +03 means ten res two three.

140
00:10:32,000 --> 00:10:38,000
So when you multiply this ten days to three with this vector, you got this value that is in.

141
00:10:39,000 --> 00:10:43,000
Okay, so this is how we get this vector.

142
00:10:43,000 --> 00:10:47,000
So from here, this step two is completed.

143
00:10:47,000 --> 00:10:49,000
The objective function or here we have to.

144
00:10:50,000 --> 00:10:55,000
Find out the minimum value, because in this case we have to minimize.

145
00:10:55,000 --> 00:10:58,000
So minimum value is 1.3 to 6.

146
00:10:59,000 --> 00:11:02,000
So second particle we want to work with.

147
00:11:04,000 --> 00:11:11,000
So over here, as you see for each particle, calculate the velocity, new velocity and new position.

148
00:11:11,000 --> 00:11:15,000
So new velocity and new position will be calculated using this formula.

149
00:11:16,000 --> 00:11:18,000
Calculate the velocity v one.

150
00:11:18,000 --> 00:11:29,000
De plus one is equal to w max that is rate vector v i d plus c one that is average.

151
00:11:30,000 --> 00:11:39,000
Correction vector into r1x best minus x plus C to r to g best minus x.

152
00:11:40,000 --> 00:11:41,000
Right.

153
00:11:41,000 --> 00:11:45,000
So from here you have to just apply this formula.

154
00:11:45,000 --> 00:11:47,000
So I just go to my code.

155
00:11:47,000 --> 00:11:52,000
So as you see over here, I got x1x2x3.

156
00:11:52,000 --> 00:12:00,000
Then over here this part will be create or will create our objective function.

157
00:12:00,000 --> 00:12:11,000
As you see over here, this x one minus one, all square is multiplied with ax2 minus two, all square

158
00:12:11,000 --> 00:12:15,000
is multiplied with bx3 minus.

159
00:12:15,000 --> 00:12:18,000
Or you can also change this to constant.

160
00:12:18,000 --> 00:12:19,000
It is up to you.

161
00:12:20,000 --> 00:12:22,000
For this particular function.

162
00:12:22,000 --> 00:12:23,000
These values are fixed.

163
00:12:24,000 --> 00:12:28,000
Then you have to find out the minimum of all these three.

164
00:12:28,000 --> 00:12:31,000
The minimum value will be over here.

165
00:12:31,000 --> 00:12:38,000
As you see, the minimum value is this from here, the minimum value is second one and the indexing

166
00:12:38,000 --> 00:12:40,000
for this is one.

167
00:12:40,000 --> 00:12:47,000
So as you see, index function is V one, because in the live view every iteration starts from zero.

168
00:12:47,000 --> 00:12:58,000
So Siberia's my .99.9, 6.6, 1.1 and subway array for this means velocity is .9.6.1.

169
00:12:58,000 --> 00:13:01,000
In the next phase we have to apply this.

170
00:13:02,000 --> 00:13:03,000
Function.

171
00:13:03,000 --> 00:13:08,000
We have to calculate the velocity and position of the particle.

172
00:13:08,000 --> 00:13:11,000
So to calculate the velocity, I just apply this.

173
00:13:11,000 --> 00:13:22,000
So in this case I just go to phase five or here I want to put the value point nine because maximum value

174
00:13:22,000 --> 00:13:24,000
is as you see or here.

175
00:13:27,000 --> 00:13:32,000
This is one nine and C one and Z two is two.

176
00:13:32,000 --> 00:13:33,000
So just.

177
00:13:34,000 --> 00:13:37,000
Put these values inside this function.

178
00:13:37,000 --> 00:13:38,000
See to.

179
00:13:41,000 --> 00:13:44,000
So when I hit on Run button again, I got.

180
00:13:45,000 --> 00:13:48,000
x1x2x3 OC.

181
00:13:49,000 --> 00:13:52,000
So I just increase the size.

182
00:13:58,000 --> 00:14:07,000
So over here, these values are different from these values because in this case we use random number.

183
00:14:07,000 --> 00:14:12,000
Random number will generate any value from 0 to 1.

184
00:14:12,000 --> 00:14:18,000
And in this case, also in the lab view, random number will generate different values.

185
00:14:19,000 --> 00:14:20,000
So.

186
00:14:21,000 --> 00:14:22,000
From here.

187
00:14:22,000 --> 00:14:23,000
Then we have to.

188
00:14:25,000 --> 00:14:34,000
Apply the pollution for each particle and the solution formula is x i t plus one is to the previous

189
00:14:34,000 --> 00:14:35,000
position plus velocity.

190
00:14:35,000 --> 00:14:39,000
That is the same part and or here in the lab view.

191
00:14:40,000 --> 00:14:41,000
So this is my.

192
00:14:44,000 --> 00:14:46,000
Updated position, as you see.

193
00:14:47,000 --> 00:14:49,000
This is my upgraded position.

194
00:14:49,000 --> 00:14:51,000
And over here, I got new.

195
00:14:52,000 --> 00:14:55,000
Variables x1x2x3.

196
00:14:55,000 --> 00:14:59,000
And from here again, we have to find out the fitness value.

197
00:14:59,000 --> 00:15:03,000
And as you see from here, the minimum value is.

198
00:15:04,000 --> 00:15:07,000
One five, six, nine.

199
00:15:07,000 --> 00:15:08,000
But.

200
00:15:09,000 --> 00:15:11,000
If you want to.

201
00:15:12,000 --> 00:15:22,000
Check or if you want to compare this fitness value, the fitness tool and fitness or here I got fitness

202
00:15:22,000 --> 00:15:22,000
one.

203
00:15:23,000 --> 00:15:31,000
This value is less so both from it will compare from fitness one with fitness two and which value is

204
00:15:31,000 --> 00:15:33,000
less because the function is minimization.

205
00:15:33,000 --> 00:15:37,000
It will check best over here.

206
00:15:37,000 --> 00:15:42,000
And my best is this 136 as you see.

207
00:15:42,000 --> 00:15:45,000
And my best is 9.9, 6.61.1.

208
00:15:45,000 --> 00:15:52,000
So using this, my final updated positions are this and initial positions are these as you see.

209
00:15:53,000 --> 00:15:58,000
So this is how you can or if you want to go through the video.

210
00:15:58,000 --> 00:16:00,000
So step by step.

211
00:16:00,000 --> 00:16:05,000
Again, we have to calculate using about our particular formula.

212
00:16:05,000 --> 00:16:07,000
So it will compare new fitness values.

213
00:16:07,000 --> 00:16:15,000
And from here, as you see our fitness value, initial fitness value, it will compare with.

214
00:16:16,000 --> 00:16:20,000
Future fitness value and it will generate best value.

215
00:16:20,000 --> 00:16:26,000
These are the best value as you see from this value and this value, this one is less.

216
00:16:26,000 --> 00:16:29,000
It will take it from this value and this value.

217
00:16:29,000 --> 00:16:30,000
This one is less.

218
00:16:30,000 --> 00:16:34,000
So it will take this from this value and this value it will.

219
00:16:34,000 --> 00:16:36,000
It is less so it will take this one.

220
00:16:37,000 --> 00:16:42,000
So mistakenly it is 7.217.

221
00:16:42,000 --> 00:16:44,000
It is 2.2179.

222
00:16:44,000 --> 00:16:51,000
So as you see which one is less, it will take its position.

223
00:16:51,000 --> 00:16:54,000
So as you see from here, the.

224
00:16:55,000 --> 00:17:01,000
Initial positions are these and updated positions are these initial positions are 8.8, 9.91.1.

225
00:17:01,000 --> 00:17:07,000
But the new fitness value for particular one is updated.

226
00:17:07,000 --> 00:17:11,000
So the positions are 9.8652.

227
00:17:11,000 --> 00:17:19,000
So using this, you can apply the BSO in live view.

228
00:17:19,000 --> 00:17:21,000
So this is how you can apply.

229
00:17:21,000 --> 00:17:27,000
So we just create these functions and lab view.

230
00:17:27,000 --> 00:17:29,000
So this will apply.

231
00:17:30,000 --> 00:17:34,000
Your particle swarm optimisation minimization problem.

232
00:17:34,000 --> 00:17:35,000
And you.

233
00:17:39,000 --> 00:17:40,000
So this is all about.

234
00:17:40,000 --> 00:17:42,000
So leave you.

235
00:17:42,000 --> 00:17:42,000
Thank you.

