【特征选择】基于二元多邻域人工蜂群 (BMNABC) 特征选择问题(Matlab代码实现)
创始人
2024-02-06 12:24:23
0

 👨‍🎓个人主页:研学社的博客 

💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

💥1 概述

特征选择(特征子集选择)问题是各个领域重要的预处理阶段之一。在真实的数据集中,存在许多不相关、误导性和冗余的特征,这些特征是无用的。主要特征可以通过特征选择技术提取。特征选择属于 NP 难题类;因此,元启发式算法对于解决问题很有用。引入一种新的二元ABC称为二元多邻域人工蜂群(BMNABC),以增强ABC阶段的勘探和开发能力。BMNABC 在第一阶段和第二阶段使用新的概率函数应用近邻域和远邻域信息。在第三阶段,对那些在前一阶段没有改进的解决方案进行了比标准ABC更有针对性的搜索。该算法可以与包装器方法结合使用,以获得最佳结果。

📚2 运行结果

 部分代码:

function [BestChart,Error,BestFitness,BestPosition]= BMNABC(FoodNumber,maxCycle,D,fobj,Limit)
global SzW
rand('state',sum(100*clock)) %#ok
%reset trial counters
trial=zeros(1,FoodNumber);
rmin=0;rmax=1;
Vmax=6;
BestChart=[];

%%
%/FoodNumber:The number of food sources equals the half of the colony size*/
Foods=initialization(FoodNumber,D,1,0)>0.5;

for i=1:FoodNumber
    ObjVal(i) =feval(fobj,Foods(i,:));
end

BestInd=find(ObjVal==min(ObjVal));
BestInd=BestInd(end);
BestFitness=ObjVal(BestInd);
BestPosition=Foods(BestInd,:);
x=BestPosition;
Acc=(SzW*sum(x)/length(x)-BestFitness)/(1-SzW)+1; % This relation is computed based on FitnessValue=(1-SzW)*(1-cp.CorrectRate)+SzW*sum(x)/(length(x));
% The feature subset is based on two criteria: the maximum classi?cation accuracy (minimum error rate) and the minimal number of selected features. 
%Fitness = a* ClassificationError+ (1-a) NumberOfSelectedFeatures/TotalFeatures

 
Error=1-Acc;
BestChart=[BestChart,Error];
fprintf('Iteration:%3d\tAccuracy:%7.4f\tFitness:%7.4f\t#Selected Features:%d\n',1,((1-Error)*100),BestFitness,(sum(BestPosition,2)));

gindex=BestInd;

