Filter löschen
Filter löschen

INDEX EXCEED NUMBER OF ARAY in GAPSO optimization of simulink model?

2 Ansichten (letzte 30 Tage)
Dawit Kefale
Dawit Kefale am 1 Jul. 2023
Beantwortet: Samay Sagar am 3 Jul. 2023
Hello there,
I downloaded a GAPSO zip code to tune simulink parameters. but the following problem appeared even if I tried repeatdly
may anyone help me?'.............
  • Index exceeds the number of array elements (100).
  • Error in GAPSO (line 54)
  • gpop=pop(index);
..nvar=18;
% ub=[6.8 265 49 65 400 60 3.5 17 17 5.5 15 70 4.5 30 15 3.8 16.2 14.2]; %Upper Bound
% lb=[2.5 255 42 40 300 40 1.5 10 12 2.5 11 55 0 18 5 0 8 5]; %Lower Bound
lb.v=-5;
ub.v=5;
popsize=100;
maxiter=500;
pc=0.9;
ncross=2*round((popsize*pc)/2);
pm=1-pc;
nmut=round(popsize*pm);
W=1;
C1=2;
C2=2;
W_RF=0.97;
%% initial population algorithm
tic
emp.Obj=[];
emp.PObj=[];
emp.v=[];
pop=repmat(emp,popsize,1);
for i=1:popsize
pop(i).Obj=lb.var+rand(1,nvar).*(ub.var-lb.var);
pop(i).PObj= STSMC_Parameters(pop(i).Obj);
pop(i).v=0;
end
[value,index]=min([pop.PObj]);
gpop=pop(index); %$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Line 54
bpop=pop;
%% main loop algorithm
BEST=zeros(maxiter,1);
MEAN = zeros(maxiter,1);
for iter=1:maxiter
% PSO
PSOpop=PSOfunc(pop,bpop,W,C1,C2,nvar,lb,ub);
% crossover
crosspop=repmat(emp,ncross,1);
crosspop=crossover(crosspop,pop,ncross);
% mutation
mutpop=repmat(emp,nmut,1);
mutpop=mutation(mutpop,pop,nvar,nmut,popsize,lb,ub);
[pop]=[pop;PSOpop;crosspop;mutpop];
[value,index]=sort([pop.PObj]);
pop=pop(index);
gpop=pop(1);
pop=pop(1:popsize);
BEST(iter)=gpop.PObj;
MEAN(iter)=mean([pop.PObj]);
disp([' Iter = ', num2str(iter) ' BEST = ' ,num2str(BEST(iter))])
W=W*W_RF;
end
%% results algorithm
disp([ ' Best Solution = ' num2str(gpop.Obj)])
disp([ ' Best Fitness = ' num2str(gpop.PObj)])
disp([ ' MEAN = ' num2str(mean([pop.PObj]))])
disp([ ' Time = ' num2str(toc)])
figure(1)
plot(BEST(1:iter),'r','LineWidth',1.25);
hold on
plot(MEAN(1:iter),'b-.','LineWidth',1.25);
xlabel('iteration')
ylabel(' best solution')
legend(' BEST, PSO&GA' , 'MEAN, PSO&GA')
%title('PSO&GA')
%plot(BEST,'r')
%xlabel('Iteration')
%ylabel('Fitness')
%egend('BEST')
%title('GAPSO')

Antworten (1)

Samay Sagar
Samay Sagar am 3 Jul. 2023
The error message suggests that the class names for your SVM classification are not found in the input labels. In your code, you are using the fitcsvm function with the 'ClassNames' parameter set to [1, 2], which implies that your class labels should be 1 and 2.However, it seems that your trainClusters variable contains cluster indices rather than class labels. To resolve this issue, you can convert the cluster indices to class labels before fitting the SVM model.

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by