⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ga_weights.m

📁 遗传算法matlab实现
💻 M
字号:
function weights = ga_weights(numSVM,MODELS,Xdev,labels)Ntest = size(Xdev,1);group=zeros(100,numSVM);% 100 for the size of group. 400 for the coding lengthfit=zeros(1,100)+0.2;for i=1:100    group(i,:)=round(rand(1,numSVM));endN=200;% iterationsgrp=zeros(N,numSVM); % save the best invidual of each iterationfit_optimal=zeros(1,N);generation=0;while generation<N        generation=generation+1;%Search for the optimal individual.     [best,index]=max(fit);%Compute the selection probability with the fitness of each individual.     p_s=fit/sum(fit);%select mating pool     parent=select_parent(p_s);%For the selected mating pool apply the crossover operation,temperate group is n_group     n_group=crossover(group,parent,0.8,numSVM);%For the temperate group, apply the mutation operation, N-1 new group is n_group.     n_group=mutation(n_group,0.005,numSVM);         %Put maximize individual into new generation, and form the fininal new generation group.     n_group(100,:)=group(index,:);     group=n_group;     fit=zeros(1,100);     p_s=zeros(1,100);     for g=1:100 % use the truenum on test set as fitness value                  Woutput=zeros(Ntest,1);                               for k=1:numSVM %for each svm                              Woutput = Woutput + group(g,k)*simlssvm(MODELS{k},Xdev);                          end                  for i=1:Ntest                          if Woutput(i)*labels(i) > 0                 fit(g) = fit(g)+1;             end                      end                   end          fit = fit/Ntest;          [best,index]=max(fit);     iteration=generation        grp(generation,:)=n_group(index,:);     result=[best,index]        fit_optimal(generation)=best;           endsave grp grp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -