# 【lssvm回归预测】基于萤火虫算法优化最小二乘支持向量机lssvm实现数据回归预测附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

%

%  RBF_kernel, lin_kernel, kpca, trainlssvm, kentropy

[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.

## ⛄ Matlab代码关注

##### ❤️ 关注我领取海量matlab电子书和数学建模资料

|
1天前
|

m基于PSO-LSTM粒子群优化长短记忆网络的电力负荷数据预测算法matlab仿真

16 6
|
1天前
|

**摘要:** 实现变异混合蛙跳算法的MATLAB2022a版车间调度优化程序，支持动态调整工件和机器数，输出甘特图。核心算法结合SFLA与变异策略，解决Job-Shop Scheduling Problem，最小化总完成时间。SFLA模拟蛙群行为，分组进行局部搜索和全局信息交换。变异策略增强全局探索，避免局部最优。程序初始化随机解，按规则更新，经多次迭代和信息交换后终止。
16 1
|
22小时前
|

11 0
|
1月前
|

35 1
|
1月前

81 1
|
1月前
|

28 1
|
1月前
|
Serverless

24 1
|
1月前
|

27 1
|
1月前
|

31 1
|
1月前
|

31 1