✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
短时交通流预测是实现智能交通控制与管理,交通流状态辨识和实时交通流诱导的前提及关键,也是智能化交通管理的客观需要.到目前为止,它的研究结果都不尽如人意.现有的以精确数学模型为基础的传统预测方法存在计算复杂,运算时间长,需要大量历史数据,预测精度不高等缺点.因此通过研究新型人工智能方法改进短期交通流预测具有一定的现实意义.本文在对现有短期交通流预测模型对比分析及交通流特性研究分析基础上,采用萤火虫算法优化最小二乘支持向量机方法进行短期交通流预测模型,取得较好的效果. 支持向量机是一种新的机器学习算法,建立在统计学习理论的基础上,采用结构风险最小化原则,具有预测能力强,全局最优化以及收敛速度快等特点,相比较以经验风险化为基础的神经网络学习算法有更好的理论依据和更好的泛化性能.对于支持向量机模型而言,其算法相对简单,运算时间短,预测精度较高,比较适用于交通流预测研究,特别是在引入最小二乘理论后,计算简化为求解一个线性方程组,同时精度也能得到保证.,该方法首先利用萤火虫算法算法的全局搜索能力来获取最小二乘支持向量机的惩罚因子和核函数宽度,有效解决了最小二乘支持向量机难以快速精准寻找最优参数的问题.
⛄ 部分代码
function omega = kernel_matrix(Xtrain,kernel_type, kernel_pars,Xt)
% Construct the positive (semi-) definite and symmetric kernel matrix
%
% >> Omega = kernel_matrix(X, kernel_fct, sig2)
%
% This matrix should be positive definite if the kernel function
% satisfies the Mercer condition. Construct the kernel values for
% all test data points in the rows of Xt, relative to the points of X.
%
% >> Omega_Xt = kernel_matrix(X, kernel_fct, sig2, Xt)
%
%
% Full syntax
%
% >> Omega = kernel_matrix(X, kernel_fct, sig2)
% >> Omega = kernel_matrix(X, kernel_fct, sig2, Xt)
%
% Outputs
% Omega : N x N (N x Nt) kernel matrix
% Inputs
% X : N x d matrix with the inputs of the training data
% kernel : Kernel type (by default 'RBF_kernel')
% sig2 : Kernel parameter (bandwidth in the case of the 'RBF_kernel')
% Xt(*) : Nt x d matrix with the inputs of the test data
%
% See also:
% RBF_kernel, lin_kernel, kpca, trainlssvm, kentropy
% Copyright (c) 2011, KULeuven-ESAT-SCD, License & help @ http://www.esat.kuleuven.be/sista/lssvmlab
[nb_data,d] = size(Xtrain);
if strcmp(kernel_type,'RBF_kernel'),
if nargin<4,
XXh = sum(Xtrain.^2,2)*ones(1,nb_data);
omega = XXh+XXh'-2*(Xtrain*Xtrain');
omega = exp(-omega./(2*kernel_pars(1)));
else
XXh1 = sum(Xtrain.^2,2)*ones(1,size(Xt,1));
XXh2 = sum(Xt.^2,2)*ones(1,nb_data);
omega = XXh1+XXh2' - 2*Xtrain*Xt';
omega = exp(-omega./(2*kernel_pars(1)));
end
elseif strcmp(kernel_type,'RBF4_kernel'),
if nargin<4,
XXh = sum(Xtrain.^2,2)*ones(1,nb_data);
omega = XXh+XXh'-2*(Xtrain*Xtrain');
omega = 0.5*(3-omega./kernel_pars).*exp(-omega./(2*kernel_pars(1)));
else
XXh1 = sum(Xtrain.^2,2)*ones(1,size(Xt,1));
XXh2 = sum(Xt.^2,2)*ones(1,nb_data);
omega = XXh1+XXh2' - 2*Xtrain*Xt';
omega = 0.5*(3-omega./kernel_pars).*exp(-omega./(2*kernel_pars(1)));
end
% elseif strcmp(kernel_type,'sinc_kernel'),
% if nargin<4,
% omega = sum(Xtrain,2)*ones(1,size(Xtrain,1));
% omega = omega - omega';
% omega = sinc(omega./kernel_pars(1));
% else
% XXh1 = sum(Xtrain,2)*ones(1,size(Xt,1));
% XXh2 = sum(Xt,2)*ones(1,nb_data);
% omega = XXh1-XXh2';
% omega = sinc(omega./kernel_pars(1));
% end
elseif strcmp(kernel_type,'lin_kernel')
if nargin<4,
omega = Xtrain*Xtrain';
else
omega = Xtrain*Xt';
end
elseif strcmp(kernel_type,'poly_kernel')
if nargin<4,
omega = (Xtrain*Xtrain'+kernel_pars(1)).^kernel_pars(2);
else
omega = (Xtrain*Xt'+kernel_pars(1)).^kernel_pars(2);
end
% elseif strcmp(kernel_type,'wav_kernel')
% if nargin<4,
% XXh = sum(Xtrain.^2,2)*ones(1,nb_data);
% omega = XXh+XXh'-2*(Xtrain*Xtrain');
%
% XXh1 = sum(Xtrain,2)*ones(1,nb_data);
% omega1 = XXh1-XXh1';
% omega = cos(kernel_pars(3)*omega1./kernel_pars(2)).*exp(-omega./kernel_pars(1));
%
% else
% XXh1 = sum(Xtrain.^2,2)*ones(1,size(Xt,1));
% XXh2 = sum(Xt.^2,2)*ones(1,nb_data);
% omega = XXh1+XXh2' - 2*(Xtrain*Xt');
%
% XXh11 = sum(Xtrain,2)*ones(1,size(Xt,1));
% XXh22 = sum(Xt,2)*ones(1,nb_data);
% omega1 = XXh11-XXh22';
%
% omega = cos(kernel_pars(3)*omega1./kernel_pars(2)).*exp(-omega./kernel_pars(1));
% end
end
⛄ 运行结果
⛄ 参考文献
[1]刘林. 基于LSSVM的短期交通流预测研究与应用[D]. 西南交通大学, 2011.