How to solve this error when using PSOGWO to optimize an objective function?

1 visualización (últimos 30 días)
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);
>>

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Feb. de 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 comentarios
M.Shaarawy
M.Shaarawy el 19 de Feb. de 2019
Hi Walter Rober,
I agree with you so what is the error here knowing that the objective function
phi=phid+lamda*phim
where :phi.jpg
phid.jpg
phim.jpg
The nemonator in phim is defined in the code above, and z is vector of length 1*4 and z0=0
and beta=2, so where is the error.....
Knowing that the error comes from phim..?
Walter Roberson
Walter Roberson el 19 de Feb. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by