pbest=Foods;
pbestval=ObjVal;
iter=2;
while ((iter <=maxCycle)),   
    r= rmax-iter*(rmax-rmin)/maxCycle;
    
    %%
    %%%%%%%%% EMPLOYED BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    for i=1:(FoodNumber)
        neigh=[]; d=[]; dd=[];
        w=0;
        for k=1:FoodNumber
            if k~=i
                w=w+1;
                d(w)=sum(Foods(i,:)~=Foods(k,:)); %Hamming distance.
                dd(w)=k;
            end
        end
        Meand=mean(d);
        Maxd=max(d);
        u=1;
        for z=1:w
            
            if (d(z)<=Maxd && d(z)>=r*Meand)
                
                neigh(u)=dd(z);
                u=u+1;
            end
        end
        
        
        
        fi=rand(length(neigh),D);
        
        FIP=sum(fi.*pbest(neigh,:))./sum(length(neigh));
        sol=Foods(i,:);
        
        V(i,:)=rand(1,D).*(Foods(i,:)-FIP);
        V(i,:)=max(min(V(i,:),Vmax),-Vmax);
        aa=abs(tanh(V(i,:)));
        
        AA=1-exp(-trial(i)/(iter*maxCycle));
        S=AA+aa;
        
        temp=rand(1,D)         moving=find(temp==1);
        
        sol(moving)=~sol(moving);
        
        
        ObjValSol=feval(fobj,sol);
        
        if (ObjValSol             pbest(i,:)=sol;
            pbestval(i)=ObjValSol;
        end
        
        if (ObjValSol             Foods(i,:)=sol;
            ObjVal(i)=ObjValSol;
            trial(i)=0;
        else
            trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
        end;
        
        
    end;
    
    %%
    %%%%%%%%%%%%%%%%%%%%%%%% ONLOOKER BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    i=0;
    
    while(i         i=i+1;
        
        neigh=[]; d=[];dd=[];
        w=0;
        for k=1:FoodNumber
            if k~=i
                w=w+1;
                d(w)=sum(Foods(i,:)~=Foods(k,:));
                dd(w)=k;
            end
        end
        Meand=mean(d);
        u=1;
        for z=1:w
            
            if (d(z)<=Meand)
                neigh(u)=dd(z);
                u=u+1;
            end
        end
        
        
        [tmp,tmpid]=min(ObjVal(neigh));
        
        nn=neigh(tmpid);
        
        sol=Foods(i,:);
        
        
        V(i,:)=rand(1,D).*(Foods(i,:)-Foods(nn,:));
        V(i,:)=max(min(V(i,:),Vmax),-Vmax);
        aa=abs(tanh(V(i,:)));
        
        
        AA=1-exp(-trial(i)/(iter*maxCycle));
        S=AA+aa;
        
        temp=rand(1,D)         moving=find(temp==1);
        
        sol(moving)=~sol(moving);
        
        
        ObjValSol=feval(fobj,sol);
        
        if (ObjValSol             pbest(i,:)=sol;
            pbestval(i)=ObjValSol;
        end
        % /*a greedy selection is applied between the current solution i and its mutant*/
        if (ObjValSol             Foods(i,:)=sol;
            ObjVal(i)=ObjValSol;
            trial(i)=0;
        else
            trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
        end;
        
        
    end
   %% 
    %/*The best food source is memorized*/
    
    ind=find(ObjVal==min(ObjVal));
    ind=ind(end);
    if (ObjVal(ind)         
        BestFitness=ObjVal(ind);
        BestPosition=Foods(ind,:);
        x=BestPosition;
        Acc=(SzW*sum(x)/length(x)-BestFitness)/(1-SzW)+1;
        Error=1-Acc;
        gindex=ind;
        success=1;
    else
        success=0;
    end;
    
   %% 
    %%%%%%%%%%%% SCOUT BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %/*determine the food sources whose trial counter exceeds the "Limit" value.
    %In Basic ABC, only one scout is allowed to occur in each cycle*/
    
    ind=find(trial==max(trial));
    ind=ind(end);
    if (trial(ind)>Limit)
        
        sol=Foods(ind,:);
        b=randi([1 FoodNumber]);
        while ((b==ind)|| (b==gindex))
            b=randi([1 FoodNumber]);
        end
        
        
        if (success==1)
            sol=or(Foods(ind,:),BestPosition) ;
        else
            sol= or (xor(Foods(ind,:),BestPosition) ,or(Foods(ind,:),Foods(b,:)));
        end
        
        ObjValSol=feval(fobj,sol);
        
        if (ObjValSol             pbest(ind,:)=sol;
            pbestval(ind)=ObjValSol;
        end
        if (ObjValSol             Foods(ind,:)=sol;
            ObjVal(ind)=ObjValSol;
            trial(ind)=0;
        else
            trial(ind)=trial(ind)+1; %/*if the solution i can not be improved, increase its trial counter*/
        end;
    end
    
    BestChart=[BestChart,Error];
    fprintf('Iteration:%3d\tAccuracy:%7.4f\tFitness:%7.4f\t#Selected Features:%d\n',iter,((1-Error)*100),BestFitness,(sum(BestPosition,2)));
    
    iter=iter+1;
end

🎉3 参考文献

部分理论来源于网络,如有侵权请联系删除。

Zahra Beheshti(2018), BMNABC: Binary Multi-Neighborhood Artificial Bee Colony for High-Dimensional Discrete  Optimization Problems, Cybernetics and Systems 49 (7-8), 452-474.
 

🌈4 Matlab代码实现

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...
美团联名卡审核成功待激活(美团... 今天百科达人给各位分享美团联名卡审核成功待激活的知识,其中也会对美团联名卡审核未通过进行解释,如果能...