飞道的博客

【回归预测-lssvm】基于粒子群算法优化最小二乘支持向量机lssvm实现数据回归预测附matlab代码

298人阅读  评论(0)

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

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

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

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

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

⛄ 内容介绍

准确预测光伏电站输出功率,是促进光伏并网发电,提高电网运行稳定性的主要途径之一.该文提出一种基于粒子群算法最小二乘支持向量机(particle swarm optimization and least squares support vector machine,PSO-LSSVM)的日前光伏功率预测方法,该方法首先利用粒子群算法的全局搜索能力来获取最小二乘支持向量机的惩罚因子和核函数宽度,有效解决了最小二乘支持向量机难以快速精准寻找最优参数的问题;然后利用数值天气预报和光伏功率的历史数据对PSO-LSSVM模型进行训练,利用训练好的PSO-LSSVM模型对日前光伏功率进行预测.

⛄ 部分代码

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]殷樾. 基于粒子群算法最小二乘支持向量机的日前光伏功率预测[J]. 分布式能源, 2021, 6(2):7.

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

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


转载:https://blog.csdn.net/qq_59747472/article/details/127754186
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场