├── .DS_Store ├── README.md ├── README └── Awards.jpg ├── 免疫优化算法在物流配送中心选址中的应用 ├── Cross.m ├── IAdata.mat ├── Mutation.m ├── Select.m ├── bestselect.m ├── centre.fig ├── concentration.m ├── draw.m ├── excellence.m ├── figure.fig ├── fitness.m ├── incorporate.m ├── main.m ├── popinit.m ├── similar.m └── test.m ├── 基于PSO工具箱的函数寻优算法 ├── .DS_Store ├── PSOt │ ├── forcecol.m │ ├── forcerow.m │ ├── goplotpso.m │ ├── linear_dyn.m │ ├── normmat.m │ ├── pso_Trelea_vectorized.m │ └── spiral_dyn.m └── testfunctions │ ├── DeJong_f2.m │ ├── DeJong_f3.m │ ├── DeJong_f4.m │ ├── Foxhole.m │ ├── Griewank.m │ ├── NDparabola.m │ ├── Rastrigin.m │ ├── Rosenbrock.m │ ├── ackley.m │ ├── alpine.m │ ├── f6.m │ ├── f6_bubbles_dyn.m │ ├── f6_linear_dyn.m │ ├── f6_spiral_dyn.m │ ├── f6mod.m │ ├── forcecol.m │ ├── forcerow.m │ ├── goplotpso.m │ ├── linear_dyn.m │ ├── main.m │ ├── normmat.m │ ├── pso_Trelea_vectorized.m │ ├── spiral_dyn.m │ ├── test_func.m │ └── tripod.m ├── 基于动态粒子群算法的动态环境寻优算法 ├── DF1function.m ├── fitnessRecord.mat ├── main.m └── result.mat ├── 基于粒子群算法的PID控制器优化设计 ├── GA_run.m ├── PID_Model.mdl ├── PSO.m ├── PSO_PID.m └── 问题解决思路.pdf ├── 基于蚁群算法的三位路径规划算法 ├── CacuFit.m ├── CacuQfz.m ├── HeightData.mat ├── czfz.m ├── data.m ├── data1.m ├── main.m └── searchpath.m ├── 基于遗传算法和非线性规划的函数寻优算法 ├── 案例1 │ ├── Code.m │ ├── Cross.m │ ├── Genetic.m │ ├── Mutation.m │ ├── Select.m │ ├── fun.m │ └── test.m ├── 案例1非线性 │ ├── Code.m │ ├── Cross.m │ ├── Mutation.m │ ├── Select.m │ ├── fun.m │ ├── main.m │ ├── nonlinear.m │ └── test.m ├── 案例2 │ ├── Code.m │ ├── Cross.m │ ├── Genetic.m │ ├── Mutation.m │ ├── Select.m │ ├── fun.m │ └── test.m ├── 案例2非线性 │ ├── Code.m │ ├── Cross.m │ ├── Genetic.m │ ├── Mutation.m │ ├── Select.m │ ├── fun.m │ ├── nonlinear.m │ └── test.m ├── 案例3 │ ├── Code.m │ ├── Cross.m │ ├── Genetic.m │ ├── Mutation.m │ ├── Select.m │ ├── fun.m │ └── test.m └── 案例3非线性 │ ├── Code.m │ ├── Cross.m │ ├── Genetic.m │ ├── Mutation.m │ ├── Select.m │ ├── fun.m │ ├── nonlinear.m │ └── test.m ├── 基于遗传算法的BP神经网络优化算法 ├── R2009a │ ├── Bpfun.m │ ├── GABPMain.m │ ├── Objfun.m │ ├── callbackfun.m │ └── data.mat └── R2014a │ ├── Bpfun.m │ ├── GABPMain.m │ ├── Objfun.m │ ├── callbackfun.m │ └── data.mat ├── 基于遗传算法的LQR控制器优化设计 ├── Active_Suspension_LQR.mdl ├── GA_LQR.m └── GA_LQR_run.m ├── 基于遗传算法的TSP算法 ├── CityPosition1.mat ├── CityPosition2.mat ├── CityPosition3.mat ├── Distanse.m ├── DrawPath.m ├── Fitness.m ├── GA_TSP.m ├── InitPop.m ├── Mutate.m ├── OutputPath.m ├── PathLength.m ├── Recombin.m ├── Reins.m ├── Reverse.m ├── Select.m ├── Sus.m └── dsxy2figxy.m ├── 多种群遗传算法的函数优化算法 ├── EliteInduvidual.m ├── MPGA.m ├── ObjectFunction.m ├── SGA.m └── immigrant.m ├── 支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断 ├── BreastTissue_data.mat ├── libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode] │ ├── COPYRIGHT │ ├── Makefile │ ├── README │ ├── heart_scale.mat │ ├── implement[by faruto] │ │ ├── SVC.m │ │ ├── SVC_test.m │ │ ├── SVMcgForClass.m │ │ ├── SVMcgForRegress.m │ │ ├── SVR.m │ │ ├── SVR_test.m │ │ ├── TutorialForFarutoUltimate3.0.pdf │ │ ├── TutorialTest.m │ │ ├── VF.m │ │ ├── a_template_flow_usingSVM_class.m │ │ ├── a_template_flow_usingSVM_regress.m │ │ ├── fasticaForSVM.m │ │ ├── gaSVMcgForClass.m │ │ ├── gaSVMcgForRegress.m │ │ ├── gaSVMcgpForRegress.m │ │ ├── myprivate │ │ │ ├── gatbx[Sheffield] │ │ │ │ ├── bs2rv.m │ │ │ │ ├── contents.m │ │ │ │ ├── crtbase.m │ │ │ │ ├── crtbp.m │ │ │ │ ├── crtrp.m │ │ │ │ ├── migrate.m │ │ │ │ ├── mpga.m │ │ │ │ ├── mut.m │ │ │ │ ├── mutate.m │ │ │ │ ├── mutbga.m │ │ │ │ ├── ranking.m │ │ │ │ ├── recdis.m │ │ │ │ ├── recint.m │ │ │ │ ├── reclin.m │ │ │ │ ├── recmut.m │ │ │ │ ├── recombin.m │ │ │ │ ├── reins.m │ │ │ │ ├── rep.m │ │ │ │ ├── resplot.m │ │ │ │ ├── rws.m │ │ │ │ ├── scaling.m │ │ │ │ ├── select.m │ │ │ │ ├── sus.m │ │ │ │ ├── xovdp.m │ │ │ │ ├── xovdprs.m │ │ │ │ ├── xovmp.m │ │ │ │ ├── xovsh.m │ │ │ │ ├── xovshrs.m │ │ │ │ ├── xovsp.m │ │ │ │ └── xovsprs.m │ │ │ ├── plotroc.m │ │ │ └── roc.m │ │ ├── pcaForSVM.m │ │ ├── psoSVMcgForClass.m │ │ ├── psoSVMcgForRegress.m │ │ ├── readme[by faruto].txt │ │ ├── scaleForSVM.m │ │ ├── svmplot.m │ │ └── test_for_ica_SVM.m │ ├── libsvm 参数说明.txt │ ├── libsvmread.c │ ├── libsvmread.mexw32 │ ├── libsvmwrite.c │ ├── libsvmwrite.mexw32 │ ├── make.m │ ├── readme[by faruto].txt │ ├── svm.cpp │ ├── svm.h │ ├── svm.obj │ ├── svm_model_matlab.c │ ├── svm_model_matlab.h │ ├── svm_model_matlab.obj │ ├── svmpredict.c │ ├── svmpredict.mexw32 │ ├── svmtrain.c │ ├── svmtrain.mexw32 │ ├── test_data │ │ ├── wine_test.mat │ │ └── x123.mat │ └── 安装说明.txt └── main.m ├── 支持向量机的回归拟合——混凝土抗压强度预测 ├── concrete_data.mat └── main.m ├── 有监督学习神经网络的回归拟合——基于红外光谱的汽油辛烷值预测 ├── main_2009a.m ├── main_2014a.m └── spectra_data.mat ├── 粒子群算法的寻优算法 ├── sample1 │ ├── MexicoHatnew.m │ ├── PSO0.m │ ├── PSO1.m │ ├── PSO2.m │ ├── PSO3.m │ ├── PSO4.m │ ├── fun.m │ ├── main.m │ └── wchange.m ├── sample2-Rastrgrin │ ├── PSO.m │ ├── fun.m │ ├── pso.fig │ ├── pso.mat │ ├── rastrigrin.fig │ └── rastrigrin.m └── sample3-Griewankan │ ├── Griewank.fig │ ├── Griewank.m │ ├── PSO.m │ ├── fun.m │ ├── pso.fig │ └── pso.mat └── 蚁群算法的优化计算——TSP优化 ├── my_first_SA.m └── my_first_SA_run.m /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MATLAB_Algorithm_with_cases 2 | 遗传算法、免疫算法、退火算法、粒子群算法、鱼群算法、蚁群算法和神经网络算法等常用智能算法的MATLAB实现 3 | 4 | # Introduction 5 | 6 | 在数学建模竞赛期间学习的各类智能算法,之前放在CSDN上,标了1积分的辛苦分,但是在下载人数多了以后自动给我涨分,多的甚至高达50分/次,个人感觉不利于建模者学习,故此在将之前的代码改回1积分的同时也转移到Github上。主要包括遗传算法、免疫算法、退火算法、粒子群算法、鱼群算法、蚁群算法和神经网络算法等常用智能算法的MATLAB实现,部分代码有案例,方便对于算法的学习与应用。 7 | 8 | 如果觉得还可以的话就给我颗star吧~ 9 | 10 | 2018年MCM/ICM美赛B题M奖 11 | 12 | ![Awards_1_meitu_1](README/Awards.jpg) 13 | -------------------------------------------------------------------------------- /README/Awards.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/README/Awards.jpg -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/Cross.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/Cross.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/IAdata.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/IAdata.mat -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/Mutation.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/Mutation.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/Select.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/Select.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/bestselect.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/bestselect.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/centre.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/centre.fig -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/concentration.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/concentration.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/draw.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/draw.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/excellence.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/excellence.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/figure.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/figure.fig -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/fitness.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/fitness.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/incorporate.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/incorporate.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/main.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/popinit.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/popinit.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/similar.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/similar.m -------------------------------------------------------------------------------- /免疫优化算法在物流配送中心选址中的应用/test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/免疫优化算法在物流配送中心选址中的应用/test.m -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于PSO工具箱的函数寻优算法/.DS_Store -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/PSOt/forcecol.m: -------------------------------------------------------------------------------- 1 | % forcecol.m 2 | % function to force a vector to be a single column 3 | % 4 | % Brian Birge 5 | % Rev 1.0 6 | % 7/1/98 7 | 8 | function[out]=forcecol(in) 9 | len=prod(size(in)); 10 | out=reshape(in,[len,1]); 11 | -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/PSOt/forcerow.m: -------------------------------------------------------------------------------- 1 | % forcerow.m 2 | % function to force a vector to be a single row 3 | % 4 | % Brian Birge 5 | % Rev 2.0 - vectorized 6 | % 7/1/98 7 | 8 | function[out]=forcerow(in) 9 | len=prod(size(in)); 10 | out=reshape(in,[1,len]); -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/PSOt/goplotpso.m: -------------------------------------------------------------------------------- 1 | % goplotpso.m 2 | % default plotting script used in PSO functions 3 | % 4 | % this script is not a function, 5 | % it is a plugin for the main PSO routine (pso_Trelea_vectorized) 6 | % so it shares all the same variables, be careful with variable names 7 | % when making your own plugin 8 | 9 | % Brian Birge 10 | % Rev 2.0 11 | % 3/1/06 12 | 13 | % setup figure, change this for your own machine 14 | 15 | clf 16 | set(gcf,'Position',[651 31 626 474]); % this is the computer dependent part 17 | %set(gcf,'Position',[743 33 853 492]); 18 | set(gcf,'Doublebuffer','on'); 19 | 20 | % particle plot, upper right 21 | subplot('position',[.7,.6,.27,.32]); 22 | set(gcf,'color','k') 23 | 24 | plot3(pos(:,1),pos(:,D),out,'b.','Markersize',7) 25 | 26 | hold on 27 | plot3(pbest(:,1),pbest(:,D),pbestval,'g.','Markersize',7); 28 | plot3(gbest(1),gbest(D),gbestval,'r.','Markersize',25); 29 | 30 | % crosshairs 31 | offx = max(abs(min(min(pbest(:,1)),min(pos(:,1)))),... 32 | abs(max(max(pbest(:,1)),max(pos(:,1))))); 33 | 34 | offy = max(abs(min(min(pbest(:,D)),min(pos(:,D)))),... 35 | abs(min(max(pbest(:,D)),max(pos(:,D))))); 36 | plot3([gbest(1)-offx;gbest(1)+offx],... 37 | [gbest(D);gbest(D)],... 38 | [gbestval;gbestval],... 39 | 'r-.'); 40 | plot3([gbest(1);gbest(1)],... 41 | [gbest(D)-offy;gbest(D)+offy],... 42 | [gbestval;gbestval],... 43 | 'r-.'); 44 | 45 | hold off 46 | 47 | xlabel('Dimension 1','color','y') 48 | ylabel(['Dimension ',num2str(D)],'color','y') 49 | zlabel('Cost','color','y') 50 | 51 | title('Particle Dynamics','color','w','fontweight','bold') 52 | 53 | set(gca,'Xcolor','y') 54 | set(gca,'Ycolor','y') 55 | set(gca,'Zcolor','y') 56 | set(gca,'color','k') 57 | 58 | % camera control 59 | view(2) 60 | try 61 | axis([gbest(1)-offx,gbest(1)+offx,gbest(D)-offy,gbest(D)+offy]); 62 | catch 63 | axis([VR(1,1),VR(1,2),VR(D,1),VR(D,2)]); 64 | end 65 | 66 | % error plot, left side 67 | subplot('position',[0.1,0.1,.475,.825]); 68 | semilogy(tr(find(~isnan(tr))),'color','m','linewidth',2) 69 | %plot(tr(find(~isnan(tr))),'color','m','linewidth',2) 70 | xlabel('epoch','color','y') 71 | ylabel('gbest val.','color','y') 72 | 73 | if D==1 74 | titstr1=sprintf(['%11.6g = %s( [ %9.6g ] )'],... 75 | gbestval,strrep(functname,'_','\_'),gbest(1)); 76 | elseif D==2 77 | titstr1=sprintf(['%11.6g = %s( [ %9.6g, %9.6g ] )'],... 78 | gbestval,strrep(functname,'_','\_'),gbest(1),gbest(2)); 79 | elseif D==3 80 | titstr1=sprintf(['%11.6g = %s( [ %9.6g, %9.6g, %9.6g ] )'],... 81 | gbestval,strrep(functname,'_','\_'),gbest(1),gbest(2),gbest(3)); 82 | else 83 | titstr1=sprintf(['%11.6g = %s( [ %g inputs ] )'],... 84 | gbestval,strrep(functname,'_','\_'),D); 85 | end 86 | title(titstr1,'color','m','fontweight','bold'); 87 | 88 | grid on 89 | % axis tight 90 | 91 | set(gca,'Xcolor','y') 92 | set(gca,'Ycolor','y') 93 | set(gca,'Zcolor','y') 94 | set(gca,'color','k') 95 | 96 | set(gca,'YMinorGrid','off') 97 | 98 | % text box in lower right 99 | % doing it this way so I can format each line any way I want 100 | subplot('position',[.62,.1,.29,.4]); 101 | clear titstr 102 | if trelea==0 103 | PSOtype = 'Common PSO'; 104 | xtraname = 'Inertia Weight : '; 105 | xtraval = num2str(iwt(length(iwt))); 106 | 107 | elseif trelea==2 | trelea==1 108 | 109 | PSOtype = (['Trelea Type ',num2str(trelea)]); 110 | xtraname = ' '; 111 | xtraval = ' '; 112 | 113 | elseif trelea==3 114 | PSOtype = (['Clerc Type 1"']); 115 | xtraname = '\chi value : '; 116 | xtraval = num2str(chi); 117 | 118 | end 119 | if isnan(errgoal) 120 | errgoalstr='Unconstrained'; 121 | else 122 | errgoalstr=num2str(errgoal); 123 | end 124 | if minmax==1 125 | minmaxstr = ['Maximize to : ']; 126 | elseif minmax==0 127 | minmaxstr = ['Minimize to : ']; 128 | else 129 | minmaxstr = ['Target to : ']; 130 | end 131 | 132 | if rstflg==1 133 | rststat1 = 'Environment Change'; 134 | rststat2 = ' '; 135 | else 136 | rststat1 = ' '; 137 | rststat2 = ' '; 138 | end 139 | 140 | titstr={'PSO Model: ' ,PSOtype;... 141 | 'Dimensions : ' ,num2str(D);... 142 | '# of particles : ',num2str(ps);... 143 | minmaxstr ,errgoalstr;... 144 | 'Function : ' ,strrep(functname,'_','\_');... 145 | xtraname ,xtraval;... 146 | rststat1 ,rststat2}; 147 | 148 | text(.1,1,[titstr{1,1},titstr{1,2}],'color','g','fontweight','bold'); 149 | hold on 150 | text(.1,.9,[titstr{2,1},titstr{2,2}],'color','m'); 151 | text(.1,.8,[titstr{3,1},titstr{3,2}],'color','m'); 152 | text(.1,.7,[titstr{4,1}],'color','w'); 153 | text(.55,.7,[titstr{4,2}],'color','m'); 154 | text(.1,.6,[titstr{5,1},titstr{5,2}],'color','m'); 155 | text(.1,.5,[titstr{6,1},titstr{6,2}],'color','w','fontweight','bold'); 156 | text(.1,.4,[titstr{7,1},titstr{7,2}],'color','r','fontweight','bold'); 157 | 158 | % if we are training a neural net, show a few more parameters 159 | if strcmp('pso_neteval',functname) 160 | % net is passed from trainpso to pso_Trelea_vectorized in case you are 161 | % wondering where that structure comes from 162 | hiddlyrstr = []; 163 | for lyrcnt=1:length(net.layers) 164 | TF{lyrcnt} = net.layers{lyrcnt}.transferFcn; 165 | Sn(lyrcnt) = net.layers{lyrcnt}.dimensions; 166 | hiddlyrstr = [hiddlyrstr,', ',TF{lyrcnt}]; 167 | end 168 | hiddlyrstr = hiddlyrstr(3:end); 169 | 170 | text(0.1,.35,['#neur/lyr = [ ',num2str(net.inputs{1}.size),' ',... 171 | num2str(Sn),' ]'],'color','c','fontweight','normal',... 172 | 'fontsize',10); 173 | text(0.1,.275,['Lyr Fcn: ',hiddlyrstr],... 174 | 'color','c','fontweight','normal','fontsize',9); 175 | 176 | end 177 | 178 | 179 | legstr = {'Green = Personal Bests';... 180 | 'Blue = Current Positions';... 181 | 'Red = Global Best'}; 182 | text(.1,0.025,legstr{1},'color','g'); 183 | text(.1,-.05,legstr{2},'color','b'); 184 | text(.1,-.125,legstr{3},'color','r'); 185 | 186 | hold off 187 | 188 | set(gca,'color','k'); 189 | set(gca,'visible','off'); 190 | 191 | drawnow -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/PSOt/linear_dyn.m: -------------------------------------------------------------------------------- 1 | % linear_dyn.m 2 | % returns an offset that can be added to data that increases linearly with 3 | % time, based on cputime, first time it is called is start time 4 | % 5 | % equation is: offset = (cputime - tnot)*scalefactor 6 | % where tnot = cputime at the first call 7 | % scalefactor = value that slows or speeds up linear movement 8 | % 9 | % usage: [offset] = linear_dyn(scalefactor) 10 | 11 | % Brian Birge 12 | % Rev 1.0 13 | % 8/23/04 14 | 15 | function out = linear_dyn(sf) 16 | % this keeps the same start time for each run of the calling function 17 | % this will reset when any calling prog is re-saved or workspace is 18 | % cleared 19 | persistent tnot 20 | % find starting time 21 | if ~exist('tnot') | length(tnot)==0 22 | tnot = cputime; 23 | end 24 | 25 | out = (cputime-tnot)*sf; 26 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/PSOt/normmat.m: -------------------------------------------------------------------------------- 1 | function [out,varargout]=normmat(x,newminmax,flag) 2 | % normmat.m 3 | % takes a matrix and reformats the data to fit between a new range 4 | % 5 | % Usage: 6 | % [xprime,mins,maxs]=normmat(x,range,method) 7 | % 8 | % Inputs: 9 | % x - matrix to reformat of dimension MxN 10 | % range - a vector or matrix specifying minimum and maximum values for the new matrix 11 | % for method = 0, range is a 2 element row vector of [min,max] 12 | % for method = 1, range is a 2 row matrix with same column size as 13 | % input matrix with format of [min1,min2,...minN; 14 | % max1,max2,...maxM]; 15 | % for method = 2, range is a 2 column matrix with same row size as 16 | % input matrix with format of [min1,max1; 17 | % min2,max2; 18 | % ... , ...; 19 | % minM,maxM]; 20 | % alternatively for method 1 and 2, can input just a 2 element vector as in method 0 21 | % this will just apply the same min/max across each column or row respectively 22 | % method - a scalar flag with the following function 23 | % = 1, normalize each column of the input matrix separately 24 | % = 2, normalize each row of the input matrix separately 25 | % = 0, normalize matrix globally 26 | % Outputs: 27 | % xprime - new matrix normalized per method 28 | % mins,maxs - optional outputs return the min and max vectors of the original matrix x 29 | % used for recovering original matrix from xprime 30 | % 31 | % example: x = [-10,3,0;2,4.1,-7;3.4,1,0.01] 32 | % [xprime,mins,maxs]=normmat(x,[0,10],0) 33 | 34 | % Brian Birge 35 | % Rev 2.1 36 | % 3/16/06 - changed name of function to avoid same name in robust control 37 | % toolbox 38 | %-------------------------------------------------------------------------------------------------------- 39 | if flag==0 40 | 41 | a=min(min((x))); 42 | b=max(max((x))); 43 | if abs(a)>abs(b) 44 | large=a; 45 | small=b; 46 | else 47 | large=b; 48 | small=a; 49 | end 50 | temp=size(newminmax); 51 | if temp(1)~=1 52 | error('Error: for method=0, range vector must be a 2 element row vector'); 53 | end 54 | den=abs(large-small); 55 | range=newminmax(2)-newminmax(1); 56 | if den==0 57 | out=x; 58 | else 59 | z21=(x-a)/(den); 60 | out=z21*range+newminmax(1)*ones(size(z21)); 61 | end 62 | 63 | %-------------------------------------------------------------------------------------------------------- 64 | elseif flag==1 65 | a=min(x,[],1); 66 | b=max(x,[],1); 67 | for i=1:length(b) 68 | if abs(a(i))>abs(b(i)) 69 | large(i)=a(i); 70 | small(i)=b(i); 71 | else 72 | large(i)=b(i); 73 | small(i)=a(i); 74 | end 75 | end 76 | den=abs(large-small); 77 | temp=size(newminmax); 78 | if temp(1)*temp(2)==2 79 | newminmaxA(1,:)=newminmax(1).*ones(size(x(1,:))); 80 | newminmaxA(2,:)=newminmax(2).*ones(size(x(1,:))); 81 | elseif temp(1)>2 82 | error('Error: for method=1, range matrix must have 2 rows and same columns as input matrix'); 83 | else 84 | newminmaxA=newminmax; 85 | end 86 | 87 | range=newminmaxA(2,:)-newminmaxA(1,:); 88 | for j=1:length(x(:,1)) 89 | for i=1:length(b) 90 | if den(i)==0 91 | out(j,i)=x(j,i); 92 | else 93 | z21(j,i)=(x(j,i)-a(i))./(den(i)); 94 | out(j,i)=z21(j,i).*range(1,i)+newminmaxA(1,i); 95 | end 96 | end 97 | end 98 | %-------------------------------------------------------------------------------------------------------- 99 | elseif flag==2 100 | a=min(x,[],2); 101 | b=max(x,[],2); 102 | for i=1:length(b) 103 | if abs(a(i))>abs(b(i)) 104 | large(i)=a(i); 105 | small(i)=b(i); 106 | else 107 | large(i)=b(i); 108 | small(i)=a(i); 109 | end 110 | end 111 | den=abs(large-small); 112 | temp=size(newminmax); 113 | if temp(1)*temp(2)==2 114 | newminmaxA(:,1)=newminmax(1).*ones(size(x(:,1))); 115 | newminmaxA(:,2)=newminmax(2).*ones(size(x(:,1))); 116 | elseif temp(2)>2 117 | error('Error: for method=2, range matrix must have 2 columns and same rows as input matrix'); 118 | else 119 | newminmaxA=newminmax; 120 | end 121 | 122 | range=newminmaxA(:,2)-newminmaxA(:,1); 123 | for j=1:length(x(1,:)) 124 | for i=1:length(b) 125 | if den(i)==0 126 | out(i,j)=x(i,j); 127 | else 128 | z21(i,j)=(x(i,j)-a(i))./([forcecol(den(i))]); 129 | out(i,j)=z21(i,j).*range(i,1)+newminmaxA(i,1); 130 | end 131 | end 132 | end 133 | 134 | end 135 | %-------------------------------------------------------------------------------------------------------- 136 | varargout{1}=a; 137 | varargout{2}=b; 138 | 139 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/PSOt/spiral_dyn.m: -------------------------------------------------------------------------------- 1 | % spiral_dyn.m 2 | % returns x,y position along an archimedean spiral of degree n 3 | % based on cputime, first time it is called is start time 4 | % 5 | % based on: r = a*(theta^n) 6 | % 7 | % usage: [x_cnt,y_cnt] = spiral_dyn(n,a) 8 | % i.e., 9 | % n = 2 (Fermat) 10 | % = 1 (Archimedes) 11 | % = -1 (Hyberbolic) 12 | % = -2 (Lituus) 13 | 14 | % Brian Birge 15 | % Rev 1.1 16 | % 8/23/04 17 | 18 | function [x_cnt,y_cnt] = spiral_dyn(n,a) 19 | % this keeps the same start time for each run of the calling function 20 | % this will reset when any calling prog is re-saved or workspace is 21 | % cleared 22 | persistent tnot iter 23 | % find starting time 24 | if ~exist('tnot') | length(tnot)==0 25 | tnot = cputime; 26 | % iter = 0; 27 | end 28 | %iter = iter+10 ; 29 | 30 | theta = cputime-tnot; 31 | %theta = iter/10000; 32 | 33 | r = a*(theta.^n); 34 | 35 | x_cnt = r*cos(theta); 36 | y_cnt = r*sin(theta); 37 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/DeJong_f2.m: -------------------------------------------------------------------------------- 1 | % DeJong_f2.m 2 | % De Jong's f2 function, also called a Rosenbrock Variant 3 | % This is a 2D only equation 4 | % 5 | % described by Clerc in ... 6 | % http://clerc.maurice.free.fr/pso/Semi-continuous_challenge/Semi-continuous_challenge.htm 7 | % 8 | % used to test optimization/global minimization problems 9 | % in Clerc's "Semi-continuous challenge" 10 | % 11 | % f(x,y) = 100*(x.^2 - y).^2 + (1-x).^2; 12 | % 13 | % input = 2 element row vector containing [x, y] 14 | % each row is processed independently, 15 | % you can feed in matrices of timeXN no prob 16 | % 17 | % example: cost = DeJong_f2([1,2;3,4;5,6]) 18 | % note minimum =0 @ (1,1) 19 | 20 | % Brian Birge 21 | % Rev 1.0 22 | % 9/12/04 23 | function [out]=DeJong_f2(in) 24 | 25 | x= in(:,1); 26 | y= in(:,2); 27 | 28 | out = 100*(x.^2 - y).^2 + (1-x).^2; -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/DeJong_f3.m: -------------------------------------------------------------------------------- 1 | % DeJong_f3.m 2 | % De Jong's f3 function, ND, also called STEP 3 | % from: http://www.cs.rpi.edu/~hornda/pres/node4.html 4 | % 5 | % f(x) = sum( floor(x) ) 6 | % 7 | % x = N element row vector containing [ x0, x1,..., xN ] 8 | % each row is processed independently, 9 | % you can feed in matrices of timeXN no prob 10 | % 11 | % example: cost = DeJong_f3([1,2;3,4;5,6]) 12 | % note minimum @ x= -Inf or whatever lower bound you've chosen 13 | 14 | % Brian Birge 15 | % Rev 1.0 16 | % 9/12/04 17 | 18 | function [out]=DeJong_f3(in) 19 | out = sum( floor(in) , 2); -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/DeJong_f4.m: -------------------------------------------------------------------------------- 1 | % DeJong_f4.m 2 | % De Jong's f4 function, ND, no noise 3 | % 4 | % described by Clerc in ... 5 | % http://clerc.maurice.free.fr/pso/Semi-continuous_challenge/Semi-continuous_challenge.htm 6 | % 7 | % used to test optimization/global minimization problems 8 | % in Clerc's "Semi-continuous challenge" 9 | % 10 | % f(x) = sum( [1:N].*(in.^4), 2) 11 | % 12 | % x = N element row vector containing [ x0, x1,..., xN ] 13 | % each row is processed independently, 14 | % you can feed in matrices of timeXN no prob 15 | % 16 | % example: cost = DeJong_f4([1,2;3,4;5,6]) 17 | % note minimum =0 @ x= all zeros 18 | 19 | % Brian Birge 20 | % Rev 1.0 21 | % 9/12/04 22 | function [out]=DeJong_f4(in) 23 | persistent D tlen d 24 | 25 | % this speeds routine up a lot, if called from PSO these won't change from 26 | % call to call (repmat is a cpu hog) 27 | Dx=length(in(1,:)); 28 | tlenx=length(in(:,1)); 29 | if isempty(D) | D~=Dx | tlen~=tlenx 30 | D=Dx; % dimension of prob 31 | tlen=tlenx; % how many separate states 32 | d=repmat([1:D],tlen,1); % needed to vectorize this 33 | end 34 | out = sum( d.*(in.^4), 2); -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/Foxhole.m: -------------------------------------------------------------------------------- 1 | % Foxhole.m 2 | % Foxhole function, 2D multi-minima function 3 | % 4 | % from: http://www.cs.rpi.edu/~hornda/pres/node10.html 5 | % 6 | % f(x) = 0.002 + sum([1/(j + sum( [x(i) - a(i,j)].^6 ) )]) 7 | % 8 | % x = 2 element row vector containing [ x, y ] 9 | % each row is processed independently, 10 | % you can feed in matrices of timeX2 no prob 11 | % 12 | % example: cost = Foxhole([1,2;3,4]) 13 | % note: known minimum =0 @ (-32,-32) unless you change 'a' in the function 14 | 15 | % Brian Birge 16 | % Rev 1.0 17 | % 9/12/04 18 | function [out]=Foxhole(in) 19 | x=in(:,1); 20 | y=in(:,2); 21 | 22 | % location of foxholes, you can change this, these are what DeJong used 23 | % if you change 'em, a{1} and a{2} must each have same # of elements 24 | a{1} = [... 25 | -32 -16 0 16 32 ;... 26 | -32 -16 0 16 32 ;... 27 | -32 -16 0 16 32 ;... 28 | -32 -16 0 16 32 ;... 29 | -32 -16 0 16 32 ;... 30 | ]; 31 | 32 | a{2} = [... 33 | -32 -32 -32 -32 -32 ;... 34 | -16 -16 -16 -16 -16 ;... 35 | 0 0 0 0 0 ;... 36 | 16 16 16 16 16 ;... 37 | 32 32 32 32 32 ;... 38 | ]; 39 | 40 | term_sum=0; 41 | for j=1:prod(size((a{1}))) 42 | ax=a{1} (j); 43 | ay=a{2} (j); 44 | term_num = (x - ax).^6 + (y - ay).^6; 45 | term_sum=term_sum+ 1./(j+term_num); 46 | end 47 | out = .002 + term_sum; -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/Griewank.m: -------------------------------------------------------------------------------- 1 | % Griewank.m 2 | % Griewank function 3 | % described by Clerc in ... 4 | % http://clerc.maurice.free.fr/pso/Semi-continuous_challenge/Semi-continuous_challenge.htm 5 | % 6 | % used to test optimization/global minimization problems 7 | % in Clerc's "Semi-continuous challenge" 8 | % 9 | % f(x) = sum((x-100).^2,2)./4000 - ... 10 | % prod(cos((x-100)./(sqrt(repmat([1:N],length(x(:,1),1)))),2) ... 11 | % +1 12 | % 13 | % x = N element row vector containing [x0, x1, ..., xN] 14 | % each row is processed independently, 15 | % you can feed in matrices of timeXN no prob 16 | % 17 | % example: cost = Griewank([1,2;5,6;0,-50]) 18 | % note: known minimum =0 @ all x = 100 19 | 20 | % Brian Birge 21 | % Rev 1.0 22 | % 9/12/04 23 | function [out]=Griewank(in) 24 | persistent d D tlen sqrtd 25 | 26 | % this speeds routine up a lot, if called from PSO these won't change from 27 | % call to call 28 | Dx=length(in(1,:)); 29 | tlenx=length(in(:,1)); 30 | if isempty(D) | D~=Dx | tlen~=tlenx 31 | D=Dx; % dimension of prob 32 | tlen=tlenx; % how many separate states 33 | d=repmat([1:D],tlen,1); % needed to vectorize this 34 | sqrtd=sqrt(d); 35 | end 36 | 37 | % just follows from the referenced website/paper 38 | term1 = sum([(in-100).^2],2)./4000; 39 | term2 = prod( (cos( (in-100)./sqrtd )) ,2); 40 | out = term1 - term2 + 1; -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/NDparabola.m: -------------------------------------------------------------------------------- 1 | % NDparabola.m 2 | % ND Parabola function (also called a Sphere function and DeJong's f1), 3 | % described by Clerc... 4 | % http://clerc.maurice.free.fr/pso/Semi-continuous_challenge/Semi-continuous_challenge.htm 5 | % 6 | % used to test optimization/global minimization problems 7 | % in Clerc's "Semi-continuous challenge" 8 | % 9 | % f(x) = sum( x.^2 ) 10 | % 11 | % x = N element row vector containing [x0, x1, ..., xN] 12 | % each row is processed independently, 13 | % you can feed in matrices of timeXN no prob 14 | % 15 | % example: cost = NDparabola([1,2;5,6;0,-50]) 16 | % note: known minimum =0 @ all x = 0 17 | 18 | % Brian Birge 19 | % Rev 1.0 20 | % 9/12/04 21 | 22 | function [out]=NDparabola(in) 23 | out = sum(in.^2, 2); -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/Rastrigin.m: -------------------------------------------------------------------------------- 1 | % Rastrigin.m 2 | % Rastrigin function 3 | % 4 | % used to test optimization/global minimization problems 5 | % 6 | % f(x) = sum([x.^2-10*cos(2*pi*x) + 10], 2); 7 | % 8 | % x = N element row vector containing [x0, x1, ..., xN] 9 | % each row is processed independently, 10 | % you can feed in matrices of timeXN no prob 11 | % 12 | % example: cost = Rastrigin([1,2;5,6;0,-50]) 13 | % note: known minimum =0 @ all x = 0 14 | 15 | % Brian Birge 16 | % Rev 1.0 17 | % 9/12/04 18 | 19 | function [out]=Rastrigin(in) 20 | 21 | cos_in = cos(2*pi*in); 22 | out = sum((in.^2-10*cos_in + 10), 2); -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/Rosenbrock.m: -------------------------------------------------------------------------------- 1 | % Rosenbrock.m 2 | % Rosenbrock function 3 | % 4 | % described by Clerc in ... 5 | % http://clerc.maurice.free.fr/pso/Semi-continuous_challenge/Semi-continuous_challenge.htm 6 | % 7 | % used to test optimization/global minimization problems 8 | % in Clerc's "Semi-continuous challenge" 9 | % 10 | % f(x) = sum([ 100*(x(i+1) - x(i)^2)^2 + (x(i) -1)^2]) 11 | % 12 | % x = N element row vector containing [x0, x1, ..., xN] 13 | % each row is processed independently, 14 | % you can feed in matrices of timeXN no prob 15 | % 16 | % example: cost = Rosenbrock([1,2;5,6;0,-50]) 17 | % note: known minimum =0 @ all x = 1 18 | 19 | % Brian Birge 20 | % Rev 1.0 21 | % 9/12/04 22 | function [out]=Rosenbrock(in) 23 | 24 | x0=in(:,1:end-1); 25 | x1=in(:,2:end); 26 | 27 | out = sum( (100*(x1-x0.^2).^2 + (x0-1).^2) , 2); -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/ackley.m: -------------------------------------------------------------------------------- 1 | % ackley.m 2 | % Ackley's function, from http://www.cs.vu.nl/~gusz/ecbook/slides/16 3 | % and further shown at: 4 | % http://clerc.maurice.free.fr/pso/Semi-continuous_challenge/Semi-continuous_challenge.htm 5 | % 6 | % commonly used to test optimization/global minimization problems 7 | % 8 | % f(x)= [ 20 + e ... 9 | % -20*exp(-0.2*sqrt((1/n)*sum(x.^2,2))) ... 10 | % -exp((1/n)*sum(cos(2*pi*x),2))]; 11 | % 12 | % dimension n = # of columns of input, x1, x2, ..., xn 13 | % each row is processed independently, 14 | % you can feed in matrices of timeXdim no prob 15 | % 16 | % example: cost = ackley([1,2,3;4,5,6]) 17 | 18 | % Brian Birge 19 | % Rev 1.0 20 | % 9/12/04 21 | 22 | function [out]=ackley(in) 23 | 24 | % dimension is # of columns of input, x1, x2, ..., xn 25 | n=length(in(1,:)); 26 | 27 | x=in; 28 | e=exp(1); 29 | 30 | out = (20 + e ... 31 | -20*exp(-0.2*sqrt((1/n).*sum(x.^2,2))) ... 32 | -exp((1/n).*sum(cos(2*pi*x),2))); 33 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/alpine.m: -------------------------------------------------------------------------------- 1 | % alpine.m 2 | % ND Alpine function, described by Clerc... 3 | % http://clerc.maurice.free.fr/pso/Semi-continuous_challenge/Semi-continuous_challenge.htm 4 | % 5 | % used to test optimization/global minimization problems 6 | % in Clerc's "Semi-continuous challenge" 7 | % 8 | % f(x) = sum( abs(x.*sin(x) + 0.1.*x) ) 9 | % 10 | % x = N element row vector containing [x0, x1, ..., xN] 11 | % each row is processed independently, 12 | % you can feed in matrices of timeXN no prob 13 | % 14 | % example: cost = alpine([1,2;5,6;0,-50]) 15 | % note: known minimum =0 @ all x = 0 16 | 17 | % Brian Birge 18 | % Rev 1.0 19 | % 9/12/04 20 | 21 | function [out]=alpine(in) 22 | 23 | out = sum(abs(in.*sin(in) + 0.1.*in),2); -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/f6.m: -------------------------------------------------------------------------------- 1 | % f6.m 2 | % Schaffer's F6 function 3 | % commonly used to test optimization/global minimization problems 4 | % 5 | % z = 0.5+ (sin^2(sqrt(x^2+y^2))-0.5)/((1+0.01*(x^2+y^2))^2) 6 | 7 | function [out]=f6(in) 8 | x=in(:,1); 9 | y=in(:,2); 10 | num=sin(sqrt(x.^2+y.^2)).^2 - 0.5; 11 | den=(1.0+0.01*(x.^2+y.^2)).^2; 12 | 13 | out=0.5 +num./den; 14 | 15 | 16 | -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/f6_bubbles_dyn.m: -------------------------------------------------------------------------------- 1 | % f6_bubbles_dyn.m 2 | % 2 separate Schaffer's F6 functions, one with min at [-8,-8] and the 3 | % other with min at [8,8] 4 | % as time goes on, each bubbles magnitude cycles up and down, 5 | % they are 180 deg out of phase with each other 6 | % 7 | % commonly used to test optimization/global minimization problems 8 | 9 | function [out]=f6_bubbles_dyn(in) 10 | persistent tnot 11 | 12 | % find starting time 13 | if ~exist('tnot') | length(tnot)==0 14 | tnot = cputime; 15 | end 16 | time = cputime/10 - tnot; 17 | 18 | % calculate offset for whole function 19 | %[xc,yc]=spiral_dyn(1,.1); 20 | xc = 0; 21 | yc = xc; 22 | 23 | % parse input 24 | x = in(:,1) +xc; 25 | y = in(:,2) +yc; 26 | 27 | % bubble centers 28 | x1 = -8; 29 | y1 = x1; 30 | x2 = 8; 31 | y2 = x2; 32 | 33 | % f6 #1 (bubble #1) 34 | num = sin(sqrt((x-x1).^2+(y-y1).^2)).^2 - 0.5; 35 | den = (1.0+0.01*((x-x1).^2+(y-y1).^2)).^2; 36 | f6_1 = (0.5 + num./den).*abs(sin(time+pi/2)); 37 | % bubble #1 offset 38 | num_ofs = sin(sqrt((10000-x1).^2+(10000-y1).^2)).^2 - 0.5; 39 | den_ofs = (1.0+0.01*((10000-x1).^2+(10000-y1).^2)).^2; 40 | f6_1_ofs = (0.5 + num_ofs./den_ofs).*abs(sin(time+pi/2)); 41 | 42 | % f6 #2 (bubble #2) 43 | num = sin(sqrt((x-x2).^2+(y-y2).^2)).^2 - 0.5; 44 | den = (1.0+0.01*((x-x2).^2+(y-y2).^2)).^2; 45 | f6_2 = (0.5 + num./den).*abs(sin(time)); 46 | % bubble #2 offset 47 | num_ofs = sin(sqrt((10000-x2).^2+(10000-y2).^2)).^2 - 0.5; 48 | den_ofs = (1.0+0.01*((10000-x2).^2+(10000-y2).^2)).^2; 49 | f6_2_ofs = (0.5 + num_ofs./den_ofs).*abs(sin(time)); 50 | 51 | % output & return 52 | out = 2*((f6_1 + f6_2) - (f6_1_ofs + f6_2_ofs)); 53 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/f6_linear_dyn.m: -------------------------------------------------------------------------------- 1 | % f6_linear_dyn.m 2 | % Schaffer's F6 function 3 | % commonly used to test optimization/global minimization problems 4 | % 5 | % This version moves the minimum linearly along a 45 deg angle in x,y space 6 | 7 | % Brian Birge 8 | % Rev 1.0 9 | % 9/12/04 10 | 11 | function [out]=f6_linear_dyn(in) 12 | % parse input 13 | x = in(:,1); 14 | y = in(:,2); 15 | 16 | % find current minimum based on clock 17 | offset = linear_dyn(.5); % this is in 'hiddenutils' 18 | x_center = offset; 19 | y_center = offset; 20 | 21 | num = sin(sqrt((x-x_center).^2+(y-y_center).^2)).^2 - 0.5; 22 | den = (1.0+0.01*((x-x_center).^2+(y-y_center).^2)).^2; 23 | 24 | out = 0.5 + num./den; 25 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/f6_spiral_dyn.m: -------------------------------------------------------------------------------- 1 | % f6_spiral_dyn.m 2 | % Schaffer's F6 function 3 | % commonly used to test optimization/global minimization problems 4 | % 5 | % This version moves the minimum about a Fermat Spiral 6 | % according to the equation: r = a*(theta^2) 7 | % theta is a function of time and is checked internally (not an input) 8 | % x_center = r*cos(theta) 9 | % y_center = r*sin(theta) 10 | % 11 | % z = 0.5 ... 12 | % +(sin^2(sqrt((x-x_center)^2+(y-y_center)^2))-0.5) ... 13 | % /((1+0.01*((x-x_center)^2+(y-y_center)^2))^2) 14 | 15 | % Brian Birge 16 | % Rev 1.0 17 | % 9/12/04 18 | 19 | function [out]=f6_spiral_dyn(in) 20 | % parse input 21 | x = in(:,1); 22 | y = in(:,2); 23 | 24 | % find current minimum based on clock 25 | [x_center,y_center]=spiral_dyn(1,.1); % this is in 'hiddenutils' 26 | 27 | num = sin(sqrt((x-x_center).^2+(y-y_center).^2)).^2 - 0.5; 28 | den = (1.0+0.01*((x-x_center).^2+(y-y_center).^2)).^2; 29 | 30 | out = 0.5 + num./den; 31 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/f6mod.m: -------------------------------------------------------------------------------- 1 | % f6mod.m 2 | % Schaffer's F6 function 3 | % commonly used to test optimization/global minimization problems 4 | % 5 | % This version is a modified form, just the sum of 5 f6 functions with 6 | % different centers to look at local minimum issues 7 | % normal f6= 8 | % z = 0.5+ (sin^2(sqrt(x^2+y^2))-0.5)/((1+0.01*(x^2+y^2))^2) 9 | 10 | function [out]=f6mod(in) 11 | x=in(:,1); 12 | y=in(:,2); 13 | a=ones(size(x)); 14 | b=20; 15 | 16 | xycntr=[0*a,0*a,-b*a,-b*a,-b*a,b*a,b*a,-b*a,b*a,b*a]; 17 | tmpout=0.*a; 18 | 19 | for i=1:5 20 | num=sin(sqrt( (x-xycntr(:,2*i-1)).^2 + (y-xycntr(:,2*i)).^2) ).^2 - 0.5; 21 | den=(1.0+0.01*((x-xycntr(:,2*i-1)).^2+(y-xycntr(:,2*i)).^2)).^2; 22 | tmpout=[tmpout, 0.5*a +num./den]; 23 | end 24 | 25 | out=sum(tmpout,2)./5; 26 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/forcecol.m: -------------------------------------------------------------------------------- 1 | % forcecol.m 2 | % function to force a vector to be a single column 3 | % 4 | % Brian Birge 5 | % Rev 1.0 6 | % 7/1/98 7 | 8 | function[out]=forcecol(in) 9 | len=prod(size(in)); 10 | out=reshape(in,[len,1]); 11 | -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/forcerow.m: -------------------------------------------------------------------------------- 1 | % forcerow.m 2 | % function to force a vector to be a single row 3 | % 4 | % Brian Birge 5 | % Rev 2.0 - vectorized 6 | % 7/1/98 7 | 8 | function[out]=forcerow(in) 9 | len=prod(size(in)); 10 | out=reshape(in,[1,len]); -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/goplotpso.m: -------------------------------------------------------------------------------- 1 | % goplotpso.m 2 | % default plotting script used in PSO functions 3 | % 4 | % this script is not a function, 5 | % it is a plugin for the main PSO routine (pso_Trelea_vectorized) 6 | % so it shares all the same variables, be careful with variable names 7 | % when making your own plugin 8 | 9 | % Brian Birge 10 | % Rev 2.0 11 | % 3/1/06 12 | 13 | % setup figure, change this for your own machine 14 | 15 | clf 16 | set(gcf,'Position',[651 31 626 474]); % this is the computer dependent part 17 | %set(gcf,'Position',[743 33 853 492]); 18 | set(gcf,'Doublebuffer','on'); 19 | 20 | % particle plot, upper right 21 | subplot('position',[.7,.6,.27,.32]); 22 | set(gcf,'color','k') 23 | 24 | plot3(pos(:,1),pos(:,D),out,'b.','Markersize',7) 25 | 26 | hold on 27 | plot3(pbest(:,1),pbest(:,D),pbestval,'g.','Markersize',7); 28 | plot3(gbest(1),gbest(D),gbestval,'r.','Markersize',25); 29 | 30 | % crosshairs 31 | offx = max(abs(min(min(pbest(:,1)),min(pos(:,1)))),... 32 | abs(max(max(pbest(:,1)),max(pos(:,1))))); 33 | 34 | offy = max(abs(min(min(pbest(:,D)),min(pos(:,D)))),... 35 | abs(min(max(pbest(:,D)),max(pos(:,D))))); 36 | plot3([gbest(1)-offx;gbest(1)+offx],... 37 | [gbest(D);gbest(D)],... 38 | [gbestval;gbestval],... 39 | 'r-.'); 40 | plot3([gbest(1);gbest(1)],... 41 | [gbest(D)-offy;gbest(D)+offy],... 42 | [gbestval;gbestval],... 43 | 'r-.'); 44 | 45 | hold off 46 | 47 | xlabel('Dimension 1','color','y') 48 | ylabel(['Dimension ',num2str(D)],'color','y') 49 | zlabel('Cost','color','y') 50 | 51 | title('Particle Dynamics','color','w','fontweight','bold') 52 | 53 | set(gca,'Xcolor','y') 54 | set(gca,'Ycolor','y') 55 | set(gca,'Zcolor','y') 56 | set(gca,'color','k') 57 | 58 | % camera control 59 | view(2) 60 | try 61 | axis([gbest(1)-offx,gbest(1)+offx,gbest(D)-offy,gbest(D)+offy]); 62 | catch 63 | axis([VR(1,1),VR(1,2),VR(D,1),VR(D,2)]); 64 | end 65 | 66 | % error plot, left side 67 | subplot('position',[0.1,0.1,.475,.825]); 68 | semilogy(tr(find(~isnan(tr))),'color','m','linewidth',2) 69 | %plot(tr(find(~isnan(tr))),'color','m','linewidth',2) 70 | xlabel('epoch','color','y') 71 | ylabel('gbest val.','color','y') 72 | 73 | if D==1 74 | titstr1=sprintf(['%11.6g = %s( [ %9.6g ] )'],... 75 | gbestval,strrep(functname,'_','\_'),gbest(1)); 76 | elseif D==2 77 | titstr1=sprintf(['%11.6g = %s( [ %9.6g, %9.6g ] )'],... 78 | gbestval,strrep(functname,'_','\_'),gbest(1),gbest(2)); 79 | elseif D==3 80 | titstr1=sprintf(['%11.6g = %s( [ %9.6g, %9.6g, %9.6g ] )'],... 81 | gbestval,strrep(functname,'_','\_'),gbest(1),gbest(2),gbest(3)); 82 | else 83 | titstr1=sprintf(['%11.6g = %s( [ %g inputs ] )'],... 84 | gbestval,strrep(functname,'_','\_'),D); 85 | end 86 | title(titstr1,'color','m','fontweight','bold'); 87 | 88 | grid on 89 | % axis tight 90 | 91 | set(gca,'Xcolor','y') 92 | set(gca,'Ycolor','y') 93 | set(gca,'Zcolor','y') 94 | set(gca,'color','k') 95 | 96 | set(gca,'YMinorGrid','off') 97 | 98 | % text box in lower right 99 | % doing it this way so I can format each line any way I want 100 | subplot('position',[.62,.1,.29,.4]); 101 | clear titstr 102 | if trelea==0 103 | PSOtype = 'Common PSO'; 104 | xtraname = 'Inertia Weight : '; 105 | xtraval = num2str(iwt(length(iwt))); 106 | 107 | elseif trelea==2 | trelea==1 108 | 109 | PSOtype = (['Trelea Type ',num2str(trelea)]); 110 | xtraname = ' '; 111 | xtraval = ' '; 112 | 113 | elseif trelea==3 114 | PSOtype = (['Clerc Type 1"']); 115 | xtraname = '\chi value : '; 116 | xtraval = num2str(chi); 117 | 118 | end 119 | if isnan(errgoal) 120 | errgoalstr='Unconstrained'; 121 | else 122 | errgoalstr=num2str(errgoal); 123 | end 124 | if minmax==1 125 | minmaxstr = ['Maximize to : ']; 126 | elseif minmax==0 127 | minmaxstr = ['Minimize to : ']; 128 | else 129 | minmaxstr = ['Target to : ']; 130 | end 131 | 132 | if rstflg==1 133 | rststat1 = 'Environment Change'; 134 | rststat2 = ' '; 135 | else 136 | rststat1 = ' '; 137 | rststat2 = ' '; 138 | end 139 | 140 | titstr={'PSO Model: ' ,PSOtype;... 141 | 'Dimensions : ' ,num2str(D);... 142 | '# of particles : ',num2str(ps);... 143 | minmaxstr ,errgoalstr;... 144 | 'Function : ' ,strrep(functname,'_','\_');... 145 | xtraname ,xtraval;... 146 | rststat1 ,rststat2}; 147 | 148 | text(.1,1,[titstr{1,1},titstr{1,2}],'color','g','fontweight','bold'); 149 | hold on 150 | text(.1,.9,[titstr{2,1},titstr{2,2}],'color','m'); 151 | text(.1,.8,[titstr{3,1},titstr{3,2}],'color','m'); 152 | text(.1,.7,[titstr{4,1}],'color','w'); 153 | text(.55,.7,[titstr{4,2}],'color','m'); 154 | text(.1,.6,[titstr{5,1},titstr{5,2}],'color','m'); 155 | text(.1,.5,[titstr{6,1},titstr{6,2}],'color','w','fontweight','bold'); 156 | text(.1,.4,[titstr{7,1},titstr{7,2}],'color','r','fontweight','bold'); 157 | 158 | % if we are training a neural net, show a few more parameters 159 | if strcmp('pso_neteval',functname) 160 | % net is passed from trainpso to pso_Trelea_vectorized in case you are 161 | % wondering where that structure comes from 162 | hiddlyrstr = []; 163 | for lyrcnt=1:length(net.layers) 164 | TF{lyrcnt} = net.layers{lyrcnt}.transferFcn; 165 | Sn(lyrcnt) = net.layers{lyrcnt}.dimensions; 166 | hiddlyrstr = [hiddlyrstr,', ',TF{lyrcnt}]; 167 | end 168 | hiddlyrstr = hiddlyrstr(3:end); 169 | 170 | text(0.1,.35,['#neur/lyr = [ ',num2str(net.inputs{1}.size),' ',... 171 | num2str(Sn),' ]'],'color','c','fontweight','normal',... 172 | 'fontsize',10); 173 | text(0.1,.275,['Lyr Fcn: ',hiddlyrstr],... 174 | 'color','c','fontweight','normal','fontsize',9); 175 | 176 | end 177 | 178 | 179 | legstr = {'Green = Personal Bests';... 180 | 'Blue = Current Positions';... 181 | 'Red = Global Best'}; 182 | text(.1,0.025,legstr{1},'color','g'); 183 | text(.1,-.05,legstr{2},'color','b'); 184 | text(.1,-.125,legstr{3},'color','r'); 185 | 186 | hold off 187 | 188 | set(gca,'color','k'); 189 | set(gca,'visible','off'); 190 | 191 | drawnow -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/linear_dyn.m: -------------------------------------------------------------------------------- 1 | % linear_dyn.m 2 | % returns an offset that can be added to data that increases linearly with 3 | % time, based on cputime, first time it is called is start time 4 | % 5 | % equation is: offset = (cputime - tnot)*scalefactor 6 | % where tnot = cputime at the first call 7 | % scalefactor = value that slows or speeds up linear movement 8 | % 9 | % usage: [offset] = linear_dyn(scalefactor) 10 | 11 | % Brian Birge 12 | % Rev 1.0 13 | % 8/23/04 14 | 15 | function out = linear_dyn(sf) 16 | % this keeps the same start time for each run of the calling function 17 | % this will reset when any calling prog is re-saved or workspace is 18 | % cleared 19 | persistent tnot 20 | % find starting time 21 | if ~exist('tnot') | length(tnot)==0 22 | tnot = cputime; 23 | end 24 | 25 | out = (cputime-tnot)*sf; 26 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于PSO工具箱的函数寻优算法/testfunctions/main.m -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/normmat.m: -------------------------------------------------------------------------------- 1 | function [out,varargout]=normmat(x,newminmax,flag) 2 | % normmat.m 3 | % takes a matrix and reformats the data to fit between a new range 4 | % 5 | % Usage: 6 | % [xprime,mins,maxs]=normmat(x,range,method) 7 | % 8 | % Inputs: 9 | % x - matrix to reformat of dimension MxN 10 | % range - a vector or matrix specifying minimum and maximum values for the new matrix 11 | % for method = 0, range is a 2 element row vector of [min,max] 12 | % for method = 1, range is a 2 row matrix with same column size as 13 | % input matrix with format of [min1,min2,...minN; 14 | % max1,max2,...maxM]; 15 | % for method = 2, range is a 2 column matrix with same row size as 16 | % input matrix with format of [min1,max1; 17 | % min2,max2; 18 | % ... , ...; 19 | % minM,maxM]; 20 | % alternatively for method 1 and 2, can input just a 2 element vector as in method 0 21 | % this will just apply the same min/max across each column or row respectively 22 | % method - a scalar flag with the following function 23 | % = 1, normalize each column of the input matrix separately 24 | % = 2, normalize each row of the input matrix separately 25 | % = 0, normalize matrix globally 26 | % Outputs: 27 | % xprime - new matrix normalized per method 28 | % mins,maxs - optional outputs return the min and max vectors of the original matrix x 29 | % used for recovering original matrix from xprime 30 | % 31 | % example: x = [-10,3,0;2,4.1,-7;3.4,1,0.01] 32 | % [xprime,mins,maxs]=normmat(x,[0,10],0) 33 | 34 | % Brian Birge 35 | % Rev 2.1 36 | % 3/16/06 - changed name of function to avoid same name in robust control 37 | % toolbox 38 | %-------------------------------------------------------------------------------------------------------- 39 | if flag==0 40 | 41 | a=min(min((x))); 42 | b=max(max((x))); 43 | if abs(a)>abs(b) 44 | large=a; 45 | small=b; 46 | else 47 | large=b; 48 | small=a; 49 | end 50 | temp=size(newminmax); 51 | if temp(1)~=1 52 | error('Error: for method=0, range vector must be a 2 element row vector'); 53 | end 54 | den=abs(large-small); 55 | range=newminmax(2)-newminmax(1); 56 | if den==0 57 | out=x; 58 | else 59 | z21=(x-a)/(den); 60 | out=z21*range+newminmax(1)*ones(size(z21)); 61 | end 62 | 63 | %-------------------------------------------------------------------------------------------------------- 64 | elseif flag==1 65 | a=min(x,[],1); 66 | b=max(x,[],1); 67 | for i=1:length(b) 68 | if abs(a(i))>abs(b(i)) 69 | large(i)=a(i); 70 | small(i)=b(i); 71 | else 72 | large(i)=b(i); 73 | small(i)=a(i); 74 | end 75 | end 76 | den=abs(large-small); 77 | temp=size(newminmax); 78 | if temp(1)*temp(2)==2 79 | newminmaxA(1,:)=newminmax(1).*ones(size(x(1,:))); 80 | newminmaxA(2,:)=newminmax(2).*ones(size(x(1,:))); 81 | elseif temp(1)>2 82 | error('Error: for method=1, range matrix must have 2 rows and same columns as input matrix'); 83 | else 84 | newminmaxA=newminmax; 85 | end 86 | 87 | range=newminmaxA(2,:)-newminmaxA(1,:); 88 | for j=1:length(x(:,1)) 89 | for i=1:length(b) 90 | if den(i)==0 91 | out(j,i)=x(j,i); 92 | else 93 | z21(j,i)=(x(j,i)-a(i))./(den(i)); 94 | out(j,i)=z21(j,i).*range(1,i)+newminmaxA(1,i); 95 | end 96 | end 97 | end 98 | %-------------------------------------------------------------------------------------------------------- 99 | elseif flag==2 100 | a=min(x,[],2); 101 | b=max(x,[],2); 102 | for i=1:length(b) 103 | if abs(a(i))>abs(b(i)) 104 | large(i)=a(i); 105 | small(i)=b(i); 106 | else 107 | large(i)=b(i); 108 | small(i)=a(i); 109 | end 110 | end 111 | den=abs(large-small); 112 | temp=size(newminmax); 113 | if temp(1)*temp(2)==2 114 | newminmaxA(:,1)=newminmax(1).*ones(size(x(:,1))); 115 | newminmaxA(:,2)=newminmax(2).*ones(size(x(:,1))); 116 | elseif temp(2)>2 117 | error('Error: for method=2, range matrix must have 2 columns and same rows as input matrix'); 118 | else 119 | newminmaxA=newminmax; 120 | end 121 | 122 | range=newminmaxA(:,2)-newminmaxA(:,1); 123 | for j=1:length(x(1,:)) 124 | for i=1:length(b) 125 | if den(i)==0 126 | out(i,j)=x(i,j); 127 | else 128 | z21(i,j)=(x(i,j)-a(i))./([forcecol(den(i))]); 129 | out(i,j)=z21(i,j).*range(i,1)+newminmaxA(i,1); 130 | end 131 | end 132 | end 133 | 134 | end 135 | %-------------------------------------------------------------------------------------------------------- 136 | varargout{1}=a; 137 | varargout{2}=b; 138 | 139 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/spiral_dyn.m: -------------------------------------------------------------------------------- 1 | % spiral_dyn.m 2 | % returns x,y position along an archimedean spiral of degree n 3 | % based on cputime, first time it is called is start time 4 | % 5 | % based on: r = a*(theta^n) 6 | % 7 | % usage: [x_cnt,y_cnt] = spiral_dyn(n,a) 8 | % i.e., 9 | % n = 2 (Fermat) 10 | % = 1 (Archimedes) 11 | % = -1 (Hyberbolic) 12 | % = -2 (Lituus) 13 | 14 | % Brian Birge 15 | % Rev 1.1 16 | % 8/23/04 17 | 18 | function [x_cnt,y_cnt] = spiral_dyn(n,a) 19 | % this keeps the same start time for each run of the calling function 20 | % this will reset when any calling prog is re-saved or workspace is 21 | % cleared 22 | persistent tnot iter 23 | % find starting time 24 | if ~exist('tnot') | length(tnot)==0 25 | tnot = cputime; 26 | % iter = 0; 27 | end 28 | %iter = iter+10 ; 29 | 30 | theta = cputime-tnot; 31 | %theta = iter/10000; 32 | 33 | r = a*(theta.^n); 34 | 35 | x_cnt = r*cos(theta); 36 | y_cnt = r*sin(theta); 37 | return -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/test_func.m: -------------------------------------------------------------------------------- 1 | function z=test_func(in) 2 | nn=size(in); 3 | x=in(:,1); 4 | y=in(:,2); 5 | nx=nn(1); 6 | for i=1:nx 7 | temp = 0.5*(x(i)-3)^2+0.2*(y(i)-5)^2-0.1; 8 | z(i,:) = temp; 9 | end -------------------------------------------------------------------------------- /基于PSO工具箱的函数寻优算法/testfunctions/tripod.m: -------------------------------------------------------------------------------- 1 | % tripod.m 2 | % 2D tripod function, described by Clerc... 3 | % http://clerc.maurice.free.fr/pso/Semi-continuous_challenge/Semi-continuous_challenge.htm 4 | % 5 | % used to test optimization/global minimization problems 6 | % in Clerc's "Semi-continuous challenge" 7 | % 8 | % f(x)= [ p(x2)*(1+p(x1)) ... 9 | % + abs(x1 + 50*p(x2)*(1-2*p(x1)))... 10 | % + abs(x2 + 50*(1-2*p(x2))) ]; 11 | % 12 | % where p(u) = 1 for u >= 0 13 | % = 0 else 14 | % 15 | % in = 2 element row vector containing [x1, x2] 16 | % each row is processed independently, 17 | % you can feed in matrices of timeX2 no prob 18 | % 19 | % example: cost = tripod([1,2;5,6;0,-50]) 20 | % note: known minimum =0 @ (0,-50) 21 | 22 | % Brian Birge 23 | % Rev 1.0 24 | % 9/12/04 25 | 26 | function [out]=tripod(in) 27 | 28 | x1=in(:,1); 29 | x2=in(:,2); 30 | 31 | px1=((x1) >= 0); 32 | px2=((x2) >= 0); 33 | 34 | out= ( px2.*(1+px1) ... 35 | + abs(x1 + 50*px2.*(1-2*px1))... 36 | + abs(x2 + 50*(1-2.*px2)) ); -------------------------------------------------------------------------------- /基于动态粒子群算法的动态环境寻优算法/DF1function.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于动态粒子群算法的动态环境寻优算法/DF1function.m -------------------------------------------------------------------------------- /基于动态粒子群算法的动态环境寻优算法/fitnessRecord.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于动态粒子群算法的动态环境寻优算法/fitnessRecord.mat -------------------------------------------------------------------------------- /基于动态粒子群算法的动态环境寻优算法/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于动态粒子群算法的动态环境寻优算法/main.m -------------------------------------------------------------------------------- /基于动态粒子群算法的动态环境寻优算法/result.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于动态粒子群算法的动态环境寻优算法/result.mat -------------------------------------------------------------------------------- /基于粒子群算法的PID控制器优化设计/GA_run.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于粒子群算法的PID控制器优化设计/GA_run.m -------------------------------------------------------------------------------- /基于粒子群算法的PID控制器优化设计/PSO.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于粒子群算法的PID控制器优化设计/PSO.m -------------------------------------------------------------------------------- /基于粒子群算法的PID控制器优化设计/PSO_PID.m: -------------------------------------------------------------------------------- 1 | function z=PSO_PID(x) 2 | assignin('base','Kp',x(1)); 3 | assignin('base','Ki',x(2)); 4 | assignin('base','Kd',x(3)); 5 | [t_time,x_state,y_out]=sim('PID_Model',[0,20]); 6 | z=y_out(end,1); -------------------------------------------------------------------------------- /基于粒子群算法的PID控制器优化设计/问题解决思路.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于粒子群算法的PID控制器优化设计/问题解决思路.pdf -------------------------------------------------------------------------------- /基于蚁群算法的三位路径规划算法/CacuFit.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于蚁群算法的三位路径规划算法/CacuFit.m -------------------------------------------------------------------------------- /基于蚁群算法的三位路径规划算法/CacuQfz.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于蚁群算法的三位路径规划算法/CacuQfz.m -------------------------------------------------------------------------------- /基于蚁群算法的三位路径规划算法/HeightData.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于蚁群算法的三位路径规划算法/HeightData.mat -------------------------------------------------------------------------------- /基于蚁群算法的三位路径规划算法/czfz.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于蚁群算法的三位路径规划算法/czfz.m -------------------------------------------------------------------------------- /基于蚁群算法的三位路径规划算法/data.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于蚁群算法的三位路径规划算法/data.m -------------------------------------------------------------------------------- /基于蚁群算法的三位路径规划算法/data1.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于蚁群算法的三位路径规划算法/data1.m -------------------------------------------------------------------------------- /基于蚁群算法的三位路径规划算法/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于蚁群算法的三位路径规划算法/main.m -------------------------------------------------------------------------------- /基于蚁群算法的三位路径规划算法/searchpath.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于蚁群算法的三位路径规划算法/searchpath.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1/Code.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1/Code.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1/Cross.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1/Cross.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1/Genetic.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1/Genetic.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1/Mutation.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1/Mutation.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1/Select.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1/Select.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1/fun.m: -------------------------------------------------------------------------------- 1 | function y = fun(x) 2 | y=-5*sin(x(1))*sin(x(2))*sin(x(3))*sin(x(4))*sin(x(5))-sin(5*x(1))*sin(5*x(2))*sin(5*x(3))*sin(5*x(4))*sin(5*x(5))+8; 3 | 4 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1/test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1/test.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1非线性/Code.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1非线性/Code.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1非线性/Cross.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1非线性/Cross.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1非线性/Mutation.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1非线性/Mutation.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1非线性/Select.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1非线性/Select.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1非线性/fun.m: -------------------------------------------------------------------------------- 1 | function y = fun(x) 2 | y=-5*sin(x(1))*sin(x(2))*sin(x(3))*sin(x(4))*sin(x(5))-sin(5*x(1))*sin(5*x(2))*sin(5*x(3))*sin(5*x(4))*sin(5*x(5))+8; 3 | 4 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1非线性/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1非线性/main.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1非线性/nonlinear.m: -------------------------------------------------------------------------------- 1 | function ret = nonlinear(chrom,sizepop) 2 | 3 | for i=1:sizepop 4 | x=fmincon(inline('-5*sin(x(1))*sin(x(2))*sin(x(3))*sin(x(4))*sin(x(5))-sin(5*x(1))*sin(5*x(2))*sin(5*x(3))*sin(5*x(4))*sin(5*x(5))'),chrom(i,:)',[],[],[],[],[0 0 0 0 0],[2.8274 2.8274 2.8274 2.8274 2.8274]); 5 | ret(i,:)=x'; 6 | end 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例1非线性/test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例1非线性/test.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2/Code.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2/Code.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2/Cross.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2/Cross.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2/Genetic.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2/Genetic.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2/Mutation.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2/Mutation.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2/Select.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2/Select.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2/fun.m: -------------------------------------------------------------------------------- 1 | function y = fun(x) 2 | 3 | y=-20*exp(-0.2*sqrt((x(1)^2+x(2)^2)/2))-exp((cos(2*pi*x(1))+cos(2*pi*x(2)))/2)+20+2.71289; 4 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2/test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2/test.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Code.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Code.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Cross.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Cross.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Genetic.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Genetic.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Mutation.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Mutation.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Select.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2非线性/Select.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2非线性/fun.m: -------------------------------------------------------------------------------- 1 | function y = fun(x) 2 | 3 | y=-20*exp(-0.2*sqrt((x(1)^2+x(2)^2)/2))-exp((cos(2*pi*x(1))+cos(2*pi*x(2)))/2)+20+2.71289; 4 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2非线性/nonlinear.m: -------------------------------------------------------------------------------- 1 | function ret = nonlinear(chrom,sizepop) 2 | 3 | for i=1:sizepop 4 | x=fmincon(inline('-20*exp(-0.2*sqrt((x(1)^2+x(2)^2)/2))-exp((cos(2*pi*x(1))+cos(2*pi*x(2)))/2)+20+2.71289'),chrom(i,:)',[],[],[],[],[-5 -5],[5 5]); 5 | ret(i,:)=x'; 6 | end 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例2非线性/test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例2非线性/test.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3/Code.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3/Code.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3/Cross.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3/Cross.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3/Genetic.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3/Genetic.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3/Mutation.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3/Mutation.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3/Select.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3/Select.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3/fun.m: -------------------------------------------------------------------------------- 1 | function y = fun(x) 2 | 3 | y=(x(1)^2+x(2)^2)^0.25*(sin((50*(x(1)^2+x(2)^2))^0.1)+1); 4 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3/test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3/test.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Code.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Code.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Cross.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Cross.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Genetic.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Genetic.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Mutation.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Mutation.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Select.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3非线性/Select.m -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3非线性/fun.m: -------------------------------------------------------------------------------- 1 | function y = fun(x) 2 | 3 | y=(x(1)^2+x(2)^2)^0.25*(sin((50*(x(1)^2+x(2)^2))^0.1)+1); 4 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3非线性/nonlinear.m: -------------------------------------------------------------------------------- 1 | function ret = nonlinear(chrom,sizepop) 2 | 3 | for i=1:sizepop 4 | x=fmincon(inline('-20*exp(-0.2*sqrt((x(1)^2+x(2)^2)/2))-exp((cos(2*pi*x(1))+cos(2*pi*x(2)))/2)+20+2.71289'),chrom(i,:)',[],[],[],[],[-5 -5],[5 5]); 5 | ret(i,:)=x'; 6 | end 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /基于遗传算法和非线性规划的函数寻优算法/案例3非线性/test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法和非线性规划的函数寻优算法/案例3非线性/test.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2009a/Bpfun.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2009a/Bpfun.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2009a/GABPMain.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2009a/GABPMain.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2009a/Objfun.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2009a/Objfun.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2009a/callbackfun.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2009a/callbackfun.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2009a/data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2009a/data.mat -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2014a/Bpfun.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2014a/Bpfun.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2014a/GABPMain.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2014a/GABPMain.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2014a/Objfun.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2014a/Objfun.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2014a/callbackfun.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2014a/callbackfun.m -------------------------------------------------------------------------------- /基于遗传算法的BP神经网络优化算法/R2014a/data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的BP神经网络优化算法/R2014a/data.mat -------------------------------------------------------------------------------- /基于遗传算法的LQR控制器优化设计/GA_LQR_run.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的LQR控制器优化设计/GA_LQR_run.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/CityPosition1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/CityPosition1.mat -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/CityPosition2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/CityPosition2.mat -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/CityPosition3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/CityPosition3.mat -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/Distanse.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/Distanse.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/DrawPath.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/DrawPath.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/Fitness.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/Fitness.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/GA_TSP.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/GA_TSP.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/InitPop.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/InitPop.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/Mutate.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/Mutate.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/OutputPath.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/OutputPath.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/PathLength.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/PathLength.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/Recombin.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/Recombin.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/Reins.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/Reins.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/Reverse.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/Reverse.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/Select.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/Select.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/Sus.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/基于遗传算法的TSP算法/Sus.m -------------------------------------------------------------------------------- /基于遗传算法的TSP算法/dsxy2figxy.m: -------------------------------------------------------------------------------- 1 | function varargout = dsxy2figxy(varargin) 2 | if length(varargin{1}) == 1 && ishandle(varargin{1}) ... 3 | && strcmp(get(varargin{1},'type'),'axes') 4 | hAx = varargin{1}; 5 | varargin = varargin(2:end); 6 | else 7 | hAx = gca; 8 | end; 9 | if length(varargin) == 1 10 | pos = varargin{1}; 11 | else 12 | [x,y] = deal(varargin{:}); 13 | end 14 | axun = get(hAx,'Units'); 15 | set(hAx,'Units','normalized'); 16 | axpos = get(hAx,'Position'); 17 | axlim = axis(hAx); 18 | axwidth = diff(axlim(1:2)); 19 | axheight = diff(axlim(3:4)); 20 | if exist('x','var') 21 | varargout{1} = (x - axlim(1)) * axpos(3) / axwidth + axpos(1); 22 | varargout{2} = (y - axlim(3)) * axpos(4) / axheight + axpos(2); 23 | else 24 | pos(1) = (pos(1) - axlim(1)) / axwidth * axpos(3) + axpos(1); 25 | pos(2) = (pos(2) - axlim(3)) / axheight * axpos(4) + axpos(2); 26 | pos(3) = pos(3) * axpos(3) / axwidth; 27 | pos(4) = pos(4) * axpos(4 )/ axheight; 28 | varargout{1} = pos; 29 | end 30 | set(hAx,'Units',axun) 31 | -------------------------------------------------------------------------------- /多种群遗传算法的函数优化算法/EliteInduvidual.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/多种群遗传算法的函数优化算法/EliteInduvidual.m -------------------------------------------------------------------------------- /多种群遗传算法的函数优化算法/MPGA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/多种群遗传算法的函数优化算法/MPGA.m -------------------------------------------------------------------------------- /多种群遗传算法的函数优化算法/ObjectFunction.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/多种群遗传算法的函数优化算法/ObjectFunction.m -------------------------------------------------------------------------------- /多种群遗传算法的函数优化算法/SGA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/多种群遗传算法的函数优化算法/SGA.m -------------------------------------------------------------------------------- /多种群遗传算法的函数优化算法/immigrant.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/多种群遗传算法的函数优化算法/immigrant.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/BreastTissue_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/BreastTissue_data.mat -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/COPYRIGHT: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2000-2009 Chih-Chung Chang and Chih-Jen Lin 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | 3. Neither name of copyright holders nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/Makefile: -------------------------------------------------------------------------------- 1 | # This Makefile is used under Linux 2 | 3 | MATLABDIR ?= /usr/local/matlab 4 | # for Mac 5 | # MATLABDIR ?= /opt/local/matlab 6 | 7 | CXX ?= g++ 8 | #CXX = g++-4.1 9 | CFLAGS = -Wall -Wconversion -O3 -fPIC -I$(MATLABDIR)/extern/include 10 | 11 | MEX = $(MATLABDIR)/bin/mex 12 | MEX_OPTION = CC\#$(CXX) CXX\#$(CXX) CFLAGS\#"$(CFLAGS)" CXXFLAGS\#"$(CFLAGS)" 13 | # comment the following line if you use MATLAB on 32-bit computer 14 | MEX_OPTION += -largeArrayDims 15 | MEX_EXT = $(shell $(MATLABDIR)/bin/mexext) 16 | 17 | OCTAVEDIR ?= /usr/include/octave 18 | OCTAVE_MEX = env CC=$(CXX) mkoctfile 19 | OCTAVE_MEX_OPTION = --mex 20 | OCTAVE_MEX_EXT = mex 21 | OCTAVE_CFLAGS = -Wall -O3 -fPIC -I$(OCTAVEDIR) 22 | 23 | all: matlab 24 | 25 | matlab: binary 26 | 27 | octave: 28 | @make MEX="$(OCTAVE_MEX)" MEX_OPTION="$(OCTAVE_MEX_OPTION)" \ 29 | MEX_EXT="$(OCTAVE_MEX_EXT)" CFLAGS="$(OCTAVE_CFLAGS)" \ 30 | binary 31 | 32 | binary: svmpredict.$(MEX_EXT) svmtrain.$(MEX_EXT) libsvmread.$(MEX_EXT) libsvmwrite.$(MEX_EXT) 33 | 34 | svmpredict.$(MEX_EXT): svmpredict.c svm.h svm.o svm_model_matlab.o 35 | $(MEX) $(MEX_OPTION) svmpredict.c svm.o svm_model_matlab.o 36 | 37 | svmtrain.$(MEX_EXT): svmtrain.c svm.h svm.o svm_model_matlab.o 38 | $(MEX) $(MEX_OPTION) svmtrain.c svm.o svm_model_matlab.o 39 | 40 | libsvmread.$(MEX_EXT): libsvmread.c 41 | $(MEX) $(MEX_OPTION) libsvmread.c 42 | 43 | libsvmwrite.$(MEX_EXT): libsvmwrite.c 44 | $(MEX) $(MEX_OPTION) libsvmwrite.c 45 | 46 | svm_model_matlab.o: svm_model_matlab.c svm.h 47 | $(CXX) $(CFLAGS) -c svm_model_matlab.c 48 | 49 | svm.o: svm.cpp svm.h 50 | $(CXX) $(CFLAGS) -c svm.cpp 51 | 52 | clean: 53 | rm -f *~ *.o *.mex* *.obj 54 | -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/heart_scale.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/heart_scale.mat -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVC.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVC.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVC_test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVC_test.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVMcgForClass.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVMcgForClass.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVMcgForRegress.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVMcgForRegress.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVR.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVR.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVR_test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/SVR_test.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/TutorialForFarutoUltimate3.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/TutorialForFarutoUltimate3.0.pdf -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/TutorialTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/TutorialTest.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/VF.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/VF.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/a_template_flow_usingSVM_class.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/a_template_flow_usingSVM_class.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/a_template_flow_usingSVM_regress.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/a_template_flow_usingSVM_regress.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/fasticaForSVM.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/fasticaForSVM.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/gaSVMcgForClass.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/gaSVMcgForClass.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/gaSVMcgForRegress.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/gaSVMcgForRegress.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/gaSVMcgpForRegress.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/gaSVMcgpForRegress.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/bs2rv.m: -------------------------------------------------------------------------------- 1 | % BS2RV.m - Binary string to real vector 2 | % 3 | % This function decodes binary chromosomes into vectors of reals. The 4 | % chromosomes are seen as the concatenation of binary strings of given 5 | % length, and decoded into real numbers in a specified interval using 6 | % either standard binary or Gray decoding. 7 | % 8 | % Syntax: Phen = bs2rv(Chrom,FieldD) 9 | % 10 | % Input parameters: 11 | % 12 | % Chrom - Matrix containing the chromosomes of the current 13 | % population. Each line corresponds to one 14 | % individual's concatenated binary string 15 | % representation. Leftmost bits are MSb and 16 | % rightmost are LSb. 17 | % 18 | % FieldD - Matrix describing the length and how to decode 19 | % each substring in the chromosome. It has the 20 | % following structure: 21 | % 22 | % [len; (num) 23 | % lb; (num) 24 | % ub; (num) 25 | % code; (0=binary | 1=gray) 26 | % scale; (0=arithmetic | 1=logarithmic) 27 | % lbin; (0=excluded | 1=included) 28 | % ubin]; (0=excluded | 1=included) 29 | % 30 | % where 31 | % len - row vector containing the length of 32 | % each substring in Chrom. sum(len) 33 | % should equal the individual length. 34 | % lb, 35 | % ub - Lower and upper bounds for each 36 | % variable. 37 | % code - binary row vector indicating how each 38 | % substring is to be decoded. 39 | % scale - binary row vector indicating where to 40 | % use arithmetic and/or logarithmic 41 | % scaling. 42 | % lbin, 43 | % ubin - binary row vectors indicating whether 44 | % or not to include each bound in the 45 | % representation range 46 | % 47 | % Output parameter: 48 | % 49 | % Phen - Real matrix containing the population phenotypes. 50 | 51 | % 52 | % Author: Carlos Fonseca, Updated: Andrew Chipperfield 53 | % Date: 08/06/93, Date: 26-Jan-94 54 | 55 | function Phen = bs2rv(Chrom,FieldD) 56 | 57 | % Identify the population size (Nind) 58 | % and the chromosome length (Lind) 59 | [Nind,Lind] = size(Chrom); 60 | 61 | % Identify the number of decision variables (Nvar) 62 | [seven,Nvar] = size(FieldD); 63 | 64 | if seven ~= 7 65 | error('FieldD must have 7 rows.'); 66 | end 67 | 68 | % Get substring properties 69 | len = FieldD(1,:); 70 | lb = FieldD(2,:); 71 | ub = FieldD(3,:); 72 | code = ~(~FieldD(4,:)); 73 | scale = ~(~FieldD(5,:)); 74 | lin = ~(~FieldD(6,:)); 75 | uin = ~(~FieldD(7,:)); 76 | 77 | % Check substring properties for consistency 78 | if sum(len) ~= Lind, 79 | error('Data in FieldD must agree with chromosome length'); 80 | end 81 | 82 | if ~all(lb(scale).*ub(scale)>0) 83 | error('Log-scaled variables must not include 0 in their range'); 84 | end 85 | 86 | % Decode chromosomes 87 | Phen = zeros(Nind,Nvar); 88 | 89 | lf = cumsum(len); 90 | li = cumsum([1 len]); 91 | Prec = .5 .^ len; 92 | 93 | logsgn = sign(lb(scale)); 94 | lb(scale) = log( abs(lb(scale)) ); 95 | ub(scale) = log( abs(ub(scale)) ); 96 | delta = ub - lb; 97 | 98 | Prec = .5 .^ len; 99 | num = (~lin) .* Prec; 100 | den = (lin + uin - 1) .* Prec; 101 | 102 | for i = 1:Nvar, 103 | idx = li(i):lf(i); 104 | if code(i) % Gray decoding 105 | Chrom(:,idx)=rem(cumsum(Chrom(:,idx)')',2); 106 | end 107 | Phen(:,i) = Chrom(:,idx) * [ (.5).^(1:len(i))' ]; 108 | Phen(:,i) = lb(i) + delta(i) * (Phen(:,i) + num(i)) ./ (1 - den(i)); 109 | end 110 | 111 | expand = ones(Nind,1); 112 | if any(scale) 113 | Phen(:,scale) = logsgn(expand,:) .* exp(Phen(:,scale)); 114 | end 115 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/contents.m: -------------------------------------------------------------------------------- 1 | % Genetic Algorithm Toolbox. 2 | % Version 1.2 15-Apr-94 3 | % Department of Automatic Control and Systems Engineering 4 | % University of Sheffield, England 5 | % 6 | % Creating populations 7 | % crtbase - create a base vector 8 | % crtbp - create a binary population 9 | % crtrp - create a real-valued population 10 | % 11 | % Fitness assignment 12 | % ranking - rank-based fitness assignment 13 | % scaling - proportional fitness-scaling 14 | % 15 | % Selection and reinsertion 16 | % reins - uniform random and fitness-based reinsertion 17 | % rws - roulette wheel selection 18 | % select - high-level selection routine 19 | % sues - stochastic universal sampling 20 | % 21 | % Mutation operators 22 | % mut - discrete mutation 23 | % mutate - high-level mutation function 24 | % mutbga - real-value mutation 25 | % 26 | % Crossover operators 27 | % recdis - discrete recombination 28 | % recint - intermediate recombination 29 | % reclin - line recombination 30 | % recmut - line recombination with mutation features 31 | % recombin - high-level recombination function 32 | % xovdp - double-point crossover 33 | % xovdprs - double-point reduced surrogate crossover 34 | % xovmp - general multi-point crossover 35 | % xovsh - shuffle crossover 36 | % xovshrs - shuffle reduced surrogate crossover 37 | % xovsp - single-point crossover 38 | % xovsprs - single-point reduced surrogate crossover 39 | % 40 | % Subpopulation support 41 | % migrate - exchange individuals between subpopulations 42 | % 43 | % 44 | % Utility functions 45 | % bs2rv - binary string to real-value conversion 46 | % rep - matrix replication 47 | % 48 | % Demonstration and other functions 49 | % mpga - multi-population genetic algorithm demonstration 50 | % objfun1 - De Jongs first test function (used by sga) 51 | % objharv - harvest function (used in mpga) 52 | % resplot - result plotting (used in mpga) 53 | % sga - simple genetic algorithm demonstration 54 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/crtbase.m: -------------------------------------------------------------------------------- 1 | % CRTBASE.m - Create base vector 2 | % 3 | % This function creates a vector containing the base of the loci 4 | % in a chromosome. 5 | % 6 | % Syntax: BaseVec = crtbase(Lind, Base) 7 | % 8 | % Input Parameters: 9 | % 10 | % Lind - A scalar or vector containing the lengths 11 | % of the alleles. Sum(Lind) is the length of 12 | % the corresponding chromosome. 13 | % 14 | % Base - A scalar or vector containing the base of 15 | % the loci contained in the Alleles. 16 | % 17 | % Output Parameters: 18 | % 19 | % BaseVec - A vector whose elements correspond to the base 20 | % of the loci of the associated chromosome structure. 21 | 22 | % Author: Andrew Chipperfield 23 | % Date: 19-Jan-94 24 | 25 | function BaseVec = crtbase(Lind, Base) 26 | 27 | [ml LenL] = size(Lind) ; 28 | if nargin < 2 29 | Base = 2 * ones(LenL,1) ; % default to base 2 30 | end 31 | [mb LenB] = size(Base) ; 32 | 33 | % check parameter consistency 34 | if ml > 1 | mb > 1 35 | error( 'Lind or Base is not a vector') ; 36 | elseif (LenL > 1 & LenB > 1 & LenL ~= LenB) | (LenL == 1 & LenB > 1 ) 37 | error( 'Vector dimensions must agree' ) ; 38 | elseif LenB == 1 & LenL > 1 39 | Base = Base * ones(LenL,1) ; 40 | 41 | end 42 | 43 | BaseVec = [] ; 44 | for i = 1:LenL 45 | BaseVec = [BaseVec, Base(i)*ones(Lind(i),1)']; 46 | end 47 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/crtbp.m: -------------------------------------------------------------------------------- 1 | % CRTP.m - Create an initial population 2 | % 3 | % This function creates a binary population of given size and structure. 4 | % 5 | % Syntax: [Chrom Lind BaseV] = crtbp(Nind, Lind, Base) 6 | % 7 | % Input Parameters: 8 | % 9 | % Nind - Either a scalar containing the number of individuals 10 | % in the new population or a row vector of length two 11 | % containing the number of individuals and their length. 12 | % 13 | % Lind - A scalar containing the length of the individual 14 | % chromosomes. 15 | % 16 | % Base - A scalar containing the base of the chromosome 17 | % elements or a row vector containing the base(s) 18 | % of the loci of the chromosomes. 19 | % 20 | % Output Parameters: 21 | % 22 | % Chrom - A matrix containing the random valued chromosomes 23 | % row wise. 24 | % 25 | % Lind - A scalar containing the length of the chromosome. 26 | % 27 | % BaseV - A row vector containing the base of the 28 | % chromosome loci. 29 | 30 | % Author: Andrew Chipperfield 31 | % Date: 19-Jan-94 32 | 33 | function [Chrom, Lind, BaseV] = crtbp(Nind, Lind, Base) 34 | nargs = nargin ; 35 | 36 | % Check parameter consistency 37 | 38 | if nargs >= 1, [mN, nN] = size(Nind) ; end 39 | if nargs >= 2, [mL, nL] = size(Lind) ; end 40 | if nargs == 3, [mB, nB] = size(Base) ; end 41 | 42 | if nN == 2 43 | if (nargs == 1) 44 | Lind = Nind(2) ; Nind = Nind(1) ; BaseV = crtbase(Lind) ; 45 | elseif (nargs == 2 & nL == 1) 46 | BaseV = crtbase(Nind(2),Lind) ; Lind = Nind(2) ; Nind = Nind(1) ; 47 | elseif (nargs == 2 & nL > 1) 48 | if Lind ~= length(Lind), error('Lind and Base disagree'); end 49 | BaseV = Lind ; Lind = Nind(2) ; Nind = Nind(1) ; 50 | end 51 | elseif nN == 1 52 | if nargs == 2 53 | if nL == 1, BaseV = crtbase(Lind) ; 54 | else, BaseV = Lind ; Lind = nL ; end 55 | elseif nargs == 3 56 | if nB == 1, BaseV = crtbase(Lind,Base) ; 57 | elseif nB ~= Lind, error('Lind and Base disagree') ; 58 | else BaseV = Base ; end 59 | end 60 | else 61 | error('Input parameters inconsistent') ; 62 | end 63 | 64 | % Create a structure of random chromosomes in row wise order, dimensions 65 | % Nind by Lind. The base of each chromosomes loci is given by the value 66 | % of the corresponding element of the row vector base. 67 | 68 | Chrom = floor(rand(Nind,Lind).*BaseV(ones(Nind,1),:)) ; 69 | 70 | 71 | % End of file 72 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/crtrp.m: -------------------------------------------------------------------------------- 1 | % CRTRP.M (CReaTe an initial (Real-value) Population) 2 | % 3 | % This function creates a population of given size of random real-values. 4 | % 5 | % Syntax: Chrom = crtrp(Nind,FieldDR); 6 | % 7 | % Input parameters: 8 | % Nind - A scalar containing the number of individuals in the new 9 | % population. 10 | % 11 | % FieldDR - A matrix of size 2 by number of variables describing the 12 | % boundaries of each variable. It has the following structure: 13 | % [lower_bound; (vector with lower bound for each veriable) 14 | % upper_bound] (vector with upper bound for each veriable) 15 | % [lower_bound_var_1 lower_bound_var_2 ... lower_bound_var_Nvar; 16 | % upper_bound_var_1 upper_bound_var_2 ... upper_bound_var_Nvar] 17 | % example - each individuals consists of 4 variables: 18 | % FieldDR = [-100 -50 -30 -20; % lower bound 19 | % 100 50 30 20] % upper bound 20 | % 21 | % Output parameter: 22 | % Chrom - A matrix containing the random valued individuals of the 23 | % new population of size Nind by number of variables. 24 | 25 | % Author: Hartmut Pohlheim 26 | % History: 23.11.93 file created 27 | % 25.02.94 clean up, check parameter consistency 28 | 29 | 30 | function Chrom = crtrp(Nind,FieldDR); 31 | 32 | % Check parameter consistency 33 | if nargin < 2, error('parameter FieldDR missing'); end 34 | if nargin > 2, nargin = 2; end 35 | 36 | [mN, nN] = size(Nind); 37 | [mF, Nvar] = size(FieldDR); 38 | 39 | if (mN ~= 1 & nN ~= 1), error('Nind has to be a scalar'); end 40 | if mF ~= 2, error('FieldDR must be a matrix with 2 rows'); end 41 | 42 | % Compute Matrix with Range of variables and Matrix with Lower value 43 | Range = rep((FieldDR(2,:)-FieldDR(1,:)),[Nind 1]); 44 | Lower = rep(FieldDR(1,:), [Nind 1]); 45 | 46 | % Create initial population 47 | % Each row contains one individual, the values of each variable uniformly 48 | % distributed between lower and upper bound (given by FieldDR) 49 | Chrom = rand(Nind,Nvar) .* Range + Lower; 50 | 51 | 52 | % End of function 53 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/migrate.m: -------------------------------------------------------------------------------- 1 | % MIGRATE.M (MIGRATion of individuals between subpopulations) 2 | % 3 | % This function performs migration of individuals. 4 | % 5 | % Syntax: [Chrom, ObjV] = migrate(Chrom, SUBPOP, MigOpt, ObjV) 6 | % 7 | % Input parameters: 8 | % Chrom - Matrix containing the individuals of the current 9 | % population. Each row corresponds to one individual. 10 | % SUBPOP - Number of subpopulations 11 | % MigOpt - (optional) Vector containing migration parameters 12 | % MigOpt(1): MIGR - Rate of individuals to be migrated per 13 | % subpopulation (% of subpopulation) 14 | % if omitted or NaN, 0.2 (20%) is assumed 15 | % MigOpt(2): Select - number indicating the selection method 16 | % of replacing individuals 17 | % 0 - uniform selection 18 | % 1 - fitness-based selection (replace worst 19 | % individuals) 20 | % if omitted or NaN, 0 is assumed 21 | % MigOpt(3): Structure - number indicating the structure 22 | % of the subpopulations for migration 23 | % 0 - net structure (unconstrained migration) 24 | % 1 - neighbourhood structure 25 | % 2 - ring structure 26 | % if omitted or NaN, 0 is assumed 27 | % ObjV - (optional) Column vector containing the objective values 28 | % of the individuals in the current population, needed for 29 | % fitness-based migration, this saves the 30 | % recalculation of objective values for population. 31 | % 32 | % Output parameters: 33 | % Chrom - Matrix containing the individuals of the current 34 | % population after migration. 35 | % ObjV - if ObjV is input parameter, than column vector containing 36 | % the objective values of the individuals of the current 37 | % generation after migration. 38 | 39 | % Author: Hartmut Pohlheim 40 | % History: 16.02.94 file created 41 | % 18.02.94 comments at the beginning added 42 | % exchange of ObjV too 43 | % 25.02.94 clean up 44 | % 26.02.94 ObjV optional input parameter 45 | % Select and Structure added, parameter reordered 46 | % 17.03.94 renamed to migrate.m, more parameter checks 47 | 48 | function [Chrom, ObjV] = migrate(Chrom, SUBPOP, MigOpt, ObjV); 49 | 50 | 51 | % Check parameter consistency 52 | if nargin < 2, error('Input parameter SUBPOP missing'); end 53 | if (nargout == 2 & nargin < 4), error('Input parameter ObjV missing'); end 54 | 55 | [Nind, Nvar] = size(Chrom); 56 | if length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end 57 | if SUBPOP == 1, return; end 58 | if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('Chrom and SUBPOP disagree'); end 59 | NIND = Nind/SUBPOP; % Compute number of individuals per subpopulation 60 | 61 | if nargin > 3, 62 | [mO, nO] = size(ObjV); 63 | if nO ~= 1, error('ObjV must be a column vector'); end 64 | if Nind ~= mO, error('Chrom and ObjV disagree'); end 65 | IsObjV = 1; 66 | else IsObjV = 0; ObjV = []; 67 | end 68 | 69 | if nargin < 3, MIGR = 0.2; Select = 0; Structure = 0; end 70 | if nargin > 2, 71 | if isempty(MigOpt), MIGR = 0.2; Select = 0; Structure = 0; 72 | elseif isnan(MigOpt), MIGR = 0.2; Select = 0; Structure = 0; 73 | else 74 | MIGR = NaN; Select = NaN; Structure = NaN; 75 | if length(MigOpt) > 3, error('Parameter MigOpt is too long'); end 76 | if length(MigOpt) >= 1, MIGR = MigOpt(1); end 77 | if length(MigOpt) >= 2, Select = MigOpt(2); end 78 | if length(MigOpt) >= 3, Structure = MigOpt(3); end 79 | if isnan(MIGR), MIGR =0.2; end 80 | if isnan(Select), Select = 0; end 81 | if isnan(Structure), Structure = 0; end 82 | end 83 | end 84 | 85 | if (MIGR < 0 | MIGR > 1), error('Parameter for migration rate must be a scalar in [0 1]'); end 86 | if (Select ~= 0 & Select ~= 1), error('Parameter for selection method must be 0 or 1'); end 87 | if (Structure < 0 | Structure > 2), error ('Parameter for structure must be 0, 1 or 2'); end 88 | if (Select == 1 & IsObjV == 0), error('ObjV for fitness-based migration needed');end 89 | 90 | if MIGR == 0, return; end 91 | MigTeil = max(floor(NIND * MIGR), 1); % Number of individuals to migrate 92 | 93 | % Perform migration between subpopulations --> create a matrix for migration 94 | % in every subpopulation from best individuals of the other subpopulations 95 | 96 | % Clear storing matrices 97 | ChromMigAll = []; 98 | if IsObjV == 1, ObjVAll = []; end 99 | 100 | % Create matrix with best/uniform individuals of all subpopulations 101 | for irun = 1:SUBPOP 102 | % sort ObjV of actual subpopulation 103 | if Select == 1, % fitness-based selection 104 | [Dummy, IndMigSo]=sort(ObjV((irun-1)*NIND+1:irun*NIND)); 105 | else % if Select == 0 % uniform selection 106 | [Dummy, IndMigSo]=sort(rand(NIND, 1)); 107 | end 108 | % take MigTeil (best) individuals, copy individuals and objective values 109 | IndMigTeil=IndMigSo(1:MigTeil)+(irun-1)*NIND; 110 | ChromMigAll = [ChromMigAll; Chrom(IndMigTeil,:)]; 111 | if IsObjV == 1, ObjVAll = [ObjVAll; ObjV(IndMigTeil,:)]; end 112 | end 113 | 114 | % perform migration 115 | for irun = 1:SUBPOP 116 | ChromMig = ChromMigAll; 117 | if IsObjV == 1, ObjVMig = ObjVAll; end 118 | if Structure == 1, % neighbourhood 119 | % select individuals of neighbourhood subpopulations for ChromMig and ObjVMig 120 | popnum = [SUBPOP 1:SUBPOP 1]; 121 | ins1 = popnum(irun); ins2 = popnum(irun + 2); 122 | InsRows = [(ins1-1)*MigTeil+1:ins1*MigTeil (ins2-1)*MigTeil+1:ins2*MigTeil]; 123 | ChromMig = ChromMig(InsRows,:); 124 | if IsObjV == 1, ObjVMig = ObjVMig(InsRows,:); end 125 | elseif Structure == 2, % ring 126 | % select individuals of actual-1 subpopulation for ChromMig and ObjVMig 127 | popnum = [SUBPOP 1:SUBPOP 1]; 128 | ins1 = popnum(irun); 129 | InsRows = (ins1-1)*MigTeil+1:ins1*MigTeil; 130 | ChromMig = ChromMig(InsRows,:); 131 | if IsObjV == 1, ObjVMig = ObjVMig(InsRows,:); end 132 | else % if Structure == 0, % complete net 133 | % delete individuals of actual subpopulation from ChromMig and ObjVMig 134 | DelRows = (irun-1)*MigTeil+1:irun*MigTeil; 135 | ChromMig(DelRows,:) = []; 136 | if IsObjV == 1, ObjVMig(DelRows,:) = []; end 137 | end 138 | % Create an index from a sorted vector with random numbers 139 | [Dummy,IndMigRa]=sort(rand(size(ChromMig,1),1)); 140 | % Take MigTeil numbers from the random vector 141 | IndMigN=IndMigRa((1:MigTeil)'); 142 | % copy MigTeil individuals into Chrom and ObjV 143 | Chrom((1:MigTeil)+(irun-1)*NIND,:) = ChromMig(IndMigN,:); 144 | if IsObjV == 1, ObjV((1:MigTeil)+(irun-1)*NIND,:) = ObjVMig(IndMigN,:); end 145 | end 146 | 147 | 148 | % End of function 149 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/mpga.m: -------------------------------------------------------------------------------- 1 | % mpga multi population genetic algorithm 2 | % 3 | % This script implements the Multi Population Genetic Algorithm. 4 | % A real-valued representation of the individuals is used. 5 | % 6 | 7 | % Author: Andrew Chipperfield 8 | % History: 30-Mar-94 file created 9 | 10 | NVAR = 20; % No. of decision variables (control steps) 11 | RANGE = [0;200]; % Bounds on decision variables 12 | 13 | % Set field descriptor 14 | FieldD = rep(RANGE,[1,NVAR]); 15 | 16 | % Define GA Parameters 17 | GGAP = .8; % Generation gap, how many new individuals are created 18 | XOVR = 1; % Crossover rate 19 | MUTR = 1/NVAR; % Mutation rate depending on NVAR 20 | MAXGEN = 1200; % Maximum number of generations 21 | TERMEXACT = 1e-4; % Value for termination if minimum reached 22 | INSR = .9; % Insertion rate, how many of the offspring are inserted 23 | SUBPOP = 8; % Number of subpopulations 24 | MIGR = 0.2; % Migration rate between subpopulations 25 | MIGGEN = 20; % Number of generations between migration 26 | NIND = 20; % Number of individuals per subpopulation 27 | 28 | % Specify other routines as strings 29 | SEL_F = 'sus'; % Name of selection function 30 | XOV_F = 'recdis'; % Name of recombination function for individuals 31 | MUT_F = 'mutbga'; % Name of mutation function 32 | OBJ_F = 'objharv'; % Name of function for objective values 33 | 34 | 35 | % Get value of minimum, defined in objective function 36 | GlobalMin = feval(OBJ_F,[],3); 37 | 38 | % Get title of objective function, defined in objective function 39 | FigTitle = [feval(OBJ_F,[],2) ' (' int2str(SUBPOP) ':' int2str(MAXGEN) ') ']; 40 | 41 | % Clear Best and storing matrix 42 | % Initialise Matrix for storing best results 43 | Best = NaN * ones(MAXGEN,3); 44 | Best(:,3) = zeros(size(Best,1),1); 45 | % Matrix for storing best individuals 46 | IndAll = []; 47 | 48 | % Create real population 49 | Chrom = crtrp(SUBPOP*NIND,FieldD); 50 | 51 | % reset count variables 52 | gen = 0; 53 | 54 | % Calculate objective function for population 55 | ObjV = feval(OBJ_F,Chrom); 56 | % count number of objective function evaluations 57 | Best(gen+1,3) = Best(gen+1,3) + NIND; 58 | 59 | % Generational loop 60 | while gen < MAXGEN, 61 | 62 | % Save the best and average objective values and the best individual 63 | [Best(gen+1,1),ix] = min(ObjV); 64 | Best(gen+1,2) = mean(ObjV); 65 | IndAll = [IndAll; Chrom(ix,:)]; 66 | 67 | % Fitness assignment to whole population 68 | FitnV = ranking(ObjV,2 ,SUBPOP); 69 | 70 | % Select individuals from population 71 | SelCh = select(SEL_F, Chrom, FitnV, GGAP, SUBPOP); 72 | 73 | % Recombine selected individuals 74 | SelCh=recombin(XOV_F, SelCh, XOVR, SUBPOP); 75 | 76 | % Mutate offspring 77 | SelCh=mutate(MUT_F, SelCh, FieldD, [MUTR], SUBPOP); 78 | 79 | % Calculate objective function for offsprings 80 | ObjVOff = feval(OBJ_F,SelCh); 81 | Best(gen+1,3) = Best(gen+1,3) + size(SelCh,1); 82 | 83 | % Insert best offspring in population replacing worst parents 84 | [Chrom, ObjV] = reins(Chrom, SelCh, SUBPOP, [1 INSR], ObjV, ObjVOff); 85 | 86 | gen=gen+1; 87 | 88 | % Plot some results, rename title of figure for graphic output 89 | if ((rem(gen,20) == 1) | (rem(gen,MAXGEN) == 0)), 90 | set(gcf,'Name',[FigTitle ' in ' int2str(gen)]); 91 | resplot(Chrom(1:2:size(Chrom,1),:),... 92 | IndAll(max(1,gen-39):size(IndAll,1),:),... 93 | [ObjV; GlobalMin], Best(max(1,gen-19):gen,[1 2]), gen); 94 | end 95 | 96 | 97 | % migrate individuals between subpopulations 98 | if (rem(gen,MIGGEN) == 0) 99 | [Chrom, ObjV] = migrate(Chrom, SUBPOP, [MIGR, 1, 0], ObjV); 100 | end 101 | 102 | end 103 | 104 | 105 | % Results 106 | % add number of objective function evaluations 107 | Results = cumsum(Best(1:gen,3)); 108 | % number of function evaluation, mean and best results 109 | Results = [Results Best(1:gen,2) Best(1:gen,1)]; 110 | 111 | % Plot Results and show best individuals => optimum 112 | figure('Name',['Results of ' FigTitle]); 113 | subplot(2,1,1), plot(Results(:,1),Results(:,2),'-',Results(:,1),Results(:,3),':'); 114 | subplot(2,1,2), plot(IndAll(gen-4:gen,:)'); 115 | 116 | 117 | % End of script 118 | 119 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/mut.m: -------------------------------------------------------------------------------- 1 | % MUT.m 2 | % 3 | % This function takes the representation of the current population, 4 | % mutates each element with given probability and returns the resulting 5 | % population. 6 | % 7 | % Syntax: NewChrom = mut(OldChrom,Pm,BaseV) 8 | % 9 | % Input parameters: 10 | % 11 | % OldChrom - A matrix containing the chromosomes of the 12 | % current population. Each row corresponds to 13 | % an individuals string representation. 14 | % 15 | % Pm - Mutation probability (scalar). Default value 16 | % of Pm = 0.7/Lind, where Lind is the chromosome 17 | % length is assumed if omitted. 18 | % 19 | % BaseV - Optional row vector of the same length as the 20 | % chromosome structure defining the base of the 21 | % individual elements of the chromosome. Binary 22 | % representation is assumed if omitted. 23 | % 24 | % Output parameter: 25 | % 26 | % NewChrom - A Matrix containing a mutated version of 27 | % OldChrom. 28 | % 29 | 30 | % Author: Andrew Chipperfield 31 | % Date: 25-Jan-94 32 | 33 | function NewChrom = mut(OldChrom,Pm,BaseV) 34 | 35 | % get population size (Nind) and chromosome length (Lind) 36 | [Nind, Lind] = size(OldChrom) ; 37 | 38 | % check input parameters 39 | if nargin < 2, Pm = 0.7/Lind ; end 40 | if isnan(Pm), Pm = 0.7/Lind; end 41 | 42 | if (nargin < 3), BaseV = crtbase(Lind); end 43 | if (isnan(BaseV)), BaseV = crtbase(Lind); end 44 | if (isempty(BaseV)), BaseV = crtbase(Lind); end 45 | 46 | if (nargin == 3) & (Lind ~= length(BaseV)) 47 | error('OldChrom and BaseV are incompatible'), end 48 | 49 | % create mutation mask matrix 50 | BaseM = BaseV(ones(Nind,1),:) ; 51 | 52 | % perform mutation on chromosome structure 53 | NewChrom = rem(OldChrom+(rand(Nind,Lind) 4, 62 | if isempty(SUBPOP), SUBPOP = 1; 63 | elseif isnan(SUBPOP), SUBPOP = 1; 64 | elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end 65 | end 66 | 67 | if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('OldChrom and SUBPOP disagree'); end 68 | Nind = Nind/SUBPOP; % Compute number of individuals per subpopulation 69 | 70 | % Select individuals of one subpopulation and call low level function 71 | NewChrom = []; 72 | for irun = 1:SUBPOP, 73 | ChromSub = OldChrom((irun-1)*Nind+1:irun*Nind,:); 74 | if IsDiscret == 1, NewChromSub = feval(MUT_F, ChromSub, MutOpt, FieldDR); 75 | elseif IsDiscret == 0, NewChromSub = feval(MUT_F, ChromSub, FieldDR, MutOpt); end 76 | NewChrom=[NewChrom; NewChromSub]; 77 | end 78 | 79 | 80 | % End of function 81 | 82 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/mutbga.m: -------------------------------------------------------------------------------- 1 | % MUTBGA.M (real-value MUTation like Breeder Genetic Algorithm) 2 | % 3 | % This function takes a matrix OldChrom containing the real 4 | % representation of the individuals in the current population, 5 | % mutates the individuals with probability MutR and returns 6 | % the resulting population. 7 | % 8 | % This function implements the mutation operator of the Breeder Genetic 9 | % Algorithm. (Muehlenbein et. al.) 10 | % 11 | % Syntax: NewChrom = mutbga(OldChrom, FieldDR, MutOpt) 12 | % 13 | % Input parameter: 14 | % OldChrom - Matrix containing the chromosomes of the old 15 | % population. Each line corresponds to one individual. 16 | % FieldDR - Matrix describing the boundaries of each variable. 17 | % MutOpt - (optional) Vector containing mutation rate and shrink value 18 | % MutOpt(1): MutR - number containing the mutation rate - 19 | % probability for mutation of a variable 20 | % if omitted or NaN, MutR = 1/variables per individual 21 | % is assumed 22 | % MutOpt(2): MutShrink - (optional) number for shrinking the 23 | % mutation range in the range [0 1], possibility to 24 | % shrink the range of the mutation depending on, 25 | % for instance actual generation. 26 | % if omitted or NaN, MutShrink = 1 is assumed 27 | % 28 | % Output parameter: 29 | % NewChrom - Matrix containing the chromosomes of the population 30 | % after mutation in the same format as OldChrom. 31 | 32 | % Author: Hartmut Pohlheim 33 | % History: 23.11.93 file created 34 | % 24.11.93 function optimised (for,for-loop to for-loop) 35 | % mutation rate included 36 | % style improved 37 | % 06.12.93 change of function name 38 | % check of boundaries after mutation out of loop 39 | % 16.12.93 NewMutMat and OldMutMat included for compability 40 | % 16.02.94 preparation for multi-subpopulations at once 41 | % 25.02.94 NewMutMat and OldMutMat removed (now in mutran10.m) 42 | % clean up 43 | % change of function name in mutbga.m 44 | % 03.03.94 Lower and Upper directly used (less memory) 45 | % 19.03.94 multipopulation support removed 46 | % more parameter checks 47 | % 27.03.94 Delta exact calculated, for loop saved 48 | 49 | 50 | function NewChrom = mutbga(OldChrom, FieldDR, MutOpt); 51 | 52 | % Check parameter consistency 53 | if nargin < 2, error('Not enough input parameter'); end 54 | 55 | % Identify the population size (Nind) and the number of variables (Nvar) 56 | [Nind,Nvar] = size(OldChrom); 57 | 58 | [mF, nF] = size(FieldDR); 59 | if mF ~= 2, error('FieldDR must be a matrix with 2 rows'); end 60 | if Nvar ~= nF, error('FieldDR and OldChrom disagree'); end 61 | 62 | if nargin < 3, MutR = 1/Nvar; MutShrink = 1; 63 | elseif isempty(MutOpt), MutR = 1/Nvar; MutShrink = 1; 64 | elseif isnan(MutOpt), MutR = 1/Nvar; MutShrink = 1; 65 | else 66 | if length(MutOpt) == 1, MutR = MutOpt; MutShrink = 1; 67 | elseif length(MutOpt) == 2, MutR = MutOpt(1); MutShrink = MutOpt(2); 68 | else, error(' Too many parameter in MutOpt'); end 69 | end 70 | 71 | if isempty(MutR), MutR = 1/Nvar; 72 | elseif isnan(MutR), MutR = 1/Nvar; 73 | elseif length(MutR) ~= 1, error('Parameter for mutation rate must be a scalar'); 74 | elseif (MutR < 0 | MutR > 1), error('Parameter for mutation rate must be a scalar in [0, 1]'); end 75 | 76 | if isempty(MutShrink), MutShrink = 1; 77 | elseif isnan(MutShrink), MutShrink = 1; 78 | elseif length(MutShrink) ~= 1, error('Parameter for shrinking mutation range must be a scalar'); 79 | elseif (MutShrink < 0 | MutShrink > 1), 80 | error('Parameter for shrinking mutation range must be a scalar in [0, 1]'); 81 | end 82 | 83 | % the variables are mutated with probability MutR 84 | % NewChrom = OldChrom (+ or -) * Range * MutShrink * Delta 85 | % Range = 0.5 * (upperbound - lowerbound) 86 | % Delta = Sum(Alpha_i * 2^-i) from 0 to ACCUR; Alpha_i = rand(ACCUR,1) < 1/ACCUR 87 | 88 | % Matrix with range values for every variable 89 | Range = rep(0.5 * MutShrink *(FieldDR(2,:)-FieldDR(1,:)),[Nind 1]); 90 | 91 | % zeros and ones for mutate or not this variable, together with Range 92 | Range = Range .* (rand(Nind,Nvar) < MutR); 93 | 94 | % compute, if + or - sign 95 | Range = Range .* (1 - 2 * (rand(Nind,Nvar) < 0.5)); 96 | 97 | % used for later computing, here only ones computed 98 | ACCUR = 20; 99 | Vect = 2 .^ (-(0:(ACCUR-1))'); 100 | Delta = (rand(Nind,ACCUR) < 1/ACCUR) * Vect; 101 | Delta = rep(Delta, [1 Nvar]); 102 | 103 | % perform mutation 104 | NewChrom = OldChrom + Range .* Delta; 105 | 106 | % Ensure variables boundaries, compare with lower and upper boundaries 107 | NewChrom = max(rep(FieldDR(1,:),[Nind 1]), NewChrom); 108 | NewChrom = min(rep(FieldDR(2,:),[Nind 1]), NewChrom); 109 | 110 | 111 | % End of function 112 | 113 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/ranking.m: -------------------------------------------------------------------------------- 1 | % RANKING.M (RANK-based fitness assignment) 2 | % 3 | % This function performs ranking of individuals. 4 | % 5 | % Syntax: FitnV = ranking(ObjV, RFun, SUBPOP) 6 | % 7 | % This function ranks individuals represented by their associated 8 | % cost, to be *minimized*, and returns a column vector FitnV 9 | % containing the corresponding individual fitnesses. For multiple 10 | % subpopulations the ranking is performed separately for each 11 | % subpopulation. 12 | % 13 | % Input parameters: 14 | % ObjV - Column vector containing the objective values of the 15 | % individuals in the current population (cost values). 16 | % RFun - (optional) If RFun is a scalar in [1, 2] linear ranking is 17 | % assumed and the scalar indicates the selective pressure. 18 | % If RFun is a 2 element vector: 19 | % RFun(1): SP - scalar indicating the selective pressure 20 | % RFun(2): RM - ranking method 21 | % RM = 0: linear ranking 22 | % RM = 1: non-linear ranking 23 | % If RFun is a vector with length(Rfun) > 2 it contains 24 | % the fitness to be assigned to each rank. It should have 25 | % the same length as ObjV. Usually RFun is monotonously 26 | % increasing. 27 | % If RFun is omitted or NaN, linear ranking 28 | % and a selective pressure of 2 are assumed. 29 | % SUBPOP - (optional) Number of subpopulations 30 | % if omitted or NaN, 1 subpopulation is assumed 31 | % 32 | % Output parameters: 33 | % FitnV - Column vector containing the fitness values of the 34 | % individuals in the current population. 35 | % 36 | 37 | % Author: Hartmut Pohlheim (Carlos Fonseca) 38 | % History: 01.03.94 non-linear ranking 39 | % 10.03.94 multiple populations 40 | 41 | function FitnV = ranking(ObjV, RFun, SUBPOP); 42 | 43 | % Identify the vector size (Nind) 44 | [Nind,ans] = size(ObjV); 45 | 46 | if nargin < 2, RFun = []; end 47 | if nargin > 1, if isnan(RFun), RFun = []; end, end 48 | if prod(size(RFun)) == 2, 49 | if RFun(2) == 1, NonLin = 1; 50 | elseif RFun(2) == 0, NonLin = 0; 51 | else error('Parameter for ranking method must be 0 or 1'); end 52 | RFun = RFun(1); 53 | if isnan(RFun), RFun = 2; end 54 | elseif prod(size(RFun)) > 2, 55 | if prod(size(RFun)) ~= Nind, error('ObjV and RFun disagree'); end 56 | end 57 | 58 | if nargin < 3, SUBPOP = 1; end 59 | if nargin > 2, 60 | if isempty(SUBPOP), SUBPOP = 1; 61 | elseif isnan(SUBPOP), SUBPOP = 1; 62 | elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end 63 | end 64 | 65 | if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('ObjV and SUBPOP disagree'); end 66 | Nind = Nind/SUBPOP; % Compute number of individuals per subpopulation 67 | 68 | % Check ranking function and use default values if necessary 69 | if isempty(RFun), 70 | % linear ranking with selective pressure 2 71 | RFun = 2*[0:Nind-1]'/(Nind-1); 72 | elseif prod(size(RFun)) == 1 73 | if NonLin == 1, 74 | % non-linear ranking 75 | if RFun(1) < 1, error('Selective pressure must be greater than 1'); 76 | elseif RFun(1) > Nind-2, error('Selective pressure too big'); end 77 | Root1 = roots([RFun(1)-Nind [RFun(1)*ones(1,Nind-1)]]); 78 | RFun = (abs(Root1(1)) * ones(Nind,1)) .^ [(0:Nind-1)']; 79 | RFun = RFun / sum(RFun) * Nind; 80 | else 81 | % linear ranking with SP between 1 and 2 82 | if (RFun(1) < 1 | RFun(1) > 2), 83 | error('Selective pressure for linear ranking must be between 1 and 2'); 84 | end 85 | RFun = 2-RFun + 2*(RFun-1)*[0:Nind-1]'/(Nind-1); 86 | end 87 | end; 88 | 89 | FitnV = []; 90 | 91 | % loop over all subpopulations 92 | for irun = 1:SUBPOP, 93 | % Copy objective values of actual subpopulation 94 | ObjVSub = ObjV((irun-1)*Nind+1:irun*Nind); 95 | % Sort does not handle NaN values as required. So, find those... 96 | NaNix = isnan(ObjVSub); 97 | Validix = find(~NaNix); 98 | % ... and sort only numeric values (smaller is better). 99 | [ans,ix] = sort(-ObjVSub(Validix)); 100 | 101 | % Now build indexing vector assuming NaN are worse than numbers, 102 | % (including Inf!)... 103 | ix = [find(NaNix) ; Validix(ix)]; 104 | % ... and obtain a sorted version of ObjV 105 | Sorted = ObjVSub(ix); 106 | 107 | % Assign fitness according to RFun. 108 | i = 1; 109 | FitnVSub = zeros(Nind,1); 110 | for j = [find(Sorted(1:Nind-1) ~= Sorted(2:Nind)); Nind]', 111 | FitnVSub(i:j) = sum(RFun(i:j)) * ones(j-i+1,1) / (j-i+1); 112 | i =j+1; 113 | end 114 | 115 | % Finally, return unsorted vector. 116 | [ans,uix] = sort(ix); 117 | FitnVSub = FitnVSub(uix); 118 | 119 | % Add FitnVSub to FitnV 120 | FitnV = [FitnV; FitnVSub]; 121 | end 122 | 123 | 124 | % End of function 125 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/recdis.m: -------------------------------------------------------------------------------- 1 | % RECDIS.M (RECombination DIScrete) 2 | % 3 | % This function performs discret recombination between pairs of individuals 4 | % and returns the new individuals after mating. 5 | % 6 | % Syntax: NewChrom = recdis(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one individual 11 | % (in any form, not necessarily real-values). 12 | % XOVR - Probability of recombination occurring between pairs 13 | % of individuals. (not used, only for compatibility) 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 23.11.93 file created 22 | % 24.11.93 style improved 23 | % 06.12.93 change of name of function 24 | % 25.02.94 clean up 25 | % 19.03.94 multipopulation support removed 26 | 27 | function NewChrom = recdis(OldChrom, XOVR); 28 | 29 | % Identify the population size (Nind) and the number of variables (Nvar) 30 | [Nind,Nvar] = size(OldChrom); 31 | 32 | % Identify the number of matings 33 | Xops = floor(Nind/2); 34 | 35 | % which parent gives the value 36 | Mask1 = (rand(Xops,Nvar)<0.5); 37 | Mask2 = (rand(Xops,Nvar)<0.5); 38 | 39 | % Performs crossover 40 | odd = 1:2:Nind-1; 41 | even= 2:2:Nind; 42 | NewChrom(odd,:) = (OldChrom(odd,:).* Mask1) + (OldChrom(even,:).*(~Mask1)); 43 | NewChrom(even,:) = (OldChrom(odd,:).* Mask2) + (OldChrom(even,:).*(~Mask2)); 44 | 45 | % If the number of individuals is odd, the last individual cannot be mated 46 | % but must be included in the new population 47 | if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end 48 | 49 | 50 | % End of function 51 | 52 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/recint.m: -------------------------------------------------------------------------------- 1 | % RECINT.M (RECombination extended INTermediate) 2 | % 3 | % This function performs extended intermediate recombination between 4 | % pairs of individuals and returns the new individuals after mating. 5 | % 6 | % Syntax: NewChrom = recint(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one 11 | % individual 12 | % XOVR - Probability of crossover occurring between pairs 13 | % of individuals. (not used, only for compatibility) 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 25.11.93 file created 22 | % 06.12.93 change of name of function 23 | % 25.02.94 clean up 24 | % 19.03.94 multipopulation support removed 25 | 26 | function NewChrom = recint(OldChrom, XOVR); 27 | 28 | % Identify the population size (Nind) and the number of variables (Nvar) 29 | [Nind,Nvar] = size(OldChrom); 30 | 31 | % Identify the number of matings 32 | Xops = floor(Nind/2); 33 | 34 | % Performs recombination 35 | odd = 1:2:Nind-1; 36 | even= 2:2:Nind; 37 | 38 | % position of value of offspring compared to parents 39 | Alpha = -0.25 + 1.5 * rand(Xops,Nvar); 40 | 41 | % recombination 42 | NewChrom(odd,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:)); 43 | 44 | % the same ones more for second half of offspring 45 | Alpha = -0.25 + 1.5 * rand(Xops,Nvar); 46 | NewChrom(even,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:)); 47 | 48 | % If the number of individuals is odd, the last individual cannot be mated 49 | % but must be included in the new population 50 | if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end 51 | 52 | 53 | % End of function 54 | 55 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/reclin.m: -------------------------------------------------------------------------------- 1 | % RECLIN.M (RECombination extended LINe) 2 | % 3 | % This function performs extended line recombination between 4 | % pairs of individuals and returns the new individuals after mating. 5 | % 6 | % Syntax: NewChrom = reclin(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one 11 | % individual 12 | % XOVR - Probability of crossover occurring between pairs 13 | % of individuals. (not used, only for compatibility) 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 26.11.93 file created 22 | % 06.12.93 change of name of function 23 | % 25.02.94 clean up 24 | % 19.03.94 multipopulation support removed 25 | 26 | function NewChrom = reclin(OldChrom, XOVR); 27 | 28 | % Identify the population size (Nind) and the number of variables (Nvar) 29 | [Nind,Nvar] = size(OldChrom); 30 | 31 | % Identify the number of matings 32 | Xops = floor(Nind/2); 33 | 34 | % Performs recombination 35 | odd = 1:2:Nind-1; 36 | even= 2:2:Nind; 37 | 38 | % position of value of offspring compared to parents 39 | Alpha = -0.25 + 1.5 * rand(Xops,1); 40 | Alpha = Alpha(1:Xops,ones(Nvar,1)); 41 | 42 | % recombination 43 | NewChrom(odd,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:)); 44 | 45 | % the same ones more for second half of offspring 46 | Alpha = -0.25 + 1.5 * rand(Xops,1); 47 | Alpha = Alpha(1:Xops,ones(Nvar,1)); 48 | NewChrom(even,:) = OldChrom(odd,:) + Alpha .* (OldChrom(even,:) - OldChrom(odd,:)); 49 | 50 | % If the number of individuals is odd, the last individual cannot be mated 51 | % but must be included in the new population 52 | if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end 53 | 54 | 55 | % End of function 56 | 57 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/recmut.m: -------------------------------------------------------------------------------- 1 | % RECLIN.M (line RECombination with MUTation features) 2 | % 3 | % This function performs line recombination with mutation features between 4 | % pairs of individuals and returns the new individuals after mating. 5 | % 6 | % Syntax: NewChrom = recmut(OldChrom, FieldDR, MutOpt) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one individual 11 | % FieldDR - Matrix describing the boundaries of each variable. 12 | % MutOpt - (optional) Vector containing recombination rate and shrink value 13 | % MutOpt(1): MutR - number containing the recombination rate - 14 | % probability for recombine a pair of parents 15 | % if omitted or NaN, MutOpt(1) = 1 is assumed 16 | % MutOpt(2): MutShrink - (optional) number for shrinking the 17 | % recombination range in the range [0 1], possibility to 18 | % shrink the range of the recombination depending on, 19 | % for instance actual generation. 20 | % if omitted or NaN, MutOpt(2) = 1 is assumed 21 | % 22 | % Output parameter: 23 | % NewChrom - Matrix containing the chromosomes of the population 24 | % after mating, ready to be mutated and/or evaluated, 25 | % in the same format as OldChrom. 26 | 27 | % Author: Hartmut Pohlheim 28 | % History: 27.03.94 file created 29 | 30 | function NewChrom = recmut(OldChrom, FieldDR, MutOpt); 31 | 32 | % Check parameter consistency 33 | if nargin < 2, error('Not enough input parameter'); end 34 | 35 | % Identify the population size (Nind) and the number of variables (Nvar) 36 | [Nind,Nvar] = size(OldChrom); 37 | 38 | [mF, nF] = size(FieldDR); 39 | if mF ~= 2, error('FieldDR must be a matrix with 2 rows'); end 40 | if Nvar ~= nF, error('FieldDR and OldChrom disagree'); end 41 | 42 | if nargin < 3, MutR = 1; MutShrink = 1; 43 | elseif isempty(MutOpt), MutR = 1; MutShrink = 1; 44 | elseif isnan(MutOpt), MutR = 1; MutShrink = 1; 45 | else 46 | if length(MutOpt) == 1, MutR = MutOpt; MutShrink = 1; 47 | elseif length(MutOpt) == 2, MutR = MutOpt(1); MutShrink = MutOpt(2); 48 | else, error(' Too many parameter in MutOpt'); end 49 | end 50 | 51 | if isempty(MutR), MutR = 1; 52 | elseif isnan(MutR), MutR = 1; 53 | elseif length(MutR) ~= 1, error('Parameter for recombination rate must be a scalar'); 54 | elseif (MutR < 0 | MutR > 1), error('Parameter for recombination rate must be a scalar in [0, 1]'); end 55 | 56 | if isempty(MutShrink), MutShrink = 1; 57 | elseif isnan(MutShrink), MutShrink = 1; 58 | elseif length(MutShrink) ~= 1, error('Parameter for shrinking recombination range must be a scalar'); 59 | elseif (MutShrink < 0 | MutShrink > 1), 60 | error('Parameter for shrinking recombination range must be a scalar in [0, 1]'); 61 | end 62 | 63 | % Identify the number of matings 64 | Xops = floor(Nind/2); 65 | 66 | % NewChrom = OldChrom (+ or -) * Range * MutShrink * Delta * ChromDiff 67 | % - with probability 0.9, + with probability 0.1 68 | % Range = 0.5 * (upperbound - lowerbound), given by FieldDR 69 | % Delta = Sum(Alpha_i * 2^-i) from 0 to ACCUR; Alpha_i = rand(ACCUR,1) < 1/ACCUR 70 | % ChromDiff = (individual1 - individual2) / Distance between individuals 71 | 72 | % Matrix with range values for every variable 73 | Range = rep(0.5 * MutShrink *(FieldDR(2,:)-FieldDR(1,:)),[Xops 1]); 74 | 75 | % zeros and ones for recombine or not this variable, together with Range 76 | if MutR < 1, Range = Range .* rep((rand(Xops,1) < MutR), [1 Nvar]); end 77 | 78 | % compute, if + or - sign 79 | Range = Range .* (1 - 2 * (rand(Xops,Nvar) < 0.9)); 80 | 81 | % compute distance between mating pairs 82 | NormO = zeros(Xops,1); 83 | for irun = 1:Xops, 84 | NormO(irun) = max(realmin,abs(norm(OldChrom(2*irun,:)) - norm(OldChrom(2*irun-1,:)))); 85 | end 86 | 87 | % compute difference between variables divided by distance 88 | ChromDiff = zeros(Xops,Nvar); 89 | for irun = 1:Xops 90 | ChromDiff(irun,:) = diff([OldChrom(2*irun-1,:); OldChrom(2*irun,:)]) / NormO(irun); 91 | end 92 | 93 | % compute delta value for all individuals 94 | ACCUR = 20; 95 | Vect = 2 .^ (-(0:(ACCUR-1))'); 96 | Delta = (rand(Xops,ACCUR) < 1/ACCUR) * Vect; 97 | Delta = rep(Delta, [1 Nvar]); 98 | 99 | % Performs recombination 100 | odd = 1:2:Nind-1; 101 | even= 2:2:Nind; 102 | 103 | % recombination 104 | NewChrom(odd,:) = OldChrom(odd,:) + Range .* Delta .* (ChromDiff); 105 | NewChrom(even,:) = OldChrom(even,:) + Range .* Delta .* (-ChromDiff); 106 | 107 | % If the number of individuals is odd, the last individual cannot be mated 108 | % but must be included in the new population 109 | if rem(Nind,2), NewChrom(Nind,:)=OldChrom(Nind,:); end 110 | 111 | % Ensure variables boundaries, compare with lower and upper boundaries 112 | NewChrom = max(rep(FieldDR(1,:),[Nind 1]), NewChrom); 113 | NewChrom = min(rep(FieldDR(2,:),[Nind 1]), NewChrom); 114 | 115 | 116 | % End of function 117 | 118 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/recombin.m: -------------------------------------------------------------------------------- 1 | % RECOMBIN.M (RECOMBINation high-level function) 2 | % 3 | % This function performs recombination between pairs of individuals 4 | % and returns the new individuals after mating. The function handles 5 | % multiple populations and calls the low-level recombination function 6 | % for the actual recombination process. 7 | % 8 | % Syntax: NewChrom = recombin(REC_F, OldChrom, RecOpt, SUBPOP) 9 | % 10 | % Input parameters: 11 | % REC_F - String containing the name of the recombination or 12 | % crossover function 13 | % Chrom - Matrix containing the chromosomes of the old 14 | % population. Each line corresponds to one individual 15 | % RecOpt - (optional) Scalar containing the probability of 16 | % recombination/crossover occurring between pairs 17 | % of individuals. 18 | % if omitted or NaN, 1 is assumed 19 | % SUBPOP - (optional) Number of subpopulations 20 | % if omitted or NaN, 1 subpopulation is assumed 21 | % 22 | % Output parameter: 23 | % NewChrom - Matrix containing the chromosomes of the population 24 | % after recombination in the same format as OldChrom. 25 | 26 | % Author: Hartmut Pohlheim 27 | % History: 18.03.94 file created 28 | 29 | 30 | function NewChrom = recombin(REC_F, Chrom, RecOpt, SUBPOP); 31 | 32 | 33 | % Check parameter consistency 34 | if nargin < 2, error('Not enough input parameter'); end 35 | 36 | % Identify the population size (Nind) 37 | [Nind,Nvar] = size(Chrom); 38 | 39 | if nargin < 4, SUBPOP = 1; end 40 | if nargin > 3, 41 | if isempty(SUBPOP), SUBPOP = 1; 42 | elseif isnan(SUBPOP), SUBPOP = 1; 43 | elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end 44 | end 45 | 46 | if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('Chrom and SUBPOP disagree'); end 47 | Nind = Nind/SUBPOP; % Compute number of individuals per subpopulation 48 | 49 | if nargin < 3, RecOpt = 0.7; end 50 | if nargin > 2, 51 | if isempty(RecOpt), RecOpt = 0.7; 52 | elseif isnan(RecOpt), RecOpt = 0.7; 53 | elseif length(RecOpt) ~= 1, error('RecOpt must be a scalar'); 54 | elseif (RecOpt < 0 | RecOpt > 1), error('RecOpt must be a scalar in [0, 1]'); end 55 | end 56 | 57 | 58 | % Select individuals of one subpopulation and call low level function 59 | NewChrom = []; 60 | for irun = 1:SUBPOP, 61 | ChromSub = Chrom((irun-1)*Nind+1:irun*Nind,:); 62 | NewChromSub = feval(REC_F, ChromSub, RecOpt); 63 | NewChrom=[NewChrom; NewChromSub]; 64 | end 65 | 66 | 67 | % End of function 68 | 69 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/reins.m: -------------------------------------------------------------------------------- 1 | % REINS.M (RE-INSertion of offspring in population replacing parents) 2 | % 3 | % This function reinserts offspring in the population. 4 | % 5 | % Syntax: [Chrom, ObjVCh] = reins(Chrom, SelCh, SUBPOP, InsOpt, ObjVCh, ObjVSel) 6 | % 7 | % Input parameters: 8 | % Chrom - Matrix containing the individuals (parents) of the current 9 | % population. Each row corresponds to one individual. 10 | % SelCh - Matrix containing the offspring of the current 11 | % population. Each row corresponds to one individual. 12 | % SUBPOP - (optional) Number of subpopulations 13 | % if omitted or NaN, 1 subpopulation is assumed 14 | % InsOpt - (optional) Vector containing the insertion method parameters 15 | % ExOpt(1): Select - number indicating kind of insertion 16 | % 0 - uniform insertion 17 | % 1 - fitness-based insertion 18 | % if omitted or NaN, 0 is assumed 19 | % ExOpt(2): INSR - Rate of offspring to be inserted per 20 | % subpopulation (% of subpopulation) 21 | % if omitted or NaN, 1.0 (100%) is assumed 22 | % ObjVCh - (optional) Column vector containing the objective values 23 | % of the individuals (parents - Chrom) in the current 24 | % population, needed for fitness-based insertion 25 | % saves recalculation of objective values for population 26 | % ObjVSel - (optional) Column vector containing the objective values 27 | % of the offspring (SelCh) in the current population, needed for 28 | % partial insertion of offspring, 29 | % saves recalculation of objective values for population 30 | % 31 | % Output parameters: 32 | % Chrom - Matrix containing the individuals of the current 33 | % population after reinsertion. 34 | % ObjVCh - if ObjVCh and ObjVSel are input parameter, than column 35 | % vector containing the objective values of the individuals 36 | % of the current generation after reinsertion. 37 | 38 | % Author: Hartmut Pohlheim 39 | % History: 10.03.94 file created 40 | % 19.03.94 parameter checking improved 41 | 42 | function [Chrom, ObjVCh] = reins(Chrom, SelCh, SUBPOP, InsOpt, ObjVCh, ObjVSel); 43 | 44 | 45 | % Check parameter consistency 46 | if nargin < 2, error('Not enough input parameter'); end 47 | if (nargout == 2 & nargin < 6), error('Input parameter missing: ObjVCh and/or ObjVSel'); end 48 | 49 | [NindP, NvarP] = size(Chrom); 50 | [NindO, NvarO] = size(SelCh); 51 | 52 | if nargin == 2, SUBPOP = 1; end 53 | if nargin > 2, 54 | if isempty(SUBPOP), SUBPOP = 1; 55 | elseif isnan(SUBPOP), SUBPOP = 1; 56 | elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end 57 | end 58 | 59 | if (NindP/SUBPOP) ~= fix(NindP/SUBPOP), error('Chrom and SUBPOP disagree'); end 60 | if (NindO/SUBPOP) ~= fix(NindO/SUBPOP), error('SelCh and SUBPOP disagree'); end 61 | NIND = NindP/SUBPOP; % Compute number of individuals per subpopulation 62 | NSEL = NindO/SUBPOP; % Compute number of offspring per subpopulation 63 | 64 | IsObjVCh = 0; IsObjVSel = 0; 65 | if nargin > 4, 66 | [mO, nO] = size(ObjVCh); 67 | if nO ~= 1, error('ObjVCh must be a column vector'); end 68 | if NindP ~= mO, error('Chrom and ObjVCh disagree'); end 69 | IsObjVCh = 1; 70 | end 71 | if nargin > 5, 72 | [mO, nO] = size(ObjVSel); 73 | if nO ~= 1, error('ObjVSel must be a column vector'); end 74 | if NindO ~= mO, error('SelCh and ObjVSel disagree'); end 75 | IsObjVSel = 1; 76 | end 77 | 78 | if nargin < 4, INSR = 1.0; Select = 0; end 79 | if nargin >= 4, 80 | if isempty(InsOpt), INSR = 1.0; Select = 0; 81 | elseif isnan(InsOpt), INSR = 1.0; Select = 0; 82 | else 83 | INSR = NaN; Select = NaN; 84 | if (length(InsOpt) > 2), error('Parameter InsOpt too long'); end 85 | if (length(InsOpt) >= 1), Select = InsOpt(1); end 86 | if (length(InsOpt) >= 2), INSR = InsOpt(2); end 87 | if isnan(Select), Select = 0; end 88 | if isnan(INSR), INSR =1.0; end 89 | end 90 | end 91 | 92 | if (INSR < 0 | INSR > 1), error('Parameter for insertion rate must be a scalar in [0, 1]'); end 93 | if (INSR < 1 & IsObjVSel ~= 1), error('For selection of offspring ObjVSel is needed'); end 94 | if (Select ~= 0 & Select ~= 1), error('Parameter for selection method must be 0 or 1'); end 95 | if (Select == 1 & IsObjVCh == 0), error('ObjVCh for fitness-based exchange needed'); end 96 | 97 | if INSR == 0, return; end 98 | NIns = min(max(floor(INSR*NSEL+.5),1),NIND); % Number of offspring to insert 99 | 100 | % perform insertion for each subpopulation 101 | for irun = 1:SUBPOP, 102 | % Calculate positions in old subpopulation, where offspring are inserted 103 | if Select == 1, % fitness-based reinsertion 104 | [Dummy, ChIx] = sort(-ObjVCh((irun-1)*NIND+1:irun*NIND)); 105 | else % uniform reinsertion 106 | [Dummy, ChIx] = sort(rand(NIND,1)); 107 | end 108 | PopIx = ChIx((1:NIns)')+ (irun-1)*NIND; 109 | % Calculate position of Nins-% best offspring 110 | if (NIns < NSEL), % select best offspring 111 | [Dummy,OffIx] = sort(ObjVSel((irun-1)*NSEL+1:irun*NSEL)); 112 | else 113 | OffIx = (1:NIns)'; 114 | end 115 | SelIx = OffIx((1:NIns)')+(irun-1)*NSEL; 116 | % Insert offspring in subpopulation -> new subpopulation 117 | Chrom(PopIx,:) = SelCh(SelIx,:); 118 | if (IsObjVCh == 1 & IsObjVSel == 1), ObjVCh(PopIx) = ObjVSel(SelIx); end 119 | end 120 | 121 | 122 | % End of function 123 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/rep.m: -------------------------------------------------------------------------------- 1 | % REP.m Replicate a matrix 2 | % 3 | % This function replicates a matrix in both dimensions. 4 | % 5 | % Syntax: MatOut = rep(MatIn,REPN); 6 | % 7 | % Input parameters: 8 | % MatIn - Input Matrix (before replicating) 9 | % 10 | % REPN - Vector of 2 numbers, how many replications in each dimension 11 | % REPN(1): replicate vertically 12 | % REPN(2): replicate horizontally 13 | % 14 | % Example: 15 | % 16 | % MatIn = [1 2 3] 17 | % REPN = [1 2]: MatOut = [1 2 3 1 2 3] 18 | % REPN = [2 1]: MatOut = [1 2 3; 19 | % 1 2 3] 20 | % REPN = [3 2]: MatOut = [1 2 3 1 2 3; 21 | % 1 2 3 1 2 3; 22 | % 1 2 3 1 2 3] 23 | % 24 | % Output parameter: 25 | % MatOut - Output Matrix (after replicating) 26 | % 27 | 28 | % Author: Carlos Fonseca & Hartmut Pohlheim 29 | % History: 14.02.94 file created 30 | 31 | 32 | function MatOut = rep(MatIn,REPN) 33 | 34 | % Get size of input matrix 35 | [N_D,N_L] = size(MatIn); 36 | 37 | % Calculate 38 | Ind_D = rem(0:REPN(1)*N_D-1,N_D) + 1; 39 | Ind_L = rem(0:REPN(2)*N_L-1,N_L) + 1; 40 | 41 | % Create output matrix 42 | MatOut = MatIn(Ind_D,Ind_L); 43 | 44 | 45 | % End of function 46 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/resplot.m: -------------------------------------------------------------------------------- 1 | % RESPLOT.M (RESult PLOTing) 2 | % 3 | % This function plots some results during computation. 4 | % 5 | % Syntax: resplot(Chrom,IndAll,ObjV,Best,gen) 6 | % 7 | % Input parameters: 8 | % Chrom - Matrix containing the chromosomes of the current 9 | % population. Each line corresponds to one individual. 10 | % IndAll - Matrix containing the best individual (variables) of each 11 | % generation. Each line corresponds to one individual. 12 | % ObjV - Vector containing objective values of the current 13 | % generation 14 | % Best - Matrix containing the best and average Objective values of 15 | % each generation, [best value per generation,average value 16 | % per generation] 17 | % gen - Scalar containing the number of the current generation 18 | % 19 | % Output parameter: 20 | % no output parameter 21 | 22 | % Author: Hartmut Pohlheim 23 | % History: 27.11.93 file created 24 | % 29.11.93 decision, if plot or not deleted 25 | % yscale not log 26 | % 15.12.93 MutMatrix as parameter and plot added 27 | % 16.03.94 function cleaned, MutMatrix removed, IndAll added 28 | 29 | function resplot(Chrom,IndAll,ObjV,Best,gen); 30 | 31 | % plot of best and mean value per generation 32 | subplot(2,2,1), plot(Best); 33 | title('Best and mean objective value'); 34 | xlabel('generation'), ylabel('objective value'); 35 | 36 | % plot of best individuals in all generations 37 | subplot(2,2,2), plot(IndAll); 38 | title(['Best individuals']); 39 | xlabel('generation'), ylabel('value of variable'); 40 | 41 | % plot of variables of all individuals in current generation 42 | subplot(2,2,3), plot(Chrom'); 43 | title(['All individuals in gen ',num2str(gen)]); 44 | xlabel('number of variable'), ylabel('value of variable'); 45 | 46 | % plot of all objective values in current generation 47 | subplot(2,2,4), plot(ObjV,'y.'); 48 | title(['All objective values']); 49 | xlabel('number of individual'), ylabel('objective value'); 50 | 51 | drawnow; 52 | 53 | 54 | % End of function 55 | 56 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/rws.m: -------------------------------------------------------------------------------- 1 | % RWS.m - Roulette Wheel Selection 2 | % 3 | % Syntax: 4 | % NewChrIx = rws(FitnV, Nsel) 5 | % 6 | % This function selects a given number of individuals Nsel from a 7 | % population. FitnV is a column vector containing the fitness 8 | % values of the individuals in the population. 9 | % 10 | % The function returns another column vector containing the 11 | % indexes of the new generation of chromosomes relative to the 12 | % original population matrix, shuffled. The new population, ready 13 | % for mating, can be obtained by calculating 14 | % OldChrom(NewChrIx, :). 15 | 16 | % Author: Carlos Fonseca, Updated: Andrew Chipperfield 17 | % Date: 04/10/93, Date: 27-Jan-94 18 | 19 | function NewChrIx = rws(FitnV,Nsel); 20 | 21 | % Identify the population size (Nind) 22 | [Nind,ans] = size(FitnV); 23 | 24 | % Perform Stochastic Sampling with Replacement 25 | cumfit = cumsum(FitnV); 26 | trials = cumfit(Nind) .* rand(Nsel, 1); 27 | Mf = cumfit(:, ones(1, Nsel)); 28 | Mt = trials(:, ones(1, Nind))'; 29 | [NewChrIx, ans] = find(Mt < Mf & ... 30 | [ zeros(1, Nsel); Mf(1:Nind-1, :) ] <= Mt); 31 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/scaling.m: -------------------------------------------------------------------------------- 1 | % SCALING.m - linear fitness scaling 2 | % 3 | % This function implements a linear fitness scaling algorithm as described 4 | % by Goldberg in "Genetic Algorithms in Search, Optimization and Machine 5 | % Learning", Addison Wesley, 1989. It use is not recommended when fitness 6 | % functions produce negative results as the scaling will become unreliable. 7 | % It is included in this version of the GA Toolbox only for the sake of 8 | % completeness. 9 | % 10 | % Syntax: FitnV = scaling(ObjV, Smul) 11 | % 12 | % Input parameters: 13 | % 14 | % Objv - A vector containing the values of individuals 15 | % fitness. 16 | % 17 | % Smul - Optional scaling parameter (default 2). 18 | % 19 | % Output parameters: 20 | % 21 | % FitnV - A vector containing the individual fitnesses 22 | % for the current population. 23 | % 24 | % 25 | 26 | % Author: Andrew Chipperfield 27 | % Date: 24-Feb-94 28 | 29 | 30 | function FitnV = scaling( ObjV, Smul ) 31 | 32 | if nargin == 1 33 | Smul = 2 ; 34 | end 35 | 36 | [Nind, Nobj] = size( ObjV ) ; 37 | Oave = sum( ObjV ) / Nind ; 38 | Omin = min( ObjV ) ; 39 | Omax = max( ObjV ) ; 40 | 41 | if (Omin > ( Smul * Oave - Omax ) / ( Smul - 1.0 )) 42 | delta = Omax - Oave 43 | a = ( Smul - 1.0 ) * Oave / delta 44 | b = Oave * ( Omax - Smul * Oave ) / delta 45 | else 46 | delta = Oave - Omin ; 47 | a = Oave / delta ; 48 | b = -Omin * Oave / delta ; 49 | end 50 | 51 | FitnV = ObjV.*a + b ; 52 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/select.m: -------------------------------------------------------------------------------- 1 | % SELECT.M (universal SELECTion) 2 | % 3 | % This function performs universal selection. The function handles 4 | % multiple populations and calls the low level selection function 5 | % for the actual selection process. 6 | 7 | % 8 | % Syntax: SelCh = select(SEL_F, Chrom, FitnV, GGAP, SUBPOP) 9 | % 10 | % Input parameters: 11 | % SEL_F - Name of the selection function 12 | % Chrom - Matrix containing the individuals (parents) of the current 13 | % population. Each row corresponds to one individual. 14 | % FitnV - Column vector containing the fitness values of the 15 | % individuals in the population. 16 | % GGAP - (optional) Rate of individuals to be selected 17 | % if omitted 1.0 is assumed 18 | % SUBPOP - (optional) Number of subpopulations 19 | % if omitted 1 subpopulation is assumed 20 | % 21 | % Output parameters: 22 | % SelCh - Matrix containing the selected individuals. 23 | 24 | % Author: Hartmut Pohlheim 25 | % History: 10.03.94 file created 26 | 27 | function SelCh = select(SEL_F, Chrom, FitnV, GGAP, SUBPOP); 28 | 29 | % Check parameter consistency 30 | if nargin < 3, error('Not enough input parameter'); end 31 | 32 | % Identify the population size (Nind) 33 | [NindCh,Nvar] = size(Chrom); 34 | [NindF,VarF] = size(FitnV); 35 | if NindCh ~= NindF, error('Chrom and FitnV disagree'); end 36 | if VarF ~= 1, error('FitnV must be a column vector'); end 37 | 38 | if nargin < 5, SUBPOP = 1; end 39 | if nargin > 4, 40 | if isempty(SUBPOP), SUBPOP = 1; 41 | elseif isnan(SUBPOP), SUBPOP = 1; 42 | elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end 43 | end 44 | 45 | if (NindCh/SUBPOP) ~= fix(NindCh/SUBPOP), error('Chrom and SUBPOP disagree'); end 46 | Nind = NindCh/SUBPOP; % Compute number of individuals per subpopulation 47 | 48 | if nargin < 4, GGAP = 1; end 49 | if nargin > 3, 50 | if isempty(GGAP), GGAP = 1; 51 | elseif isnan(GGAP), GGAP = 1; 52 | elseif length(GGAP) ~= 1, error('GGAP must be a scalar'); 53 | elseif (GGAP < 0), error('GGAP must be a scalar bigger than 0'); end 54 | end 55 | 56 | % Compute number of new individuals (to select) 57 | NSel=max(floor(Nind*GGAP+.5),2); 58 | 59 | % Select individuals from population 60 | SelCh = []; 61 | for irun = 1:SUBPOP, 62 | FitnVSub = FitnV((irun-1)*Nind+1:irun*Nind); 63 | ChrIx=feval(SEL_F, FitnVSub, NSel)+(irun-1)*Nind; 64 | SelCh=[SelCh; Chrom(ChrIx,:)]; 65 | end 66 | 67 | 68 | % End of function 69 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/sus.m: -------------------------------------------------------------------------------- 1 | % SUS.M (Stochastic Universal Sampling) 2 | % 3 | % This function performs selection with STOCHASTIC UNIVERSAL SAMPLING. 4 | % 5 | % Syntax: NewChrIx = sus(FitnV, Nsel) 6 | % 7 | % Input parameters: 8 | % FitnV - Column vector containing the fitness values of the 9 | % individuals in the population. 10 | % Nsel - number of individuals to be selected 11 | % 12 | % Output parameters: 13 | % NewChrIx - column vector containing the indexes of the selected 14 | % individuals relative to the original population, shuffled. 15 | % The new population, ready for mating, can be obtained 16 | % by calculating OldChrom(NewChrIx,:). 17 | 18 | % Author: Hartmut Pohlheim (Carlos Fonseca) 19 | % History: 12.12.93 file created 20 | % 22.02.94 clean up, comments 21 | 22 | 23 | function NewChrIx = sus(FitnV,Nsel); 24 | 25 | % Identify the population size (Nind) 26 | [Nind,ans] = size(FitnV); 27 | 28 | % Perform stochastic universal sampling 29 | cumfit = cumsum(FitnV); 30 | trials = cumfit(Nind) / Nsel * (rand + (0:Nsel-1)'); 31 | Mf = cumfit(:, ones(1, Nsel)); 32 | Mt = trials(:, ones(1, Nind))'; 33 | [NewChrIx, ans] = find(Mt < Mf & [ zeros(1, Nsel); Mf(1:Nind-1, :) ] <= Mt); 34 | 35 | % Shuffle new population 36 | [ans, shuf] = sort(rand(Nsel, 1)); 37 | NewChrIx = NewChrIx(shuf); 38 | 39 | 40 | % End of function 41 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/xovdp.m: -------------------------------------------------------------------------------- 1 | % XOVDP.M (CROSSOVer Double Point) 2 | % 3 | % This function performs double point crossover between pairs of 4 | % individuals and returns the current generation after mating. 5 | % 6 | % Syntax: NewChrom = xovdp(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one individual 11 | % (in any form, not necessarily real values). 12 | % XOVR - Probability of recombination occurring between pairs 13 | % of individuals. 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 28.03.94 file created 22 | 23 | function NewChrom = xovdp(OldChrom, XOVR); 24 | 25 | if nargin < 2, XOVR = NaN; end 26 | 27 | % call low level function with appropriate parameters 28 | NewChrom = xovmp(OldChrom, XOVR, 2, 0); 29 | 30 | 31 | % End of function 32 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/xovdprs.m: -------------------------------------------------------------------------------- 1 | % XOVDPRS.M (CROSSOVer Double-Point with Reduced Surrogate) 2 | % 3 | % This function performs double-point 'reduced surrogate' crossover between 4 | % pairs of individuals and returns the current generation after mating. 5 | % 6 | % Syntax: NewChrom = xovdprs(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one individual 11 | % (in any form, not necessarily real values). 12 | % XOVR - Probability of recombination occurring between pairs 13 | % of individuals. 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 28.03.94 file created 22 | 23 | function NewChrom = xovdprs(OldChrom, XOVR); 24 | 25 | if nargin < 2, XOVR = NaN; end 26 | 27 | % call low-level function with appropriate parameters 28 | NewChrom = xovmp(OldChrom, XOVR, 2, 1); 29 | 30 | 31 | % End of function 32 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/xovmp.m: -------------------------------------------------------------------------------- 1 | % XOVMP.m Multi-point crossover 2 | % 3 | % Syntax: NewChrom = xovmp(OldChrom, Px, Npt, Rs) 4 | % 5 | % This function takes a matrix OldChrom containing the binary 6 | % representation of the individuals in the current population, 7 | % applies crossover to consecutive pairs of individuals with 8 | % probability Px and returns the resulting population. 9 | % 10 | % Npt indicates how many crossover points to use (1 or 2, zero 11 | % indicates shuffle crossover). 12 | % Rs indicates whether or not to force the production of 13 | % offspring different from their parents. 14 | % 15 | 16 | % Author: Carlos Fonseca, Updated: Andrew Chipperfield 17 | % Date: 28/09/93, Date: 27-Jan-94 18 | 19 | function NewChrom = xovmp(OldChrom, Px, Npt, Rs); 20 | 21 | % Identify the population size (Nind) and the chromosome length (Lind) 22 | [Nind,Lind] = size(OldChrom); 23 | 24 | if Lind < 2, NewChrom = OldChrom; return; end 25 | 26 | if nargin < 4, Rs = 0; end 27 | if nargin < 3, Npt = 0; Rs = 0; end 28 | if nargin < 2, Px = 0.7; Npt = 0; Rs = 0; end 29 | if isnan(Px), Px = 0.7; end 30 | if isnan(Npt), Npt = 0; end 31 | if isnan(Rs), Rs = 0; end 32 | if isempty(Px), Px = 0.7; end 33 | if isempty(Npt), Npt = 0; end 34 | if isempty(Rs), Rs = 0; end 35 | 36 | Xops = floor(Nind/2); 37 | DoCross = rand(Xops,1) < Px; 38 | odd = 1:2:Nind-1; 39 | even = 2:2:Nind; 40 | 41 | % Compute the effective length of each chromosome pair 42 | Mask = ~Rs | (OldChrom(odd, :) ~= OldChrom(even, :)); 43 | Mask = cumsum(Mask')'; 44 | 45 | % Compute cross sites for each pair of individuals, according to their 46 | % effective length and Px (two equal cross sites mean no crossover) 47 | xsites(:, 1) = Mask(:, Lind); 48 | if Npt >= 2, 49 | xsites(:, 1) = ceil(xsites(:, 1) .* rand(Xops, 1)); 50 | end 51 | xsites(:,2) = rem(xsites + ceil((Mask(:, Lind)-1) .* rand(Xops, 1)) ... 52 | .* DoCross - 1 , Mask(:, Lind) )+1; 53 | 54 | % Express cross sites in terms of a 0-1 mask 55 | Mask = (xsites(:,ones(1,Lind)) < Mask) == ... 56 | (xsites(:,2*ones(1,Lind)) < Mask); 57 | 58 | if ~Npt, 59 | shuff = rand(Lind,Xops); 60 | [ans,shuff] = sort(shuff); 61 | for i=1:Xops 62 | OldChrom(odd(i),:)=OldChrom(odd(i),shuff(:,i)); 63 | OldChrom(even(i),:)=OldChrom(even(i),shuff(:,i)); 64 | end 65 | end 66 | 67 | % Perform crossover 68 | NewChrom(odd,:) = (OldChrom(odd,:).* Mask) + (OldChrom(even,:).*(~Mask)); 69 | NewChrom(even,:) = (OldChrom(odd,:).*(~Mask)) + (OldChrom(even,:).*Mask); 70 | 71 | % If the number of individuals is odd, the last individual cannot be mated 72 | % but must be included in the new population 73 | if rem(Nind,2), 74 | NewChrom(Nind,:)=OldChrom(Nind,:); 75 | end 76 | 77 | if ~Npt, 78 | [ans,unshuff] = sort(shuff); 79 | for i=1:Xops 80 | NewChrom(odd(i),:)=NewChrom(odd(i),unshuff(:,i)); 81 | NewChrom(even(i),:)=NewChrom(even(i),unshuff(:,i)); 82 | end 83 | end 84 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/xovsh.m: -------------------------------------------------------------------------------- 1 | % XOVSH.M (CROSSOVer SHuffle) 2 | % 3 | % This function performs shuffle crossover between pairs of 4 | % individuals and returns the current generation after mating. 5 | % 6 | % Syntax: NewChrom = xovsh(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one individual 11 | % (in any form, not necessarily real values). 12 | % XOVR - Probability of recombination occurring between pairs 13 | % of individuals. 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 28.03.94 file created 22 | 23 | function NewChrom = xovsh(OldChrom, XOVR); 24 | 25 | if nargin < 2, XOVR = NaN; end 26 | 27 | % call low level function with appropriate parameters 28 | NewChrom = xovmp(OldChrom, XOVR, 0, 0); 29 | 30 | 31 | % End of function 32 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/xovshrs.m: -------------------------------------------------------------------------------- 1 | % XOVSHRS.M (CROSSOVer SHuffle with Reduced Surrogate) 2 | % 3 | % This function performs shuffle 'reduced surrogate' crossover between 4 | % pairs of individuals and returns the current generation after mating. 5 | % 6 | % Syntax: NewChrom = xovshrs(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one individual 11 | % (in any form, not necessarily real values). 12 | % XOVR - Probability of recombination occurring between pairs 13 | % of individuals. 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 28.03.94 file created 22 | 23 | function NewChrom = xovshrs(OldChrom, XOVR); 24 | 25 | if nargin < 2, XOVR = NaN; end 26 | 27 | % call low level function with appropriate parameters 28 | NewChrom = xovmp(OldChrom, XOVR, 0, 1); 29 | 30 | 31 | % End of function 32 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/xovsp.m: -------------------------------------------------------------------------------- 1 | % XOVSP.M (CROSSOVer Single-Point) 2 | % 3 | % This function performs single-point crossover between pairs of 4 | % individuals and returns the current generation after mating. 5 | % 6 | % Syntax: NewChrom = xovsp(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one individual 11 | % (in any form, not necessarily real values). 12 | % XOVR - Probability of recombination occurring between pairs 13 | % of individuals. 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 28.03.94 file created 22 | 23 | function NewChrom = xovsp(OldChrom, XOVR); 24 | 25 | if nargin < 2, XOVR = NaN; end 26 | 27 | % call low level function with appropriate parameters 28 | NewChrom = xovmp(OldChrom, XOVR, 1, 0); 29 | 30 | 31 | % End of function 32 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/gatbx[Sheffield]/xovsprs.m: -------------------------------------------------------------------------------- 1 | % XOVSPRS.M (CROSSOVer Single-Point with Reduced Surrogate) 2 | % 3 | % This function performs single-point 'reduced surrogate' crossover between 4 | % pairs of individuals and returns the current generation after mating. 5 | % 6 | % Syntax: NewChrom = xovsprs(OldChrom, XOVR) 7 | % 8 | % Input parameters: 9 | % OldChrom - Matrix containing the chromosomes of the old 10 | % population. Each line corresponds to one individual 11 | % (in any form, not necessarily real-values). 12 | % XOVR - Probability of recombination occurring between pairs 13 | % of individuals. 14 | % 15 | % Output parameter: 16 | % NewChrom - Matrix containing the chromosomes of the population 17 | % after mating, ready to be mutated and/or evaluated, 18 | % in the same format as OldChrom. 19 | 20 | % Author: Hartmut Pohlheim 21 | % History: 28.03.94 file created 22 | 23 | function NewChrom = xovsprs(OldChrom, XOVR); 24 | 25 | if nargin < 2, XOVR = NaN; end 26 | 27 | % call low-level function with appropriate parameters 28 | NewChrom = xovmp(OldChrom, XOVR, 1, 1); 29 | 30 | 31 | % End of function 32 |  -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/plotroc.m: -------------------------------------------------------------------------------- 1 | function result = plotroc(varargin) 2 | %PLOTROC Plot receiver operating characteristic. 3 | % 4 | % Syntax 5 | % 6 | % plotroc(targets,outputs) 7 | % plotroc(targets1,outputs1,'name1',targets,outputs2,'name2', ...) 8 | % 9 | % Description 10 | % 11 | % PLOTROC(TARGETS,OUTPUTS) plots the receiver operating characteristic 12 | % for each output class. The more each curve hugs the left and top edges 13 | % of the plot, the better the classification. 14 | % 15 | % PLOTROC(TARGETS1,OUTPUTS2,'name1',...) generates multiple plots. 16 | % 17 | % Example 18 | % 19 | % load simplecluster_dataset 20 | % net = newpr(simpleclusterInputs,simpleclusterTargets,20); 21 | % net = train(net,simpleclusterInputs,simpleclusterTargets); 22 | % simpleclusterOutputs = sim(net,simpleclusterInputs); 23 | % plotroc(simpleclusterTargets,simpleclusterOutputs); 24 | % 25 | % See also ROC 26 | 27 | % Copyright 2007-2008 The MathWorks, Inc. 28 | 29 | if nargin < 1, error('NNET:Arguments','Not enough input arguments.'); end 30 | 31 | %% Info 32 | if strcmp(varargin{1},'info') 33 | info.name = mfilename; 34 | info.title = 'Receiver Operating Characteristic'; 35 | info.type = 'Plot'; 36 | info.version = 6; 37 | result = info; 38 | return; 39 | end 40 | 41 | if nargin < 1, error('NNET:Arguments','Incorrect number of input arguments.'); end 42 | 43 | %% Plot 44 | v1 = varargin{1}; 45 | if ~isa(varargin{1},'network') 46 | % User arguments - New plot 47 | count = round(nargin/3); 48 | tt = cell(1,count); 49 | yy = cell(1,count); 50 | names = cell(1,count); 51 | for i=1:count 52 | tt{i} = varargin{i*3-2}; 53 | yy{i} = varargin{i*3-1}; 54 | if nargin >= (i*3) 55 | names{i} = varargin{i*3}; 56 | else 57 | names{i} = ''; 58 | end 59 | end 60 | fig = new_figure(''); 61 | elseif (isa(v1,'network') && (nargin == 3)) 62 | [net,tr,signals] = deal(varargin{:}); 63 | tt={}; 64 | yy={}; 65 | names = {}; 66 | for i=1:length(signals) 67 | signal = signals{i}; 68 | if ~isempty(signal.indices) 69 | tt = [tt {signal.T}]; 70 | yy = [yy {signal.Y}]; 71 | names = [names {signal.name}]; 72 | end 73 | end 74 | if length(names) > 1 75 | tt = [tt {cell2mat([tt{:}])}]; 76 | yy = [yy {cell2mat([yy{:}])}]; 77 | names = [names {'All'}]; 78 | end 79 | fig = nn_find_tagged_figure(mfilename); 80 | if isempty(fig) 81 | fig = new_figure(mfilename); 82 | end 83 | end 84 | update_figure(fig,tt,yy,names); 85 | if (nargout > 0), result = fig; end 86 | 87 | %% New Figure 88 | function fig = new_figure(tag) 89 | 90 | fig = figure; 91 | ud.numSignals = 0; 92 | ud.numClasses = 0; 93 | 94 | this = 'plotroc'; 95 | info = feval(this,'info'); 96 | 97 | set(fig,'name',[info.title ' (' this ')']); 98 | set(fig,'menubar','none','toolbar','none','NumberTitle','off'); 99 | set(fig,'tag',tag,'UserData',ud) 100 | 101 | %% Update Figure 102 | function update_figure(fig,tt,yy,names) 103 | 104 | ok = true; 105 | 106 | if ok 107 | plot_figure(fig,tt,yy,names); 108 | else 109 | clear_figure(fig); 110 | end 111 | drawnow 112 | 113 | %% Plot Figure 114 | function plot_figure(fig,tt,yy,names) 115 | 116 | set(0,'CurrentFigure',fig); 117 | ud = get(fig,'userdata'); 118 | 119 | t = tt{1}; if iscell(t), t = cell2mat(t); end 120 | numSignals = length(names); 121 | numClasses = size(t,1); 122 | 123 | % Rebuild figure 124 | if (ud.numSignals ~= numSignals) || (ud.numClasses ~= numClasses) 125 | clf(fig); 126 | set(fig,'nextplot','replace'); 127 | 128 | ud.numSignals = numSignals; 129 | ud.numClasses = numClasses; 130 | ud.axes = zeros(1,numSignals); 131 | 132 | pos = get(fig,'position'); 133 | windowSize = [350*numSignals, 300]; 134 | pos(3:4) = windowSize; 135 | if (ud.numSignals == 0) 136 | screenSize = get(0,'ScreenSize'); 137 | screenSize = screenSize(3:4); 138 | pos(1:2)= (screenSize-windowSize)/2; 139 | end 140 | set(fig,'position',pos); 141 | 142 | colors = {[0 0 1],[0 0.8 0],[1 0 0]}; 143 | 144 | plotcols = ceil(sqrt(numSignals)); 145 | plotrows = ceil(numSignals/plotcols); 146 | 147 | for plotrow=1:plotrows 148 | for plotcol=1:plotcols 149 | i = (plotrow-1)*plotcols+plotcol; 150 | if (i<=numSignals) 151 | 152 | a = subplot(plotrows,plotcols,i); 153 | set(a,'dataaspectratio',[1 1 1]); 154 | set(a,'xlim',[0 1]); 155 | set(a,'ylim',[0 1]); 156 | hold on 157 | 158 | axisdata = []; 159 | axisdata.lines = zeros(1,numClasses); 160 | for j=1:numClasses 161 | c = colors{rem(j-1,length(colors))+1}; 162 | line([0 1],[0 1],'linewidth',2,'color',[1 1 1]*0.8); 163 | axisdata.lines(j) = line([0 1],[0 1],'linewidth',2,'Color',c); 164 | end 165 | 166 | if ~isempty(names{1}) 167 | titleStr = [names{i} ' ROC']; 168 | else 169 | titleStr = 'ROC'; 170 | end 171 | title(a,titleStr); 172 | xlabel(a,'False Positive Rate'); 173 | ylabel(a,'True Positive Rate'); 174 | 175 | ud.axes(i) = a; 176 | set(a,'userdata',axisdata); 177 | end 178 | end 179 | end 180 | 181 | set(fig,'userdata',ud); 182 | set(fig,'nextplot','new'); 183 | 184 | screenSize = get(0,'ScreenSize'); 185 | screenSize = screenSize(3:4); 186 | windowSize = 700 * [1 (plotrows/plotcols)]; 187 | pos = [(screenSize-windowSize)/2 windowSize]; 188 | set(fig,'position',pos); 189 | end 190 | 191 | % Update details 192 | for i=1:numSignals 193 | y = yy{i}; if iscell(y), y = cell2mat(y); end 194 | t = tt{i}; if iscell(t), t = cell2mat(t); end 195 | 196 | [tpr,fpr] = roc(t,y); 197 | if ~iscell(tpr) 198 | tpr = {tpr}; 199 | fpr = {fpr}; 200 | end 201 | 202 | a = ud.axes(i); 203 | axisdata = get(a,'userdata'); 204 | 205 | for j=1:numClasses 206 | set(axisdata.lines(j),'xdata',[0 fpr{j} 1],'ydata',[0 tpr{j} 1]); 207 | end 208 | end 209 | 210 | 211 | %% Clear Figure 212 | function clear_figure(fig) 213 | 214 | ud = get(fig,'userdata'); 215 | set(ud.outputLine,'Xdata',[NaN NaN],'Ydata',[NaN NaN]); 216 | set(ud.targetLine,'Xdata',[NaN NaN],'Ydata',[NaN NaN]); 217 | set(ud.fitLine,'Xdata',[NaN NaN],'Ydata',[NaN NaN]); 218 | set(ud.errorLine,'Xdata',[NaN NaN],'Ydata',[NaN NaN]); 219 | 220 | set(ud.axis,'xlim',[0 1]); 221 | set(ud.axis,'ylim',[0 1]); 222 | set(ud.warning1,'visible','on'); 223 | set(ud.warning2,'visible','on'); 224 | 225 | -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/myprivate/roc.m: -------------------------------------------------------------------------------- 1 | function [tpr,fpr,thresholds] = roc(targets,outputs) 2 | %ROC Receiver operating characteristic. 3 | % 4 | % Syntax 5 | % 6 | % [tpr,fpr,thresholds] = roc(targets,outputs) 7 | % 8 | % Description 9 | % 10 | % The receiver operating characteristic is a metric used to check 11 | % the quality of classifiers. For each class of a classifier, 12 | % threshold values across the interval [0,1] are applied to 13 | % outputs. For each threshold, two values are calculated, the 14 | % True Positive Ratio (the number of outputs greater or equal 15 | % to the threshold, divided by the number of one targets), 16 | % and the False Positive Ratio (the number of outputs less 17 | % then the threshold, divided by the number of zero targets). 18 | % 19 | % The results of this function are often visualized with PLOTROC. 20 | % 21 | % ROC(TARGETS,OUTPUTS) takes these arguments: 22 | % TARGETS - SxQ matrix, where each column vector contains a 23 | % single 1 value, with all other elements 0. The index of the 1 24 | % indicates which of S categories that vector represents. 25 | % OUTPUTS - SxQ matrix, where each column contains values in the 26 | % range [0,1]. The index of the largest element in the column 27 | % indicates which of S categories that vector presents. 28 | % Alternately, 1xQ vector, where values greater or equal to 0.5 29 | % indicate class membership, and values below 0.5, non-membership. 30 | % and returns these values: 31 | % TPR - Sx1 cell array of 1xN true-positive/positive ratios. 32 | % FPR - Sx1 cell array of 1xN false-positive/negative ratios. 33 | % THRESHOLDS - Sx1 cell array of 1xN thresholds over interval [0,1]. 34 | % 35 | % ROC(TARGETS,OUTPUTS) takes these arguments: 36 | % TARGETS - 1xQ matrix, of boolean values indicating class membership. 37 | % OUTPUTS - SxQ matrix, of value in [0.1] interval, where values 38 | % greater-or-equal to 0.5 indicate class membership. 39 | % and returns these values: 40 | % TPR - 1xN vector of true-positive/positive ratios. 41 | % FPR - 1xN vector of false-positive/negative ratios. 42 | % THRESHOLDS - 1xN vector of thresholds over interval [0,1]. 43 | % 44 | % Example 45 | % 46 | % load iris_dataset 47 | % net = newpr(irisInputs,irisTargets,20); 48 | % net = train(net,irisInputs,irisTargets); 49 | % irisOutputs = sim(net,irisInputs); 50 | % [tpr,fpr,thresholds] = roc(irisTargets,irisOutputs) 51 | % 52 | % See also PLOTROC, CONFUSION 53 | 54 | % Copyright 2007-2008 The MathWorks, Inc. 55 | 56 | if nargin < 2, error('NNET:Arguments','Not enough input arguments.'); end 57 | 58 | [numClasses,numSamples] = size(targets); 59 | [numClasses2,numSamples2] = size(outputs); 60 | if any([numClasses,numSamples] ~= [numClasses2,numSamples2]) 61 | error('NNET:Arguments','Targets and outputs have different dimensions.'); 62 | end 63 | 64 | if (numClasses == 1) 65 | targets = [targets; 1-targets]; 66 | outputs = [outputs; 1-outputs-eps*(outputs==0.5)]; 67 | [tpr,fpr,thresholds] = roc(targets,outputs); 68 | tpr = tpr{1}; 69 | fpr = fpr{1}; 70 | thresholds = thresholds{1}; 71 | return; 72 | end 73 | 74 | fpr = cell(1,numClasses); 75 | tpr = cell(1,numClasses); 76 | thresholds = cell(1,numClasses); 77 | 78 | for i=1:numClasses 79 | [tpr{i},fpr{i},thresholds{i}] = roc_one(targets(i,:),outputs(i,:)); 80 | end 81 | 82 | %% 83 | function [tpr,fpr,thresholds] = roc_one(targets,outputs) 84 | 85 | numSamples = length(targets); 86 | numPositiveTargets = sum(targets); 87 | numNegativeTargets = numSamples-numPositiveTargets; 88 | 89 | thresholds = unique([0 outputs 1]); 90 | numThresholds = length(thresholds); 91 | 92 | sortedPosTargetOutputs = sort(outputs(targets == 1)); 93 | numPosTargetOutputs = length(sortedPosTargetOutputs); 94 | sortedNegTargetOutputs = sort(outputs(targets == 0)); 95 | numNegTargetOutputs = length(sortedNegTargetOutputs); 96 | 97 | fpcount = zeros(1,numThresholds); 98 | tpcount = zeros(1,numThresholds); 99 | 100 | posInd = 1; 101 | negInd = 1; 102 | for i=1:numThresholds 103 | threshold = thresholds(i); 104 | while (posInd <= numPosTargetOutputs) && (sortedPosTargetOutputs(posInd) <= threshold) 105 | posInd = posInd + 1; 106 | end 107 | tpcount(i) = numPosTargetOutputs + 1 - posInd; 108 | while (negInd <= numNegTargetOutputs) && (sortedNegTargetOutputs(negInd) <= threshold) 109 | negInd = negInd + 1; 110 | end 111 | fpcount(i) = numNegTargetOutputs + 1 - negInd; 112 | end 113 | 114 | tpr = fliplr(tpcount) ./ numPositiveTargets; 115 | fpr = fliplr(fpcount) ./ numNegativeTargets; 116 | -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/pcaForSVM.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/pcaForSVM.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/psoSVMcgForClass.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/psoSVMcgForClass.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/psoSVMcgForRegress.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/psoSVMcgForRegress.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/readme[by faruto].txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/readme[by faruto].txt -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/scaleForSVM.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/scaleForSVM.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/svmplot.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/svmplot.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/test_for_ica_SVM.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/implement[by faruto]/test_for_ica_SVM.m -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/libsvm 参数说明.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/libsvm 参数说明.txt -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/libsvmread.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "mex.h" 8 | 9 | #if MX_API_VER < 0x07030000 10 | typedef int mwIndex; 11 | #endif 12 | #define max(x,y) (((x)>(y))?(x):(y)) 13 | #define min(x,y) (((x)<(y))?(x):(y)) 14 | 15 | void exit_with_help() 16 | { 17 | mexPrintf( 18 | "Usage: [label_vector, instance_matrix] = libsvmread('filename');\n" 19 | ); 20 | } 21 | 22 | static void fake_answer(mxArray *plhs[]) 23 | { 24 | plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL); 25 | plhs[1] = mxCreateDoubleMatrix(0, 0, mxREAL); 26 | } 27 | 28 | static char *line; 29 | static int max_line_len; 30 | 31 | static char* readline(FILE *input) 32 | { 33 | int len; 34 | 35 | if(fgets(line,max_line_len,input) == NULL) 36 | return NULL; 37 | 38 | while(strrchr(line,'\n') == NULL) 39 | { 40 | max_line_len *= 2; 41 | line = (char *) realloc(line, max_line_len); 42 | len = (int) strlen(line); 43 | if(fgets(line+len,max_line_len-len,input) == NULL) 44 | break; 45 | } 46 | return line; 47 | } 48 | 49 | // read in a problem (in libsvm format) 50 | void read_problem(const char *filename, mxArray *plhs[]) 51 | { 52 | int max_index, min_index, inst_max_index, i; 53 | long elements, k; 54 | FILE *fp = fopen(filename,"r"); 55 | int l = 0; 56 | char *endptr; 57 | mwIndex *ir, *jc; 58 | double *labels, *samples; 59 | 60 | if(fp == NULL) 61 | { 62 | mexPrintf("can't open input file %s\n",filename); 63 | fake_answer(plhs); 64 | return; 65 | } 66 | 67 | max_line_len = 1024; 68 | line = (char *) malloc(max_line_len*sizeof(char)); 69 | 70 | max_index = 0; 71 | min_index = 1; // our index starts from 1 72 | elements = 0; 73 | while(readline(fp) != NULL) 74 | { 75 | char *idx, *val; 76 | // features 77 | int index = 0; 78 | 79 | inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel has start from 0 80 | strtok(line," \t"); // label 81 | while (1) 82 | { 83 | idx = strtok(NULL,":"); // index:value 84 | val = strtok(NULL," \t"); 85 | if(val == NULL) 86 | break; 87 | 88 | errno = 0; 89 | index = (int) strtol(idx,&endptr,10); 90 | if(endptr == idx || errno != 0 || *endptr != '\0' || index <= inst_max_index) 91 | { 92 | mexPrintf("Wrong input format at line %d\n",l+1); 93 | fake_answer(plhs); 94 | return; 95 | } 96 | else 97 | inst_max_index = index; 98 | 99 | min_index = min(min_index, index); 100 | elements++; 101 | } 102 | max_index = max(max_index, inst_max_index); 103 | l++; 104 | } 105 | rewind(fp); 106 | 107 | // y 108 | plhs[0] = mxCreateDoubleMatrix(l, 1, mxREAL); 109 | // x^T 110 | if (min_index <= 0) 111 | plhs[1] = mxCreateSparse(max_index-min_index+1, l, elements, mxREAL); 112 | else 113 | plhs[1] = mxCreateSparse(max_index, l, elements, mxREAL); 114 | 115 | labels = mxGetPr(plhs[0]); 116 | samples = mxGetPr(plhs[1]); 117 | ir = mxGetIr(plhs[1]); 118 | jc = mxGetJc(plhs[1]); 119 | 120 | k=0; 121 | for(i=0;i start from 0 146 | 147 | errno = 0; 148 | samples[k] = strtod(val,&endptr); 149 | if (endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr))) 150 | { 151 | mexPrintf("Wrong input format at line %d\n",i+1); 152 | fake_answer(plhs); 153 | return; 154 | } 155 | ++k; 156 | } 157 | } 158 | jc[l] = k; 159 | 160 | fclose(fp); 161 | free(line); 162 | 163 | { 164 | mxArray *rhs[1], *lhs[1]; 165 | rhs[0] = plhs[1]; 166 | if(mexCallMATLAB(1, lhs, 1, rhs, "transpose")) 167 | { 168 | mexPrintf("Error: cannot transpose problem\n"); 169 | fake_answer(plhs); 170 | return; 171 | } 172 | plhs[1] = lhs[0]; 173 | } 174 | } 175 | 176 | void mexFunction( int nlhs, mxArray *plhs[], 177 | int nrhs, const mxArray *prhs[] ) 178 | { 179 | if(nrhs == 1) 180 | { 181 | char filename[256]; 182 | 183 | mxGetString(prhs[0], filename, mxGetN(prhs[0]) + 1); 184 | 185 | if(filename == NULL) 186 | { 187 | mexPrintf("Error: filename is NULL\n"); 188 | return; 189 | } 190 | 191 | read_problem(filename, plhs); 192 | } 193 | else 194 | { 195 | exit_with_help(); 196 | fake_answer(plhs); 197 | return; 198 | } 199 | } 200 | 201 | -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/libsvmread.mexw32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vonsylvia/MATLAB_Algorithm_with_cases/646e51a377568889f48b8fdebbc44f0a2514048a/支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/libsvmread.mexw32 -------------------------------------------------------------------------------- /支持向量机分类——基于乳腺组织电阻抗特性的乳腺癌诊断/libsvm-mat-2[1].89-3[FarutoUltimate3.0Mcode]/libsvmwrite.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "mex.h" 5 | 6 | #if MX_API_VER < 0x07030000 7 | typedef int mwIndex; 8 | #endif 9 | 10 | void exit_with_help() 11 | { 12 | mexPrintf( 13 | "Usage: libsvmwrite('filename', label_vector, instance_matrix);\n" 14 | ); 15 | } 16 | 17 | void libsvmwrite(const char *filename, const mxArray *label_vec, const mxArray *instance_mat) 18 | { 19 | FILE *fp = fopen(filename,"w"); 20 | int i, k, low, high, l; 21 | mwIndex *ir, *jc; 22 | int label_vector_row_num; 23 | double *samples, *labels; 24 | mxArray *instance_mat_col; // instance sparse matrix in column format 25 | 26 | if(fp ==NULL) 27 | { 28 | mexPrintf("can't open output file %s\n",filename); 29 | return; 30 | } 31 | 32 | // transpose instance matrix 33 | { 34 | mxArray *prhs[1], *plhs[1]; 35 | prhs[0] = mxDuplicateArray(instance_mat); 36 | if(mexCallMATLAB(1, plhs, 1, prhs, "transpose")) 37 | { 38 | mexPrintf("Error: cannot transpose instance matrix\n"); 39 | return; 40 | } 41 | instance_mat_col = plhs[0]; 42 | mxDestroyArray(prhs[0]); 43 | } 44 | 45 | // the number of instance 46 | l = (int) mxGetN(instance_mat_col); 47 | label_vector_row_num = (int) mxGetM(label_vec); 48 | 49 | if(label_vector_row_num!=l) 50 | { 51 | mexPrintf("Length of label vector does not match # of instances.\n"); 52 | return; 53 | } 54 | 55 | // each column is one instance 56 | labels = mxGetPr(label_vec); 57 | samples = mxGetPr(instance_mat_col); 58 | ir = mxGetIr(instance_mat_col); 59 | jc = mxGetJc(instance_mat_col); 60 | 61 | for(i=0;i