Help with PSO Algorithm with multiple variables

Hi everyone. I am fairly new to PSO algorithm and i need it for a project i work on. I've gone so far after reviewing and using multiple sample codes for PSO, but unfortunately still no luck getting it to work; so any help on this is appreciated :).
I'll Attach the files. Thanks in advance.

6 Comments

Well, a lot of people may not download and run these files until you explain in detail what "still no luck getting it to work" means. Does it throw an error? (If so paste all the red text) Does it run, but just not give you the results you were expecting? What's the problem?
And, if certain optimization toolboxes are required, list them below in the Products section.
no. no additional toolboxes are needed. its not throwing any errors. simply put. its not optimizing anything ... instead it simply loops and shows the same results through out the program run. and yes, its not showing the expected results.
Did you read this link? (I'm guessing not or else you'd have given me the answer to what I'm going to ask next.)
Well, what are the expected results? Do you know what the answer is supposed to be? Are you stepping through it with the debugger examining each variable as you go?
Come on, make it easy for us to help you.
well sorry about that ... I'm currently working on a different subject that requires my full attention and I'm bit short on time. also, about the question, answers are good when the cost function decrease with every step ... meaning get more and more efficient results.
also when i check if i correctly pass the values to the function, something funny happens.
Particle(p).Position = rand(1,NPar) .* (VarMax - VarMin) + VarMin;
Particle(p).Cost = CostFuncName(Particle(p).Position);
first line creates the initial random values but when it passes to the function "CostFuncName", it simple seems to change to lower bound of value.
Note: S8, S9, S10 are all unused in your cost function.
Note: your cost function contains a singularity. Your gx divides by sqrt(S1-S3/2) but your range of values allows S3/2 to equal and exceed S1. When S3/2 exceeds S1, your gx goes complex. You might not notice immediately, because min() chooses the value with the smallest complex magnitude with complex numbers are input.

Sign in to comment.

Answers (1)

Algebraically, your cost function works out as
3638528/25 * (X11 - 57) * X1 * X12 * min(67/100, 451/31250 * ((4 * X1 - 2 * X3)^(-1/2))) + (4148000 * X1 * X11) + 7277056/25 * (X11 - 57) * X1 * X12 + 909632/25 * (X11 / 2 + X2) * X13 * X4 + 9882000 * X4 * X5 + 204553496/5 * round(X6) * round(X7) + 8784000 * (FS6 / 8 + X2 - X4 / 8 - 9/8 * X5 - 100) * FS6 + 24105248/625 * X1 - 909632/25 * ((X11 - 57) * X12 * min(67/100, 451/31250 * ((4 * X1 - 2 * X3)^(-1/2))) + 53/200) * X1 + (878400000 * X3) - 2196000 * pi * (FS6 - 80)^2 * round(X7) + 1585974053518/5
where FS6 is
piecewise(round(X6) <= 3, 125, round(X6) <= 4, 130, round(X6) <= 7, 145, round(X6) <= 9, 150, round(X6) <= 13, 165, round(X6) <= 19, 180, round(X6) <= 22, 190, 195)
We can reason about this value with calculus, such as by differentiating with respect to a variable and solving for 0 to attempt to find minima.
I will update this in pieces as I work bits out.
diff(Cost,X2) = 8784000*FS6 + (909632/25)*X13*X4
X4 is strictly positive. X13 can be 0, so we can reduce the second term to 0 (but not negative), leaving us with 8784000*FS6 . However, FS6 is strictly positive. We can deduce from this that Cost will be minimized with respect to X2 when X2 is at its lowest bound.
diff(Cost,X5) = 9882000*(X4-FS6)
FS6 never exceeds 195, and X4 has been defined to have a minimum of 300. We can deduce from this that Cost will be minimized with respect to X5 when X5 is at its lowest bound.
X8, X9, and X10 do not appear in the Cost function, so their values are irrelevant; you can improve performance by removing them.
... to be continued.

6 Comments

diff(Cost,X13) = (909632/25 * ((1/2) * X11 + X2)) *X4
All of those quantities are strictly positive. We can deduce from this that Cost will be minimized with respect to X13 when X13 is at its lowest bound.
... to be continued.
diff(Cost,X4) = -1098000 * FS6 + 9882000 * X5 + (909632/25) * X13 * ((1/2)*X11 + X2)
X13 has a minimum value of 0, but none of X13, X11, or X2 can be negative, so we can minimize the positive contribution of the final term by letting X13 = 0, leaving us -1098000 * FS6 + 9882000 * X5 . At first that looks promising for a 0, but the most negative we can take the first term is if FS6 is its maximum, 195, and -1098000 times that gives us -214110000 . However, with X5 being at least 127.5, the second term 9882000 * X5 gives a minimum contribution of 1259955000, about 5 times as large, so the overall expression cannot reach 0. We can deduce from this that Cost will be minimized with respect to X4 when X4 is at its lowest bound.
So far we have that X2, X4, X5, X13 must be at their lowest bounds, and X8, X9, X10 are unused.
... to be continued.
diff(Cost,X12) = (2728896/25*(X11-57)) * min(67/100, 451/(31250*sqrt(4*X1-2*X3))) * X1 + (7277056/25*(X11-57)) * X1
X11 is at least 175 so X11-57 is always positive.
The min() is always positive.
X1 is always positive.
With these facts we can see that diff(Cost,X12) is always positive. We can deduce from this that Cost will be minimized with respect to X12 when X12 is at its lowest bound.
diff(Cost,X11) = (2728896/25) * min(67/100, 451/(31250*sqrt(4*X1-2*X3))) * X12 * X1 + 4148000*X1 + (7277056/25) * X12 * X1 + (454816/25) * X13 * X4
X12 and X13 can both be 0, and none of the variables can be negative, so we can reduce this to the expression 4148000*X1 . However since X1 is never negative, the expression must always be positive.
We can deduce from this that Cost will be minimized with respect to X11 when X11 is at its lowest bound.
diff(Cost,X7) is complicated by the round(X7) .
A straight-forward diff(Cost,X7) would result in a summation involving round(1,X7) in both halves, where round(1,X7) is the first derivative of the round() function. The first derivative of the round function is 0 wherever it is define. Together this could tend to suggest that the derivative diff(Cost,X7) is everywhere 0 (except possibly at integers), which might be theoretically true but is not useful for our situation.
So for the moment, substitute RX7 for round(X7) in Cost, and take the derivative with respect to RX7. The result is
(204553496/5)*round(X6) - 2196000*Pi*(FS6-80)^2
That would seem to have some potential for becoming 0, but if you investigate over the bounding range X6 = 1 to 27, and substitute in the resulting FS6 values according to the piecewise() expression given above, then it turns out that this expression is everywhere negative. We can deduce from this that Cost will be minimized with respect to X7 when X7 is at its upper bound.
So far we have that X2, X4, X5, X11, X12, X13 must be at their lowest bounds, and X8, X9, X10 are unused, and X7 must be at its upper bound.
... to be continued.
If you substitute those lower bounds into Cost, and substitute in the upperbound on X7, then you get to
Cost = 3475906553518/5 + (453705578936/625)*X1 + 818213984*round(X6) + (8784000*((1/8)*FS6+11505/16))*FS6 + 878400000*X3 - 43920000*Pi*(FS6-80)^2
By examination we can see that the expression would be least when X1 and X3 are at their lowest bounds, 1250 and 300. Making that substitution, we get to
Cost = 9330562342878/5 + 818213984 * round(X6) + (8784000 * ((1/8) * FS6 + 11505/16)) * FS6 - 43920000*Pi*(FS6-80)^2
where FS6 is the piecewise given above.
Plotting that, we see that it is everywhere positive, and is least positive when round(X6) is 23.
The minima within those bounds is at X1 = 1250, X2 = 1000, X3 = 300, X4 = 300, X5 = 255/2, X6 = 23, X7 = 20, X11 = 175, X12 = 0, X13 = 0, and the minima is 15791753076038/5-580842000000*Pi which is about 1.333581655*10^12

Sign in to comment.

Asked:

on 17 Dec 2016

Commented:

on 19 Dec 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!