基于鸽群算法优化最小二乘支持向量机lssvm实现预测附matlab代码

简介: 基于鸽群算法优化最小二乘支持向量机lssvm实现预测附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法  神经网络预测雷达通信 无线传感器

信号处理图像处理路径规划元胞自动机无人机

⛄ 内容介绍

短时交通流预测是实现智能交通控制与管理,交通流状态辨识和实时交通流诱导的前提及关键,也是智能化交通管理的客观需要.到目前为止,它的研究结果都不尽如人意.现有的以精确数学模型为基础的传统预测方法存在计算复杂,运算时间长,需要大量历史数据,预测精度不高等缺点.因此通过研究新型人工智能方法改进短期交通流预测具有一定的现实意义.本文在对现有短期交通流预测模型对比分析及交通流特性研究分析基础上,采用鸽群算法优化最小二乘支持向量机方法进行短期交通流预测模型,取得较好的效果. 支持向量机是一种新的机器学习算法,建立在统计学习理论的基础上,采用结构风险最小化原则,具有预测能力强,全局最优化以及收敛速度快等特点,相比较以经验风险化为基础的神经网络学习算法有更好的理论依据和更好的泛化性能.对于支持向量机模型而言,其算法相对简单,运算时间短,预测精度较高,比较适用于交通流预测研究,特别是在引入最小二乘理论后,计算简化为求解一个线性方程组,同时精度也能得到保证.,该方法首先利用鸽群算法的全局搜索能力来获取最小二乘支持向量机的惩罚因子和核函数宽度,有效解决了最小二乘支持向量机难以快速精准寻找最优参数的问题.

⛄ 部分代码

function [model,Yt] = prelssvm(model,Xt,Yt)

% Preprocessing of the LS-SVM

%

% These functions should only be called by trainlssvm or by

% simlssvm. At first the preprocessing assigns a label to each in-

% and output component (c for continuous, a for categorical or b

% for binary variables). According to this label each dimension is rescaled:

%

%     * continuous: zero mean and unit variance

%     * categorical: no preprocessing

%     * binary: labels -1 and +1

%

% Full syntax (only using the object oriented interface):

%

% >> model   = prelssvm(model)

% >> Xp = prelssvm(model, Xt)

% >> [empty, Yp] = prelssvm(model, [], Yt)

% >> [Xp, Yp] = prelssvm(model, Xt, Yt)

%

%       Outputs    

%         model : Preprocessed object oriented representation of the LS-SVM model

%         Xp    : Nt x d matrix with the preprocessed inputs of the test data

%         Yp    : Nt x d matrix with the preprocessed outputs of the test data

%       Inputs    

%         model : Object oriented representation of the LS-SVM model

%         Xt    : Nt x d matrix with the inputs of the test data to preprocess

%         Yt    : Nt x d matrix with the outputs of the test data to preprocess


% Copyright (c) 2011,  KULeuven-ESAT-SCD, License & help @ http://www.esat.kuleuven.be/sista/lssvmlab


if model.preprocess(1)~='p', % no 'preprocessing

 if nargin>=2, model = Xt;  end

 return

end

% what to do

%

if model.preprocess(1)=='p',

 eval('if model.prestatus(1)==''c'',model.prestatus=''unschemed'';end','model.prestatus=''unschemed'';');

end  

if nargin==1, % only model rescaling

 %

 % if UNSCHEMED, redefine a rescaling

 %

 if model.prestatus(1)=='u',% 'unschemed'

   ffx =[];

   for i=1:model.x_dim,

     eval('ffx = [ffx model.pre_xscheme(i)];',...

  'ffx = [ffx signal_type(model.xtrain(:,i),inf)];');

   end

   model.pre_xscheme = ffx;

 

   ff = [];

   for i=1:model.y_dim,

     eval('ff = [ff model.pre_yscheme(i)];',...

  'ff = [ff signal_type(model.ytrain(:,i),model.type)];');

   end

   model.pre_yscheme = ff;

   model.prestatus='schemed';

 end

 

 %

 % execute rescaling as defined if not yet CODED

 %

 if model.prestatus(1)=='s',% 'schemed'  

   model=premodel(model);

   model.prestatus = 'ok';

 end

 

 %

 % rescaling of the to simulate inputs

 %

