How to solve this error when using PSOGWO to optimize an objective function?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2019년 2월 19일
(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.)
답변 (1개)
Walter Roberson
2019년 2월 19일
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
Walter Roberson
2019년 2월 19일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!