Hate_Speech_IMAYFLY_and_HOR.../imayfly_process.m
2022-07-14 12:57:48 +05:30

135 lines
3.7 KiB
Matlab

function [conver_result,Final_result,all_result]=imayfly_process(datapass,pop_size,no_of_iter)
traindata=datapass{1};
traindata_matrix=cell2mat(traindata);
len_data=max(max(traindata_matrix));
max_val1=1;
min_val1=0;
dim=len_data;
max_range=[repmat(max_val1,[1 dim])];
min_range=[repmat(min_val1,[1 dim])];
len=length(max_range);
int_pos_data=init_pop_data(pop_size,len,max_range,min_range);
data_pass_to{1}=[];
for indr=1:pop_size
dataele=(int_pos_data(indr,:));
dataele=limit_chk_process(dataele,...
max_val1,min_val1,data_pass_to);
elechoose=dataele;
obj_result=objective_process(datapass,elechoose);
int_pos_data(indr,:)=dataele;
fitness(indr)=obj_result{1};
finalall{indr}=obj_result;
end
[maxval,maxloc]=max(fitness);
bestdata=int_pos_data(maxloc(1),:);
bestfit=maxval;
xg=bestdata;
gbestdata=int_pos_data(maxloc(1),:);
gbestfit=maxval;
xhi=gbestdata;
[rr,cc]=size(int_pos_data);
initvel=ones(rr,cc)*0.01;
iter_inc=1;% Loop counter
% Main loop
data_pass_to{1}=0;
while iter_inc<=no_of_iter
gdata=linspace(1,0.1,pop_size);
for kpop=1:pop_size
xit=int_pos_data(kpop,:);
if(fitness(kpop)>gbestfit)
a1=rand;a2=rand;betaval=rand;
rpdata=norm(bestdata-int_pos_data(kpop,:),2);
rgdata=norm(gbestdata-int_pos_data(kpop,:),2);
f1=gdata(kpop)*initvel(kpop,:);
f2=a1*exp(-betaval/rpdata)*(xhi-xit);
f3=a2*exp(-betaval/rgdata)*(xg-xit);
newvel=f1+f2+f3;
else
dval=rand;rval=randn;
newvel=gdata(kpop)*initvel(kpop,:)+dval*rval;
end
initvel(kpop,:)=newvel;
end
int_pos_data=int_pos_data+initvel;
%Male
for indr=1:pop_size
dataele=(int_pos_data(indr,:));
dataele=limit_chk_process(dataele,...
max_val1,min_val1,data_pass_to);
elechoose=dataele;
obj_result=objective_process(datapass,elechoose);
int_pos_data1(indr,:)=dataele;
fitnessl(indr)=obj_result{1};
finalall{indr}=obj_result;
end
for kpop=1:pop_size
xit=int_pos_data(kpop,:);
yit=int_pos_data1(kpop,:);
if(fitness(kpop)<fitnessl(kpop))
a3=rand;betaval=rand;
rmfdata=norm(xit-yit,2);
f1=gdata(kpop)*initvel(kpop,:);
f3=a3*exp(-betaval/rmfdata)*(xit-yit);
newvel=f1+f3;
else
flval=rand;r2val=randn;
newvel=gdata(kpop)*initvel(kpop,:)+flval*r2val;
end
initvel(kpop,:)=newvel;
end
int_pos_data1=int_pos_data1+initvel;
L=rand;
int_pos_data11=L*int_pos_data1+(1-L)*int_pos_data;
%Female
for indr=1:pop_size
dataele=(int_pos_data11(indr,:));
dataele=limit_chk_process(dataele,...
max_val1,min_val1,data_pass_to);
elechoose=dataele;
if(iter_inc==no_of_iter && indr==pop_size)
datapass{21}=1;
else
datapass{21}=0;
end
obj_result=objective_process(datapass,elechoose);
int_pos_data11(indr,:)=dataele;
fitnessl1(indr)=obj_result{1};
finalall{indr}=obj_result;
end
[maxval,maxloc]=max(fitnessl1);
bestdata=int_pos_data11(maxloc(1),:);
bestdatafinal=finalall{maxloc(1)};
xg=bestdata;
[best_conver_data(iter_inc),best_location(iter_inc)]=max(fitnessl1);
final_data{iter_inc}=bestdata;
final_alldata{iter_inc}=bestdatafinal;
if iter_inc>=2 && best_conver_data(iter_inc)<best_conver_data(iter_inc-1)
best_conver_data(iter_inc)=best_conver_data(iter_inc-1);
final_data{iter_inc}=final_data{iter_inc-1};
final_alldata{iter_inc}=final_alldata{iter_inc-1};
end
iter_inc=iter_inc+1;
end
conver_result=best_conver_data;
Final_result=final_data{end};
all_result=final_alldata{end};