基于鸽群算法优化最小二乘支持向量机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电子书和数学建模资料

❤️部分理论引用网络文献,若有侵权联系博主删除

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值