├── README.md ├── Fitness_func.m └── ensemble_PSO.m /README.md: -------------------------------------------------------------------------------- 1 | # Pso-based-weighted-ensemble 2 | This is the Matlab implementation of "Elham Ghazizadeh, Bahareh Nikpour, Hossein Nezamabadi-pour and Dariush Abbasi-Moghadam, ” A PSO-based Weighting Method to Enhance Machine Learning Techniques for Cooperative Spectrum Sensing in CR Networks”, The 1st Conference on Swarm Intelligence and Evolutionary Computation (CSIEC2016), IEEE, 2016." 3 | -------------------------------------------------------------------------------- /Fitness_func.m: -------------------------------------------------------------------------------- 1 | function [fitness]=Fitness_func(PredClass_SVM,PredClass_KNN,PredClass_NB,N,dim,testdata,testLabels,population) 2 | 3 | for i=1:N 4 | for j=1:size(testLabels,1) 5 | 6 | if PredClass_SVM(j)==PredClass_KNN(j) 7 | if population(i,1)+population(i,2)>population(i,3) 8 | particle_lable(j,1)=PredClass_KNN(j); 9 | else 10 | particle_lable(j,1)=PredClass_NB(j); 11 | end 12 | elseif PredClass_SVM(j)==PredClass_NB(j) 13 | if population(i,2)+population(i,3)>population(i,1) 14 | particle_lable(j,1)=PredClass_SVM(j); 15 | else 16 | particle_lable(j,1)=PredClass_KNN(j); 17 | end 18 | elseif PredClass_KNN(j)==PredClass_NB(j) 19 | if population(i,1)+population(i,3)>population(i,2) 20 | particle_lable(j,1)=PredClass_KNN(j); 21 | else 22 | particle_lable(j,1)=PredClass_SVM(j); 23 | end 24 | % else 25 | % particle_lable(j,1)=PredClass_CF_DT(j); 26 | end 27 | end 28 | fitness(i)=sum(particle_lable == testLabels)/size(testLabels,1 ); 29 | end -------------------------------------------------------------------------------- /ensemble_PSO.m: -------------------------------------------------------------------------------- 1 | function [gbest,gbestFit]=ensemble_PSO(PredClass_SVM,PredClass_KNN,PredClass_NB,traindata,trainLabels) 2 | 3 | N=25; 4 | dim=3; 5 | population=rand(N,dim); 6 | 7 | [fitness]=Fitness_func(PredClass_SVM,PredClass_KNN,PredClass_NB,N,dim,traindata,trainLabels,population); 8 | 9 | pbest=population; 10 | [gbestFit,indx]=max(fitness); 11 | 12 | pbestFit = fitness; 13 | gbest = population(indx , :); 14 | 15 | 16 | t=0; 17 | iteration=50; 18 | vmax = 6; 19 | vmin = -6; 20 | velocity = -6+ rand(size(population))*12; 21 | w=0.7298; 22 | c1=1.5; 23 | c2=1.5; 24 | 25 | while t=1 || update_population(s,u)<=0 42 | update_population(s,u)=population(s,u); 43 | end 44 | 45 | end 46 | end 47 | 48 | 49 | 50 | population=update_population; 51 | 52 | [fitness]=Fitness_func(PredClass_SVM,PredClass_KNN,PredClass_NB,N,dim,traindata,trainLabels,population); 53 | 54 | for m=1:N 55 | if pbestFit(1,m) < fitness(1,m) 56 | 57 | pbestFit(1,m)=fitness(1,m); 58 | pbest(m,:)=population(m,:); 59 | 60 | end 61 | end 62 | 63 | [update_gbestFit,update_indx]=max(fitness); 64 | 65 | if gbestFit < update_gbestFit 66 | gbestFit = update_gbestFit; 67 | 68 | indx = update_indx; 69 | gbest = population(indx , :); 70 | end 71 | 72 | end 73 | --------------------------------------------------------------------------------