elseif model.preprocess(1)=='p'

 if model.prestatus(1)=='o',%'ok'

   eval('Yt;','Yt=[];');

   [model,Yt] = premodel(model,Xt,Yt);

 else

   warning('model rescaling inconsistent..redo ''model=prelssvm(model);''..');

 end

end






function [type,ss] = signal_type(signal,type)

%

% determine the type of the signal,

% binary classifier ('b'), categorical classifier ('a'), or continuous

% signal ('c')

%

%

ss = sort(signal);

dif = sum(ss(2:end)~=ss(1:end-1))+1;

% binary

if dif==2,

 type = 'b';


% categorical

elseif dif<sqrt(length(signal)) || type(1)== 'c',

 type='a';


% continu

else

 type ='c';

end

 





%

% effective rescaling

%

function [model,Yt] = premodel(model,Xt,Yt)

%

%

%


if nargin==1,


 for i=1:model.x_dim,

   % CONTINUOUS VARIABLE:

   if model.pre_xscheme(i)=='c',

     model.pre_xmean(i)=mean(model.xtrain(:,i));

     model.pre_xstd(i) = std(model.xtrain(:,i));

     model.xtrain(:,i) = pre_zmuv(model.xtrain(:,i),model.pre_xmean(i),model.pre_xstd(i));

     % CATEGORICAL VARIBALE:

   elseif model.pre_xscheme(i)=='a',

     model.pre_xmean(i)= 0;

     model.pre_xstd(i) = 0;

     model.xtrain(:,i) = pre_cat(model.xtrain(:,i),model.pre_xmean(i),model.pre_xstd(i));

     % BINARY VARIBALE:

   elseif model.pre_xscheme(i)=='b',      

     model.pre_xmean(i) = min(model.xtrain(:,i));

     model.pre_xstd(i) = max(model.xtrain(:,i));

     model.xtrain(:,i) = pre_bin(model.xtrain(:,i),model.pre_xmean(i),model.pre_xstd(i));

   end  

 end

 

 for i=1:model.y_dim,

   % CONTINUOUS VARIABLE:

   if model.pre_yscheme(i)=='c',

     model.pre_ymean(i)=mean(model.ytrain(:,i),1);

     model.pre_ystd(i) = std(model.ytrain(:,i),1);

     model.ytrain(:,i) = pre_zmuv(model.ytrain(:,i),model.pre_ymean(i),model.pre_ystd(i));

   % CATEGORICAL VARIBALE:

   elseif model.pre_yscheme(i)=='a',      

     model.pre_ymean(i)=0;

     model.pre_ystd(i) =0;

     model.ytrain(:,i) = pre_cat(model.ytrain(:,i),model.pre_ymean(i),model.pre_ystd(i));

   % BINARY VARIBALE:

   elseif model.pre_yscheme(i)=='b',      

     model.pre_ymean(i) = min(model.ytrain(:,i));

     model.pre_ystd(i) = max(model.ytrain(:,i));

     model.ytrain(:,i) = pre_bin(model.ytrain(:,i),model.pre_ymean(i),model.pre_ystd(i));

   end  

 end


else %if nargin>1, % testdata Xt,

 if ~isempty(Xt),

   if size(Xt,2)~=model.x_dim, warning('dimensions of Xt not compatible with dimensions of support vectors...');end

   for i=1:model.x_dim,

     % CONTINUOUS VARIABLE:

     if model.pre_xscheme(i)=='c',

Xt(:,i) = pre_zmuv(Xt(:,i),model.pre_xmean(i),model.pre_xstd(i));

     % CATEGORICAL VARIBALE:

     elseif model.pre_xscheme(i)=='a',

Xt(:,i) = pre_cat(Xt(:,i),model.pre_xmean(i),model.pre_xstd(i));

     % BINARY VARIBALE:

     elseif model.pre_xscheme(i)=='b',      

Xt(:,i) = pre_bin(Xt(:,i),model.pre_xmean(i),model.pre_xstd(i));

     end  

   end

 end

 

 if nargin>2 & ~isempty(Yt),

   if size(Yt,2)~=model.y_dim, warning('dimensions of Yt not compatible with dimensions of training output...');end

   for i=1:model.y_dim,

     % CONTINUOUS VARIABLE:

     if model.pre_yscheme(i)=='c',

