plz explain error IN PSO CODE

8 Ansichten (letzte 30 Tage)
jasleen kaur
jasleen kaur am 16 Feb. 2018
Bearbeitet: Walter Roberson am 17 Feb. 2018
Undefined operator '<' for input arguments of type 'struct'.
Error in TrainAnfisUsingPSO>RunPSO (line 103)
if particle(i).Best.Cost<BestSol.Cost
CODE IS HERE:
empty_particle.Position=[];
empty_particle.Cost=[];
empty_particle.Velocity=[];
empty_particle.Best.Position=[];
empty_particle.Best.Cost=[];
particle=repmat(empty_particle,nPop,1);
BestSol.Cost=inf;
for i=1:nPop
% Initialize Position
if i>1
particle(i).Position=unifrnd(VarMin,VarMax,VarSize);
else
particle(i).Position=ones(VarSize);
end
% Initialize Velocity
particle(i).Velocity=zeros(VarSize);
% Evaluation
particle(i).Cost=CostFunction(particle(i).Position);
% Update Personal Best
particle(i).Best.Position=particle(i).Position;
particle(i).Best.Cost=particle(i).Cost;
% Update Global Best
var1=particle(i).Best.Cost;
var2=BestSol.Cost;
if particle(i).Best.Cost<BestSol.Cost %this line
BestSol=particle(i).Best;
end
end
  3 Kommentare
jasleen kaur
jasleen kaur am 17 Feb. 2018
Bearbeitet: Walter Roberson am 17 Feb. 2018
Problem.CostFunction=@(x) TrainFISCost(x,fis,data);
CostFunction calls the following function:
function out=TrainFISCost(x,fis,data)
MinAbs=1e-5;
if any(abs(x)<MinAbs)
S=(abs(x)<MinAbs);
x(S)=MinAbs.*sign(x(S));
end
p0=GetFISParams(fis);
p=x.*p0;
fis=SetFISParams(fis,p);
x=[24,31,1,7,80,3,1,11.4285714300000,4,1.75000000000000;
40,143,3,7,80,3,1,11.4285714300000,4,1.75000000000000;
3194,1469,0,15,121,4,2,8.06666666700000,6,2.50000000000000;
355,444,1,11,79,1,1,7.18181818200000,2,5.50000000000000;
4622,1102,0,10,89,2,1,8.90000000000000,3,3.33333333300000;
2062,1531,0,11,92,3,1,8.36363636400000,4,2.75000000000000;
10,19,1,18,120,1,2,6.66666666700000,3,6;
6724,2645,0,13,104,3,1,8,4,3.25000000000000;
316,159,0,8,91,5,1,11.3750000000000,6,1.33333333300000;
1177,372,0,15,114,3,1,7.60000000000000,4,3.75000000000000;
48,95,1,7,80,3,1,11.4285714300000,4,1.75000000000000;
90,570,6,8,58,0,1,7.25000000000000,1,8;
5,5000,0,5,60,1,1,12,2,2.50000000000000;
58,5,0,5,84,1,2,16.8000000000000,3,1.66666666700000;
58,5,0,5,83,1,2,16.6000000000000,3,1.66666666700000;
117,263,2,7,80,3,1,11.4285714300000,4,1.75000000000000;
97,127,1,16,120,4,0,7.50000000000000,4,4;
43,459,10,13,91,1,1,7,2,6.50000000000000;
36374,3210,0,11,88,3,1,8,4,2.75000000000000;
3091,979,0,13,90,2,1,6.92307692300000,3,4.33333333300000] ;
t=[
1,1,0,0,0,0,0,0,1,0,1,0,1,1,0,1,0,0,0,0;
];
y=evalfis(x,fis,100);
e=t-y;
%MSE=mean(e(:).^2);
%RMSE=sqrt(MSE);
%z=RMSE;
out.fis=fis;
% out.y=y;
%out.e=e;
%out.MSE=MSE;
%out.RMSE=RMSE;
end
jasleen kaur
jasleen kaur am 17 Feb. 2018
Ok I got the error!! Thank you sir for pointing it out!! :)

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by