资源简介
用粒子群算法优化支持向量机的matlab程序,用于对股价、经济的预测作用,优化后预测精确
代码片段和文件信息
%% 清空环境
clc
clear
load wine;
train = [wine(1:30:);wine(60:95:);wine(131:153:)];
train_label = [wine_labels(1:30);wine_labels(60:95);wine_labels(131:153)];
test = [wine(31:59:);wine(96:130:);wine(154:178:)];
test_label = [wine_labels(31:59);wine_labels(96:130);wine_labels(154:178)];
[trainpstrain] = mapminmax(train‘);
pstrain.ymin = 0;
pstrain.ymax = 1;
[trainpstrain] = mapminmax(trainpstrain);
[testpstest] = mapminmax(test‘);
pstest.ymin = 0;
pstest.ymax = 1;
[testpstest] = mapminmax(testpstest);
train = train‘;
test = test‘;
%% 参数初始化
%粒子群算法中的两个参数
c1 = 1.6; % c1 belongs to [02]
c2 = 1.5; % c2 belongs to [02]
maxgen=300; % 进化次数
sizepop=30; % 种群规模
popcmax=10^(2);
popcmin=10^(-1);
popgmax=10^(3);
popgmin=10^(-2);
k = 0.6; % k belongs to [0.11.0];
Vcmax = k*popcmax;
Vcmin = -Vcmax ;
Vgmax = k*popgmax;
Vgmin = -Vgmax ;
% SVM参数初始化
v = 3;
%% 产生初始粒子和速度
for i=1:sizepop
% 随机产生种群
pop(i1) = (popcmax-popcmin)*rand+popcmin; % 初始种群
pop(i2) = (popgmax-popgmin)*rand+popgmin;
V(i1)=Vcmax*rands(1); % 初始化速度
V(i2)=Vgmax*rands(1);
% 计算初始适应度
cmd = [‘-v ‘num2str(v)‘ -c ‘num2str( pop(i1) )‘ -g ‘num2str( pop(i2) )];
fitness(i) = svmtrain(train_label train cmd);
fitness(i) = -fitness(i);
end
% 找极值和极值点
[global_fitness bestindex]=min(fitness); % 全局极值
local_fitness=fitness; % 个体极值初始化
global_x=pop(bestindex:); % 全局极值点
local_x=pop; % 个体极值点初始化
tic
%% 迭代寻优
for i=1:maxgen
for j=1:sizepop
%速度更新
wV = 0.9; % wV best belongs to [0.81.2]
V(j:) = wV*V(j:) + c1*rand*(local_x(j:) - pop(j:)) + c2*rand*(global_x - pop(j:));
if V(j1) > Vcmax
V(j1) = Vcmax;
end
if V(j1) < Vcmin
V(j1) = Vcmin;
end
- 上一篇:局部粒子群算法
- 下一篇:基于Pluto点对点通信系统设计matlab源码
相关资源
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
- k近邻算法matlab实现
- matlab识别系统
评论
共有 条评论