Yt(:,i) = pre_zmuv(Yt(:,i),model.pre_ymean(i), model.pre_ystd(i));

     % CATEGORICAL VARIBALE:

     elseif model.pre_yscheme(i)=='a',      

Yt(:,i) = pre_cat(Yt(:,i),model.pre_ymean(i),model.pre_ystd(i));

     % BINARY VARIBALE:

     elseif model.pre_yscheme(i)=='b',      

Yt(:,i) = pre_bin(Yt(:,i),model.pre_ymean(i),model.pre_ystd(i));

     end

   end

 end

 

 % assign output

 model=Xt;

end



function X = pre_zmuv(X,mean,var)

%

% preprocessing a continuous signal; rescaling to zero mean and unit

% variance

% 'c'

%

X = (X-mean)./var;

function X = pre_cat(X,mean,range)

%

% preprocessing a categorical signal;

% 'a'

%

X=X;

function X = pre_bin(X,min,max)

%

% preprocessing a binary signal;

% 'b'

%

if ~sum(isnan(X)) >= 1 %--> OneVsOne encoding

   n = (X==min);

   p = not(n);

   X=-1.*(n)+p;

end

⛄ 运行结果

⛄ 参考文献

[1]刘林. 基于LSSVM的短期交通流预测研究与应用[D]. 西南交通大学,2011.

❤️ 关注我领取海量matlab电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除


相关文章
|
19小时前
|
机器学习/深度学习 算法 API
【Paddle】PCA线性代数基础 + 领域应用:人脸识别算法(1.1w字超详细:附公式、代码)
【Paddle】PCA线性代数基础 + 领域应用:人脸识别算法(1.1w字超详细:附公式、代码)
6 0
|
4天前
|
算法 关系型数据库 C语言
卡尔曼滤波简介+ 算法实现代码(转)
卡尔曼滤波简介+ 算法实现代码(转)
16 4
|
5天前
|
数据安全/隐私保护
地震波功率谱密度函数、功率谱密度曲线,反应谱转功率谱,matlab代码
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
5天前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)
|
3天前
|
算法 数据安全/隐私保护 计算机视觉
基于二维CS-SCHT变换和LABS方法的水印嵌入和提取算法matlab仿真
该内容包括一个算法的运行展示和详细步骤,使用了MATLAB2022a。算法涉及水印嵌入和提取,利用LAB色彩空间可能用于隐藏水印。水印通过二维CS-SCHT变换、低频系数处理和特定解码策略来提取。代码段展示了水印置乱、图像处理(如噪声、旋转、剪切等攻击)以及水印的逆置乱和提取过程。最后,计算并保存了比特率,用于评估水印的稳健性。
|
4天前
|
存储 算法 数据可视化
基于harris角点和RANSAC算法的图像拼接matlab仿真
本文介绍了使用MATLAB2022a进行图像拼接的流程,涉及Harris角点检测和RANSAC算法。Harris角点检测寻找图像中局部曲率变化显著的点,RANSAC则用于排除噪声和异常点,找到最佳匹配。核心程序包括自定义的Harris角点计算函数,RANSAC参数设置,以及匹配点的可视化和仿射变换矩阵计算,最终生成全景图像。
|
4天前
|
算法 Serverless
m基于遗传优化的LDPC码NMS译码算法最优归一化参数计算和误码率matlab仿真
MATLAB 2022a仿真实现了遗传优化的归一化最小和(NMS)译码算法,应用于低密度奇偶校验(LDPC)码。结果显示了遗传优化的迭代过程和误码率对比。遗传算法通过选择、交叉和变异操作寻找最佳归一化因子,以提升NMS译码性能。核心程序包括迭代优化、目标函数计算及性能绘图。最终,展示了SNR与误码率的关系,并保存了关键数据。
13 1
|
5天前
|
算法 调度
考虑需求响应的微网优化调度模型【粒子群算法】【matlab】
考虑需求响应的微网优化调度模型【粒子群算法】【matlab】
|
5天前
|
运维 算法
基于改进遗传算法的配电网故障定位(matlab代码)
基于改进遗传算法的配电网故障定位(matlab代码)

热门文章

最新文章