How to solve this error when using PSOGWO to optimize an objective function?
2 views (last 30 days)
Show older comments
When I run the code of PSOGWO to optimize the following function :-
function f = simple_fitness_two_layers(x)
load gh2b.mat;load obs.mat;
%where :-
r=[58.3095 76.1577 86.0233 98.9949];
r0=mean(r);zx=[30 30 70 70];s=0;
for ii=1:length(r);
s=s+(abs(r(ii)-r0)./4);
end
Phim=s./(zx);
f=norm(gh2b*x(:)-obs,2)+20*Phim;
%and gh2b is : 12*30 matrix and obs is 12*1 vector
The following error:-
Operands to the || and && operators must be convertible to logical scalar values.
Error in PSOGWO (line 38)
if fitness>Alpha_score && fitness<Beta_score
Error in main (line 25)
[Best_score,Best_pos,PSOGWO_cg_curve]=PSOGWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);
>>
1 Comment
Walter Roberson
on 19 Feb 2019
(Note: the source code for PSOGWO is possibly at https://free-thesis.com/product/hybrid-particle-swarm-and-grey-wolf-optimization/ which charges up to $US100 for access to it.)
Answers (1)
Walter Roberson
on 19 Feb 2019
zx is a vector so s./zx must be a vector so Phim is a vector. You add Phim to the scalar norm giving f so your f is a vector . However the routine you are running requires that you return a scalar .
2 Comments
Walter Roberson
on 19 Feb 2019
Well in that case, if that is your objective function, then you have a problem. You will not be able to use a PSO or GWO technique. You will need to switch to a multi-objective optimizer, such as gamultiobj()
But first you should figure out whether that division by (z-z0)^(beta/2) is component-by-component division, or if it is algebraic matrix division. If it is algebraic division, you need to clarify whether z is defined as being a row vector or a column vector, as the MATLAB \ and / operators are going to produce completely different results depending on whether it is row vector or column vector; you should also be considering whether it makes sense to calculate phi_m as the sum times pinv() of the denominator.
See Also
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!