一、神经网络-支持向量机
支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本、非线性及高维模式识别中表现出许多特有的优势,并能够推广应用到函数拟合等其他机器学习问题中。 1 数学部分 1.1 二维空间
2 算法部分
二、风驱动算法
WDO算法的实现流程:
1) 初始化空气质点的个数和维度,定义最大迭代次数和相关的参数常量,设置搜索边界(位置和速度),设置相应的测试函数。
2) 随机初始化各个质点的初始信息(位置和速度),计算初始的压力值并根据压力值的大小升序排列。
3) 开始迭代。更新空气质点的速度和位置,计算质点压力值并以升序方式重新排列种群顺序。
4) 迭代终止。判断是否满足终止条件,如果不满足就返回步骤3),否则就终止迭代,最后搜索到的最优位置就是最优解。
三、代码
tic;
clear;
close all;
clc;
format long g;
delete('WDOoutput.txt');
delete('WDOpressure.txt');
delete('WDOposition.txt');
fid=fopen('WDOoutput.txt','a');
%--------------------------------------------------------------
% User defined WDO parameters:
param.popsize = 20; % population size.
param.npar = 5; % Dimension of the problem.
param.maxit = 500; % Maximum number of iterations.
param.RT = 3; % RT coefficient.
param.g = 0.2; % gravitational constant.
param.alp = 0.4; % constants in the update eq.
param.c = 0.4; % coriolis effect.
maxV = 0.3; % maximum allowed speed.
dimMin = -5; % Lower dimension boundary.
dimMax= 5; % Upper dimension boundary.
%---------------------------------------------------------------
% Initialize WDO population, position and velocity:
% Randomize population in the range of [-1, 1]:
pos = 2*(rand(param.popsize,param.npar)-0.5);
% Randomize velocity:
vel = maxV * 2 * (rand(param.popsize,param.npar)-0.5);
%---------------------------------------------------------------
% Evaluate initial population: (Sphere Function)
for K=1:param.popsize,
x = (dimMax - dimMin) * ((pos(K,:)+1)./2) + dimMin;
pres(K,:) = sum (x.^2);
end
%----------------------------------------------------------------
% Finding best air parcel in the initial population :
[globalpres,indx] = min(pres);
globalpos = pos(indx,:);
minpres(1) = min(pres); % minimum pressure
%-----------------------------------------------------------------
% Rank the air parcels:
[sorted_pres rank_ind] = sort(pres);
% Sort the air parcels:
pos = pos(rank_ind,:);
keepglob(1) = globalpres;
%-----------------------------------------------------------------
% Start iterations :
iter = 1; % iteration counter
for ij = 2:param.maxit,
% Update the velocity:
for i=1:param.popsize
% choose random dimensions:
a = randperm(param.npar);
% choose velocity based on random dimension:
velot(i,:) = vel(i,a);
vel(i,:) = (1-param.alp)*vel(i,:)-(param.g*pos(i,:))+ ...
abs(1-1/i)*((globalpos-pos(i,:)).*param.RT)+ ...
(param.c*velot(i,:)/i);
end
% Check velocity:
vel = min(vel, maxV);
vel = max(vel, -maxV);
% Update air parcel positions:
pos = pos + vel;
pos = min(pos, 1.0);
pos = max(pos, -1.0);
% Evaluate population: (Pressure)
for K=1:param.popsize,
x = (dimMax - dimMin) * ((pos(K,:)+1)./2) + dimMin;
pres(K,:) = sum (x.^2);
end
%----------------------------------------------------
% Finding best particle in population
[minpres,indx] = min(pres);
minpos = pos(indx,:); % min location for this iteration
%----------------------------------------------------
% Rank the air parcels:
[sorted_pres rank_ind] = sort(pres);
% Sort the air parcels position, velocity and pressure:
pos = pos(rank_ind,:);
vel = vel(rank_ind,:);
pres = sorted_pres;
% Updating the global best:
better = minpres < globalpres;
if better
globalpres = minpres % initialize global minimum
globalpos = minpos;
end
% Keep a record of the progress:
keepglob(ij) = globalpres;
save WDOposition.txt pos -ascii -tabs;
end
%Save values to the final file.
pressure = transpose(keepglob);
save WDOpressure.txt pressure -ascii -tabs;
%END
%-----------------------------------------------------
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
5.参考文献:
书籍《MATLAB神经网络43个案例分析