Particle Swarm Optimization (PSO) is a powerful metaheuristic optimization algorithm inspired by social behavior, where particles explore a search space by updating their positions based on their personal best (Pbest) and the global best (Gbest) found by the swarm. The algorithm requires proper initialization of particles within defined search space boundaries (LB and UB), and its effectiveness depends on parameters like particle count, acceleration coefficients (C1, C2), and velocity weighting. PSO is particularly suitable for non-convex optimization problems where traditional methods struggle, though it may not find exact solutions due to numerical approximations. The number of particles significantly impacts solution quality, with more particles generally improving results but potentially causing diminishing returns or stagnation.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Lecture_08_Opt_2026Added:
Hi all together. Yeah, today we will go ahead with the PSO uh in the context of the the simul MATLAB better to say MATLAB code. So we will repeat the concepts uh and we learn also a little bit yeah some basic u aspects or elements I would like to say of uh programming a little bit but again here is not the course related to we we cannot learn in in in a few uh hours let me say uh to to to be to be able to to to realize really uh program and so on. But I will I already uploaded and working and running I would like to say and working software let me say so and then in any case after clarification it could be possible I think uh that you are able to manage this this um um this this software um yeah let me open MATLAB and let me restart shortly uh from the the software which we considered last time the software the program which is in the program uh which came I don't know if you remember yeah which came from uh my period in ABBR of Of course, I modified, I simplified.
Uh I did I did a lot of changes in order to uh yeah to to be accessible to you in this sense. I mean as in ABB I worked a lot on PSO but of course uh was inside this this programs were inside and very complex uh let me say uh software for instance we used PSO um to to to to optimize or to to to set up coefficients of our networks in many optimization problems we used uh PSO with with different variations. Uh we will see it could be that next week before starting with another topic I will show you u possible variation also today I will tell you without showing uh yeah different variations depending on then uh on the product which we have. Of course, variations uh more suitable is relative to concrete projects. But anyway, I will tell you something concerning possible variation which can help to find to find um optima.
Okay, let me share.
Nevertheless, PSO is the method optimization method very used in engineer at least very powerful extremely powerful.
Now the example which I am considering you can find in my study two files at this moment. I will upload also uh all the files today and I think also at the beginning of next week I will we will tell you a little bit again but very shortly and then we will start next week with regretly square is also important because could be a nice introduction a nice introduction to the topic model predictive control because uh as you I came from from the field of control. Of course, the optimization which I know is not an optimization for uh let me say mathematical optimization but is optimization for engineers. I would like to say this means more applied optimization. And one of the most important chapter I would like to say or topic in engineer is the model predictive control which is in an optimal as an optimal um control technique. And again next semester next seme I the upcoming semester I will hold in a lecture course in the sense related to the karma filter which is another optimal optimization method to estimate elements it's constant parameters variables state variable of a system.
Okay. Again here we you can find two uh file in my study at this moment and one is with the name we can see here main program and the other one is output function. Of course uh originally originally we can see also here uh the the the the software was inside the complex uh uh structure. We can see here in I realized this in ABB research center.
Um how possible to say um as I told you last time uh with with with this project in including also PSO but we didn't realize the patent or PSO because we cannot uh realize patent and adjusting software but anyway just to emphasize that this method really can be can be used also in real applications um Yeah, the other file is output function is the function to be optimized and originally uh everything was in one file but I split because I think didactically is more in my opinion is more uh useful to consider two files instead of one. uh please pay attention this is the function to be optimized of course is an artificial function in particular the problem is stupid why the problem is stupid it's not stupid excuse me the problem is I would like to say the PSO is not suitable for this kind of problem the reason is uh the the problem in Zo formulated in particular if you look at this the cost function We can see that this cost function consist of just one minimum at the point x1 = 2 and x2= 3. We can consider also a different uh we can extend you can see here also uh this cost function considering more than two variables but let me remain so because so we can compare I don't know if you remember with our example which I put at the beginning in order to start didactically uh with two uh variable to mute so we can also figure out what happens here I don't know if you remember math this structure here is a paraboid and I can I can graph this function here. X parenthesis one parenthesis X parenthesis 2 parenthesis is a variable is a vector let me say with two components and they represent our two variables to be optimized.
We can realize that the otimon is at is always positive is in a convex function.
uh the ottoman is x1= 2 x2= 3 and its values is 100 I don't know if you remember let me let me uh draw or let me graph in order to understand why the problem is not or better to say PSO is not suitable for this kind of problem we can we will see PSO will solve the problem but it's not suitable because the problem is convex Uh, X1, let me say here, X1, X2, X1 was 2, X3, X1, X2 was 3 and the value of this cost function which looks like something like that. Yeah, you can find we call here cost objective function it doesn't matter objective function and this value is 100 for the the scale is different between set and yeah is objective.
Yeah. Yeah. Uh nevertheless I I am considering this kind of uh this kind of function uh because at least we know the results and then we can discuss what happens increasing the number of particle we can discuss what happens reducing them uh we can uh uh do many considerations uh because we can validate our considerations. I mean the concept of the validation is extremely important in in simulations extremely important because we can validate something we can discuss about uh what we are doing if we know the results. Now we know the results in optimization just if I consider an optimization an optimization problem which must be which should be must be I would like to say um convex because if the problem is convex we know when minimum in this case we know where the minimum is we can see x1 equal 2 x2= 3 and then we can do some consideration because we know the results this means validation of course if I am considering at the end we will see uh a non-convex optimization problem. We will see very very important this concept does the program does not change is almost the same but if the pro it's the same but if the problem is not convex we don't know where the result is this means we cannot do any consideration increasing a little bit yes of course we can guess what happens increasing or reducing particle or I don't know what I I know what but at this moment I don't want to But of course we are in the the field of hypothesis. Here we will see now that uh uh changing some parameters some elements in particular the number of particle but of course we can change a lot of thing. Uh we can realize or we can uh uh validate or we can consider with more clear uh let me say uh concept what happens. Please pay attention. I can consider again other variables. But why I I considered now just two variables in order to figure out what happens because with two variables I can I can graph with more than two variables I cannot graph. Now um of course the dimension of the problem this means how many variables I have x1 x2 x3 x4 it depends of the problem which I have theoretically infinite. Okay, theoretically you know but let me say arbitrary number of parameter this isn't a function we can see here this means it's not the main program I don't know if you know some knowledge in informatic let me say informatic in programming better to say the function must be called from by uh another program which basically we we we we call main program okay let Let me go ahead tick.
This means we have an attack somewhere.
In order to calculate uh the time between uh the line eight and another line, we close uh this this let me say this loop or this part of the c the problem in order to have an idea about the the calculation time. Typically the calculation time is not exactly an in a parameter which is say an indicator of course can be used but it's it's a relative indicator. Why is a relative indicator? is a relative indicator because uh uh the time of execution depends of the microcontroller which you have depends on many thing the tool which you have the computer everything let me roughly speak it very important are I would like to say the number the calculation law the number of operation which I do which I to do with with with with the program but in any case is as an relative indicator is very very often used in in the sense we can we can nevertheless calculate between ticket talk we we can have a good idea if I introduce the M variations what is the cost can be can be done before the variation and after the variation between tick and talk I show you later uh the computer will print the the running time between tick and talk CLC do you Remember if I remember CLC uh clear the the the common window. This basically is relevant. Clear all clear the variable which we have here in uh the workspace.
Close all close is the the the figures.
Format long. Format long is in a way to represent uh the value the variable the results uh with the maximal with the maximal number of uh decimals but it's just a representation the the the precision if you want to increase the precision you remember last time I told you um if I remember well is something like that I don't remember you have to look is here in relation to digit. Yeah, look here.
If you want to increment, if you want to increment the the position of the machines, use this one.
Here is just a representation.
RNG default is the the the the yeah because we we have with this we have the possibility uh to to use different different uh random number. Yeah. Default is in a uniform distribution between zero and one. This is the typical typical the standard let me say therefore default way to generate to generate random number. to remember the random number is extremely important in this in this context because the PSO as the genetic algorithm is based on the randomization of the let me say distribution of the particle of course we can use different distribution we can use also chaotic distribution and so on but let me this could be the top a possible topic in our project line 15 is basically in the line which set with states and vector we will see we will use at the end um without dimension I mean theoretically I put here a number let me say unlimited of of elements unlimited means until the overflow of the machines without dimension LB and UB do you remember the concept LB and UB the concept here is related it to the field this uh let me say the search space in which I will assume that the minimum is of the optimum in general I mean here I am assuming that the minimum between minus3 and three and between -9 and 10 this means x1 which minimize the function I assume that is between - 10 and 3 and x2 is between -9 and 10 it is a good hypothesis in our problem because you remember x1 was two and x3 was three I remember this means a year inside now we will see we will see what happens if my assumption is wrong in the sense uh the minimum is not inside this this interval I mean if you want to understand exactly this this this this uh this represent this representation this this boundary let me Okay. Uh basically, so uh now I already forgot. Let me see. LB it is - 10 for X1 and UB is three.
Let me see here. - 10 for X1 and here is three. This means X1 I will search randomly here. Uh, x3 was uh is - 9 10 x2 excuse me x2 is - 9 let me see here 10 of course the scale this means I will look I don't know if you can understand the search space I will look on this region here characterized by this rectangular region of of my I will look here in this domain let me say so in order to use the the wording which you know the minimum the minimum is here and we will see that the PSO will try to find this one of course again to solve this kind of problem it's not necessary PSO is not suitable PSO.
We have also method like uh Rapson on this tangent method more efficient.
More efficient means for this kind of problem because because uh we have a less number of calculations less uh running time. But of course in this case is also stupid because if I know that the cost function I can calculate analytically without numerical approximations. But anyway we will see how important nevertheless this example in order to understand the method. Now again we can understand also from this representation why I consider just X1 and X2. uh in this case I can explain very well this uh research area uh re the search the search area or the search domain you can call as you want let me now uh come back on the software of course I have to know where more or less is if I don't know I can write of course Yeah. Uh minus infinite plus infinite. But in this case of course if I put here minus infinite plus infinite the algorithm it could be that it needs a lot of time to to search because plus infinite theoretically large lb in absolute value large UB means that it could be that I'm not able to find microcond the minimum or a value which is nevertheless acceptable. for us.
Of course, there is the idea is if you look at the literature, the effectiveness of the of the algorith depends also on uh uh let me say the density of the particle and the density of the particle is related the number of the particle with respect to the dimension um of the uh search space. Again, do you remember last time this to be the example as I told you if I ever do to uh search in this room alone the key or my key is not the same thing if you help me to look in the same area together with three or four people. Yeah, it's easy to understand. If I have one million of particles instead of one, of course, the probability that I let me say the algorithm will I mean in in a in a convex problem is not so is not so uh extremely important.
Nevertheless, nevertheless, the probability that I will have some some very quickly some particle in this region is higher than if I have just one particle because one particle have to move over the steps. This means over times to this one. This means the density the number of particle divided let me say the dimensions in the sense easy to understand the surface which represent our search area or search region is uh the element which must be take take must be taken into consideration must be taken into consideration. Uh one second let me share again.
This means LB and UB are extremely important. We will see later what happens if if the minimum is outside because this is my hypothesis the dimension is two two variables I assume 10 particles.
Do you remember vax v min is the maximum and minimum value of w here is fixed. Of course this could be also variable. But let me let me fix then we will we will see c2 and c1 I fix equal to the reason is could be also variable. This could be also adaptive over steps over time. step equals time in our case um equals two because if R1 and R2 I don't know if you remember that I will come back on this the structure of the PSO uh are random variables uh uniform distribute between 0 one this means the mean value is 0 comma 5 if you want to weight you remember the component B best the component G best with the same weight statistically you have to consider the factor two But this also could be an interesting variation. We realize the different variations considering C1 and C2. This dynamic acceleration factor I told you about this metaoristic acceleration could be also considered which change over time. At this moment forget this intermediate iteration also is important in case of some variations.
We are just consider maximal iteration to start for project. we will see that we can consider so uh and I now I will clarify what what what we can use this here um maximal loops also here to think about one basically don't consider this but believe me believe me it's easy to understand that I can use for different tasks more than one sworn let me say parallelly I I will try probably next speak very shortly to to tell you about this possible variation. At this moment we have just one sworn just one word also here everything related to max and loops forget because otherwise to to complex also this one also here this four here you can forget because it's related to maximal loops we have just one just one uh swarm this means this loop here is not active Exactly. Uh yeah, we can cancel this.
Yeah, just to here because run is basically why index for the loop which is starting 47 but as I told you basically we don't have this loop because it's running just one then very interesting here we have the loop uh which start with four I and 4 A uh and we will close with end and end. The for loop means I fix I equal one. I will run J from 1 to M. Uh the command which is here inside again at the beginning for I= 1 I will run J from one to M. Then I will increase J I excuse me. And I will run again J from 1 to M. What is the meaning of this? The meaning of this that I fill up an initial position we will see of my swarm considering randomly variable between LB and UB. Why that we can see from here this is not the uni the unique way to do. We can see also another way uh possible another ways but the reason here is because of this random variables is the variable between zero and one when random is zero almost zero we are on LB or almost in LB when random is one we are in UB I don't know if you can see this means that each uh let me say loop for J because J let me say depend of I if you want. No for each I we have a full uh loop of J. I will obtain my search area or better to say I will fix randomly I and J. I will fix the particle in my search area. At the end of these two loops, I have randomly where ish me until until here. uh until here I am randomly the position of the initial uh let me say I have randomly the initial position of this wall is here x0 mat x0 mat randomly uh yeah uh calculated let me say inside lb and up I change just the variable I fix the initial value of the velocity do you remember we of uh position and velocity and then here very easiness to understand what I do here I another for loop but this time just for let me say each particle what I do here I call my output function you remember this this paraboid in two dimensions and what I what I do with this command I calculate my uh paraboid in my let me say domain for each this is the way to represent uh every every J for each J or let me say in all domain I will now I will switch on uh the lateral camera to understand better this what you can see this for I equal one I will call the the function and I will calculate the value of the function at for the particle one considering it's all its coordinate its coordinate I would like to say both and I save isn't a vector why isn't vector because to characterize a matrix I need I and J but yeah J I don't have this means I will calculate the function and I put the value which I obtain in the row one row characterized by the index I show you what I intend what I am doing with this operation For the particle one I have its coordinate which came from the randomization for instance this and I don't know this and then I will calculate calling the output function its value and I say this level here which I don't know could be 20 200 I don't know what is in a vector in a row vector characterized by the index I I use the index as I want in different context.
what I intended with this sentence.
Yeah, this is the the index of the vector f0 is the vector because uh we have fixed um this dimension, the second dimension to one Really I make mistake is the column F0 is a column it doesn't matter anyway is a vector a column vector because I represent the row okay now I will calculate the minimum once I calculate the pos the position the value of the particles Let me say for each particle I have a vector with length equal n and then I will calculate the minimum. This is in the function of matlab of this vector. What is the minimum and I can save the value of the minimum in the first uh uh element of this vector and its position. It position means I localize what is the particle which have the minimum and what is the value of this minimum is basically is a vector with two components.
I put X0 equal P best I in G best I will put the the best particle. Uh we can see X0 is the position of uh this warm this warm at the beginning we are we are not flying not yet we are in the initialization phase. Do you remember the last time I I clarified this and I put in G best what the best basically this is one particle characterized by I know what is could be the first could be the second and all its coordinates but it's best to say its coordinates in our case we have a row with two columns the best particle is characterized by X1 and X2 now in the initialization phase.
Why that? Because now we will start to fly. Let me say to fly in which I fix the number an indicator in the number of iteration about the tolerance for forget now but you can understand that we can check and intermediate. You remember this this this word intermediate uh step in order to see uh we will see later with in order to see if it's worthwhile to go ahead with with the with the with the software because sometimes really heavy the calculation lower the running time and so on. I will come back on this later. At this moment forget otherwise too many information but try to guess that I can check I can check we can see directly here now if uh some tolerances are satisfied and so on.
Now we'll try to fly. Fly means while is in the cycle like four. Let me say so roughly speaking in which the iteration we will update at the end uh plays an important role because until ititeration less or equal the maximal iteration I will run everything inside the loop characterized by while will finish with an end. It's quite similar to four.
Here again as I told you last time we have the the the weights of uh the previous velocity.
We can see that I am considering here and the variable weight between vmax and vmin as a function of the iteration. We will see this iteration will change uh first iteration second iteration will increase this counter and maximal iteration. We can see that for iteration very very small theoretically zero uh we have that we have v min excuse me uh vmax and if iteration equal maximum iteration we have a v min. This means we reduce the contribution of v the old velocity over time of the over step. The reason is the reason is uh we try to converge in one point. This means we trust we trust uh the work of of this war in order to emphasize in order to emphasize the exploitation phase over time.
But about this we can discuss and we can discuss what's in the typical typical.
Now these two loops the first loop is the loop for the velocity. I don't know if you remember uh the con is a bit a little bit complex because remember we have here let me move three vectors. This is the old velocity.
Here we have an random vector because of the random variable here which updates uh the velocity considering the position the preview position of the population the best population. I will clarify this a little bit later. But you remember last time I theoretically told you this is the matrix in which I put when I find when I find uh the best uh element but consider the the population not not just the best of the best when I see that an an element in a particle uh the step uh in which I am considering the program is better than the before I will place. Yeah. The best population, the best war, which I intend now we see uh later a little bit better. Uh when I have the the the best bird, I will replace in this B best and then I do the difference with the old one.
We can see later what I did. Here is more interesting. this because here do you remember I will orient let me say the old position considering just the best because G best if you remember is in this case in a row.
Yeah, it's the comment is a little bit strange is let me say wrong because we have I I reduce the dimension to two.
No.
Uh but in the next example I will increase to three. Therefore remained three even though in this case here is two is narrow with two elements in this example and later I will show you with increase in the dimension and then I have to put three but I forgot to correct now it's correct.
Exactly. In G best one, J we have the best element. And Matlab understand that each row, let me see here.
This is the and a row with two elements in our case, but could be three, could be four depending of the host function.
Matlab understand that each row of this because of uh J which is running this the the coordinate must be uh regalulated and it's for this means somehow we reorient reorient the previous previous uh swarm the position of word considering the best uh the position the position please when I say the position I indicate J because J uh is from one to two indicates the coordinate consider the position of the best word I can I can show you a little bit later the okay and then I do I update the position considering the the velocity And then look now interesting I will check here with this two four loop if we are in the boundary or not. If you are in the boundary I put the boundary.
Basically if x is outside the boundary this means uh uh or Yeah, in the sense is outside I put the boundary because I am searching just between LB and UB.
This is for LB and UB. Now the problem is here if I am on the boundary this means I I don't have the minimum or better to say the relative minimum. This means that we have to reset the boundary. We can do something also different but I will tell you probably next week.
Then I call again the output the output function and I will calculate the output function for the new position. This is the new position X could be on the boundary but I hope we hope that is inside because on the boundary and not in a valid minimum the sensor is uh the minimum of the interval but we looking for the relative minimum which hopefully is the global minimum.
I calculate I put also again in a in a column and then very important this for loop from here to here with inside an if loop what I'm doing here I ask if no let me say I ask if the new position which which of the new value of the function calculate that the new position of the swarm is less than the old one. Think about f0 as the initialization uh minimum.
If yes, this is the sense of the if no.
If yes, we do uh this operation and this one. If not, you don't do anything.
You don't do anything. This is the sense of the of the if is a little bit more complex than four. Four is just running here is a little bit more complex. But what is the meaning of this? Basically, if I have something better at the step one with respect at the step zero initialization, I will put what I better the I which is better with its coordinate or all coordinates if you like in PB best. basically I replace uh the position uh the old position with the new one because it's is better in accordance if this if is positive is yes and very important I put in f0 the new value why that because f0 at the beginning at the step one is the initialization uh value of of my uh first searchh first search and initialization search but then I will reuse f0 for the step two for the step three this means I have to replace what I have if is the best if is the best is better let me say if is better in the f0 so each time I will use f0 I calculate the minimum of f0 and its position the minimum on f0 and if position this position yeah forget it because run which is indicator of the to use more than one loop I didn't include now in this variation because I would like to explain the basic is already complex somehow what I am doing now I need to complete I almost at the end I need to complete the P the G best because PB best is clear what I intend each element for the or if a step one is better at the step zero I will replace at the step two I I do the same is the step two uh indicates that the new position of the swarm the particular swarm is better than before I will replace but for the old swarm here we are considering now the best of the best look I will consider the best of the best because I even consider the population best. But consider just the best of the best for all its coordinates or consider its coordinate.
A I put in G best index indicates the best of the best which I have in for all for population P.
G best very often global best. I put also in this case the value of the best of the best in F mean zero in order to be reused also. Do you remember f mean zero as f0 this is this was also present at the beginning in the uh yeah in the initialization phase. We almost at the end because now we have P best and G best.
Forget this because again everything related to the indicator and we didn't consider here. Tolerance also we didn't consider but we can understand that we can uh complicate the algorith introducing some some checks in order to reduce the time of calculation. If it doesn't work to go ahead, I will clarify now a little bit better.
Now I can print the results which is in G best because G best is what we want to obtain the best of the best value where we have the minimum or we where we supposed to have the minimum and then I can calculate for you instead of X1 and X2 is I copy uh the same the same expression but I put the G best one and G best 2.
We have g best for x1 and gb best for x2.
I increase the iteration.
I will fill up my vector. Remember this fmin plot we will use we will see for the plot is the vector is the vector in which I accumulate each time the element of f plot we can see on the left on the left we have f min plot on the right fb plot but I will add I will add uh the last minimum which I'm finding I will clarify with with the plot what is what is This what is this this this vector here at the beginning do you remember we define this fmin plot with infinite let me say dimension infinity means ant overflow this end here conclude my while and this end here conclude my run but this is not active is here because I applaud it for you.
Sometimes if you decide to work on this on this PSO could be nice, could be useful to to to to consider in the project some different variation with tolerance with more than one uh swarm.
Uh anyway, this this means is there but you remember run the indicator one is one. This means is not active. Let me run change folder.
I hope no mistakes because sometimes the student ask me some changes and then I forget to as you remember 100 is our minimum.
calculate it.
Oh, the the PSO find X1= 2 but not exactly two and X2= three but not exactly three. Yeah. The reason is the reason is that this numerical approximation not only connected with this numerical approximation I have to say you remember last time.
If you can see the excuse me here the problem just in one dimension in order to calculate auto2 a little bit better in such kind of problem if I consider just one dimension you can do at home reducing to one dimension I I show you if you want I don't know uh x equal uh x1= Two.
Just try to consider an section of this paraboid with just intersection considering a plane or two or something like that. Ideally, ideally is a function which looks like something like that. the parabola remember 100 and the parabola here set equals uh x1 - 2 + 100.
But of course in our numerical representation in our numerical representation is not exactly so but something like that because we have an numerical representation of this surface or this parabola. This means numerically the problem is not convex.
It could be that here. It could be that here and not exactly two.
This can be understood if I increase for instance the number of particle. If I increase the number of particle the probability but just in a probability that I am closer and closer to to the values two is higher.
If you remember the concept which I explained before the density the density of the particle is extremely important inside LB and UB in order to find the the solution of the solution is two in our case here or in the case which I am considering the software is 2 three and that is of course just a probability because don't forget don't forget that the the the the method ah excuse The method is a random method. But let me see if I'm able to show you this concept here.
Let me copy this.
Of course, uh for this easy example, it could also not be valid. What? But typically yes. Now what happens? The question is what happens if I increase the number the number of particle?
theoretically or statistically I will fell down in a solution closer and closer to two entry. Let me see. But of course statistically if I go here where is now instead of 100 let me like 1,000. Of course I will increase the calculation time.
Uh I don't know if I copied here probably. Yes. Let me copy these two values. Let me see if I copied. Yeah, I copied. Okay, let me run.
Not necessarily will obtain a better result but statistically yes. I don't know if we had this is the new values.
Let me compare with this.
Yeah, it seems to be better now. Let me see.
Two 4 6 8 2 4 6 8. No, we it is not better. And also here it seems to be not better.
Um but as I told you is something statistic probably increase more or decreasing decreasing with one should be worse than this one.
But also this is uh something statistical at this moment we have this is the best with 10 which is the best with 10. Let me see with one what happens.
Totally wrong. Oh, we can see the reason is the reason is with with one we will remain somewhere.
Show view this. I clarify also also wrong.
Let me we remain somewhere here we can see here in one dimension we will remain somewhere in one uh numerical local minimum the system which I'm considering the the cost function is mathematically convex but of course numerically we have many valley and many hills But of course one particle is a little bit sage because with one particle we cannot speak about uh this worm G best is equal p best. Let me consider two elements is already more meaningful.
Uh the reason is that at least we have as we have the difference between G best and P best with with two element should be definitively better but of course nevertheless relative wrong increasing increasing we have better and better it seems seems to be that we have an saturation because you remember I put 1,000 10,000 we didn't have an uh an improvement.
The reason is that of course we have we have this is a something valid but statistically it could be could be that we have also an optimal I read something about that an optimal number of but this means this is a very interesting problem uh I try to explain why this is interesting this why we have an optimal number of particle. This is could be another interesting project to optimize the number of particles.
Assuming that to build my house alone, I need one year.
If you help me to build my house to person, I can assume if the system is linear, we need half here.
If you consider uh four people, I can assume that we need just three months.
But if I enroll 1,000 people, you can believe me will never finish my house.
What is the meaning of this?
Also this concept of PB best with the the the the indicator of the new direction the indicator of what we have to do at the next step. Sometimes if the swarm is is too large not necessarily we find the best uh the best indicate also the best indication to go ahead. No, the example of to building houses is interesting.
alone. I can I can consider this to finish this work is one year with two people. I can consider half year four people three months but 1,000 people never finish the house just just to understand that the problem is a bit more complex and n could be also in the sense the density could be also uh the parameters to be optimized no but anyway I'm not expert on this no but I try to to to give you some interesting uh indication ations for possible projects. Okay, let me go ahead a little bit and next week nevertheless before starting with another topic we will come back on variation and so on. Let me consider just one dimension and then I will show you in a real project even though in a simplified form in order to see how the the program is exactly the same. This means this structure here is in a basic structure. Uh we here in my in my in my uh in my lab we will we consider also variation with 2G best with priority without G best depends of of of this optimization problem. Now I don't want to tell you much about that but next week I will tell you uh the transformation the transformation of the search domain to improve also uh or to uh reduce the station staniation of the particles.
Staniation means when the particle remain too long or don't move from the region. Now if the problem is convex we can see that the most important thing is the number of particle. Again we can see that we have an acceleration.
This means not necessarily an infinite number of particle is better than the finite one. We have also we have a scene also here because in the problem of optimization again the example my to build my house is an important example. It's difficult to optimize one the work of 1,000 people.
I am sure that we will never feed the house.
Let me now reduce the dimension how easy to modify this and then I will show view in a real project and then we upload plot which is basically the same like this.
Okay, let me go in the uh in the out function. Let me now consider uh just this plus 100 semicolon. This you can see now the active function consist just of one part one dimension this is a parabola exactly as I graph and with the lateral gamma let me say so what I have to change here a few things m= 1 number of variables now we don't have x1 and x2 we have just x1 the number of variable let me remain m equal to but let me consider 10 or the 20. So we we find more correctly the minimum the rest I have to change that just LB because a UB because now we don't have a rectangular uh search space but we have just a line let me show you in now if I'm reducing we are considering justice between I don't know what but let me include the two like yeah I am considering justice because I'm assuming that I am interested just in just to show you something for you how easy now is to This means uh let me say so between minus three and three what I have to change basically I don't have to change practically anything but you remember at the end in order to visualize in order to visualize is the the the the the solution I put it here that's this calculation here now should be considered just one dimension this means I think I I I didn't forget anything but this of course just to visualize uh the results right if you You can fancy this.
Let me run. I think no mistakes.
This is the results.
Uh it's equal to okay I put this this semicolon.
Therefore I didn't visualize the results. If you remember I told you at the beginning this semicolon here means don't print this line this result well let me we can see the result around two we didn't improve the the the the the precision we can we can using this fa look 100 it is approximated is a little bit uh uh strange this approximation I cannot clarify Y it should be not 100 should be something more I don't know why probably depends of how is set the cut of calculation I don't know I know I cannot explain why should be at something more than 100 try to use fa with digit but it's not relevant for us because just is just to to look but of course it's not 100 because 100 is a two.
We are not at two.
Very important. Now before show we do in in practical example, more practical example which is basically the same. What happens? What happens if I set LB between - 10 and 1. Interesting because now we know that the minimum is a two but lb is okay but UB is not what what I intend is this one the interval which I am fixing but in particular UB excludes basically I'm searching between what I told you minus 10 something like that and But but between minus 10 and one we don't have the minimum because the minimum seems to be at point 2. What are you waiting for? That's the PSO will crash again this upper bound because the PSO will remark we see that the minimum is outside. Let me see because the the PSO will search uh in this region here slowly slowly the particle slowly depends of how accelerated this I didn't tell you about the possibility to accelerate the algorithms but in any case we will find this minimum here which is the local minimum on the border of of this interval or if you want is the the global minimum considering the the the the the interval which I am uh which I fixed let me show you I am waiting for instead of two one no very close to one that's numerically of course we can have but I think should be And yeah, we can see a G best which is our solution is one.
The meaning is that PSO sees something better outside of the interval. If I increase again, we will find two.
I don't know if it's clear what I did.
If I put three I will find again two the best is our solution again too. the same way.
In the same way, if I put here uh three and four what I waiting now that I will find three I don't know if it's clear because two is outside but less than the lower part of the lower boundary.
I mean two is our minimum.
If I fix three, four s space, I will end up here. Okay, let me show you because the PSO try to go towards the minimum but will crash. Let me say again against the lower bound this time.
And this is due to this check this two four.
Yeah. We will check if is outside of the boundary. We fix the boundary. If what I'm looking for is outside of the lower bound. In this case, I fix the lower bound.
Now we are waiting for three.
In fact, it's not 100 110 fixed because we fixed we put exactly the boundary. We I think I explained everything here. Let me open an area project very quickly. We will see how similar is or we can we can do next week probably this better because nevertheless I needed to clarify some aspect but nevertheless we will see that the structure of the of the software is exactly say uh the problem which I would like to show view next week is an approximation of uh data which stay uh the roughness of an surface. Remember I told you at the beginning you have to minimize using uh a robot know the the roughness of of an surface. The the variable to beimize is omega and v rotational velocity of the end factor in translational velocity. But of course before before considering this optimization problem we have to consider another optimization problem which define we calculate the the the the cost function which is the roughness and this is built within a fitting problem which we have seen also the meaning of the fitting problem considering at the beginning the le square method and so on. Now we will consider with PSO why that because the problem is not convex not convex because the regressors is in a mix regression uh in this case which I am considering next week is an exponential regressor with different exponentials and this means the problem is not convex anymore you know because I cannot distinguish between what I have and what I don't have let me do next week this I don't need much time but it is better to because a little bit a different a different cost function so on but the software is exactly same because the cost function is build using exponential function and so on or better to say the square with the regressor exponential function we calculate the parameter of the exponential functions um which characterize this new regressor and then of course the step after that is to calculate the the velocity of the robot but this uh I have also somewhere but it's not necessary to I haven't I have not necessary to show you and then I will show you this way uh to manage to manage the the search space in order to avoid station of the the particles in order to having a more effectiveness uh let me say velocity also in the sense position of the of the particle. The reason is the most important phase is the init initialization phase or exploration phase because if we have a wrong and a wrong uh uh let me say direction at the beginning sometimes is difficult but of we can we can modify the algorithm as we want but the most important thing to to to have the the right direction or the a good direction a suitable direction starting from the beginning and then sometimes to uh transform with the transformation with the function the the the the search space could be useful. I will show you just one ideas um to get after showing you this this practical the real real example even though simplified for you uh to to to be understood better. Okay, let me stop here. I have I am here for questions next week. Nevertheless, I think I will dedicate 15 minutes, 20 minutes and then we will start with a new topic. New topic is recursively square. After the recursively square, I think we can conclude the course uh use just MPC considering NPC which is control optimization uh optimize control strategy. If I have a time we will see something about LR or a Miltonian but I don't know if I have time otherwise we can consider in project uh of course I will I will assist you on this this rest of the topics even though I didn't I will not able probably to go in depth or to tell you about that but the concept of the optimization I think we have seen during during at the end I hope I am here for for Listen.
Related Videos
OpenHuman VS Hermes AI: Who Wins?
JulianGoldieSEO
285 views•2026-05-29
BREAKING: Microsoft’s New Image Generating Model Beat Out GPT 1.5 and Nano Banana 2
aimmediahouse
122 views•2026-06-03
Long-Running Agents — Build an Agent That Never Forgets with Google ADK
suryakunju
142 views•2026-05-30
This computer is made from real human brain cells. And you can buy it.
Talktmsmedia
3K views•2026-05-28
I Made the Same Anime Fight Scene in Every AI Video Generator
NobleGooseAnime
295 views•2026-05-30
Nvidia Bets Big On AI PCs | New Chip To Power Windows Laptops | Technology | AI Updates | N18S
cnnnews18
3K views•2026-06-01
I Tested NEW Opus 4.8 on Four Projects (Updated LLM Leaderboard)
AICodingDaily
298 views•2026-05-29
3D Platformer Update - NO CAPES
SolarLune
294 views•2026-05-30











