✅作者简介:热爱科研的Matlab仿真开发者,擅长毕业设计辅导、数学建模、数据处理、程序设计科研仿真。
🍎完整代码获取 定制创新 论文复现点击:Matlab科研工作室
👇 关注我领取海量matlab电子书和数学建模资料
🍊个人信条:做科研,博学之、审问之、慎思之、明辨之、笃行之,是为:博学慎思,明辨笃行。
🔥 内容介绍
一、引言
负荷预测在电力系统的规划、运行和管理中起着关键作用。准确的负荷预测有助于优化发电计划、合理分配电力资源以及提高电网运行的稳定性和经济性。传统的负荷预测方法在处理复杂的负荷变化模式时存在局限性,而基于机器学习的方法展现出了强大的潜力。极限学习机(ELM)作为一种快速且有效的单隐层前馈神经网络,但其随机生成的输入权重和偏置可能导致预测性能的不稳定。本文提出利用凌日优化算法(TSOA)对 ELM 进行优化,旨在提高负荷预测的精度和可靠性。
二、相关理论基础
- 凌日优化算法(TSOA)
- 灵感来源
:凌日优化算法是一种受天文现象凌日启发而提出的新型元启发式优化算法。在天文学中,凌日是指一个天体在另一个天体与观测者之间通过的现象。TSOA 模拟了行星在围绕恒星运行过程中,受恒星引力和其他行星引力影响下的运动轨迹。
- 算法流程
:在 TSOA 中,每个优化问题的解被看作是一个 “行星”,其位置代表了问题的一个潜在解。算法通过模拟行星的运动来搜索最优解。行星的运动受到引力的影响,引力的大小与行星之间的距离以及目标函数值相关。距离较近且目标函数值较好的行星对其他行星产生更强的引力。行星根据引力的作用更新自己的位置,在搜索空间中不断移动,逐渐向最优解靠近。同时,算法引入了一定的随机扰动,以避免算法陷入局部最优解,增强全局搜索能力。例如,在每次迭代中,行星的位置更新公式结合了引力作用和随机因素,使得算法能够在探索新的搜索区域和利用已发现的较好解之间取得平衡。
- 灵感来源
三、基于 TSOA 优化 ELM 的负荷预测算法
⛳️ 运行结果
📣 部分代码
function [Best_Planet , best,Bestss] = TransitSearch (ns,maxcycle,Vmin,Vmax,nvar,CostFunction)
SN=10;
%% Initialization
Empty.Location = [];
Empty.Cost = inf;
Galaxy_Center = repmat (Empty, 1, 1);
region = repmat (Empty, ns*SN, 1);
selested_regions = repmat (Empty, ns, 1);
Stars = repmat (Empty, ns, 1);
Stars_sorted = zeros(ns,1);
Ranks = 1:1:ns;
Stars_Ranks = zeros(ns,1);
Luminosity = zeros(ns,1);
Star_RanksNormal = zeros(ns,1);
Distance = zeros(ns,1);
Transit0 = zeros(ns,1);
SN_P = repmat (Empty, SN, 1);
Bests=region;
if length(Vmin) >1
Vmin=Vmin;
Vmax=Vmax;
else
Vmin=Vmin*ones(1,nvar);
Vmax=Vmax*ones(1,nvar);
end
%% Galaxy Phase
% Initial Location of The Center of the Galaxy
Galaxy_Center.Location = unifrnd(Vmin,Vmax,1,nvar);
% Galaxy_Center.Location=initialization(ns,nvar,Vmax,Vmin);
Galaxy_Center.Cost = CostFunction(Galaxy_Center.Location);
% Galactic Habitate Zone of the Galaxy
for l = 1:ns*SN
zone = randi(2);
if zone ==1
difference = rand().*(Galaxy_Center.Location)-(unifrnd(Vmin,Vmax,1,nvar));
else
difference = rand().*(Galaxy_Center.Location)+(unifrnd(Vmin,Vmax,1,nvar));
end
Noise = ((rand(1,nvar)).^3).*(unifrnd(Vmin,Vmax,1,nvar));
region(l).Location = Galaxy_Center.Location + difference - Noise;
region(l).Location = max(region(l).Location, Vmin);
region(l).Location = min(region(l).Location, Vmax);
region(l).Cost = CostFunction(region(l).Location);
end
% Selection of Stars from the Galactic Habitate Zone of the Galaxy
[Sort,index]=sort([region.Cost]);
for i = 1:ns
selested_regions(i) = region(i);
for k = 1:SN
zone = randi(2);
if zone ==1
difference = rand().*(selested_regions(i).Location)-rand().*(unifrnd(Vmin,Vmax,1,nvar));
else
difference = rand().*(selested_regions(i).Location)+rand().*(unifrnd(Vmin,Vmax,1,nvar));
end
Noise = ((rand(1,nvar)).^3).*(unifrnd(Vmin,Vmax,1,nvar));
new.Location = selested_regions(i).Location + difference - Noise;
new.Location = max(new.Location, Vmin);
new.Location = min(new.Location, Vmax);
new.Cost = CostFunction(new.Location);
if new.Cost < Stars(i).Cost
Stars(i) = new;
end
end
end
% Initial Location of the Best Planets (Start Point: Its Star)
Best_Planets = Stars;
% Specification of the Best Planet
[Sort,index]=sort([Best_Planets(1).Cost]);
Best_Planet = Best_Planets(index(1,1));
% Telescope Location
Telescope.Location = unifrnd(Vmin,Vmax,1,nvar);
% Determination of the Luminosity of the Stars
for i = 1:ns
Stars_sorted(i,1) = Stars(i).Cost;
end
Stars_sorted = sort (Stars_sorted);
for i = 1:ns
for ii = 1:ns
if Stars(i).Cost == Stars_sorted(ii,1)
Stars_Ranks(i,1) = Ranks(1,ii);
Star_RanksNormal(i,1) = (Stars_Ranks(i,1))./ns;
end
end
Distance(i,1) = sum((Stars(i).Location-Telescope.Location).^2).^0.5;
Luminosity(i,1) = Star_RanksNormal(i,1)/((Distance(i,1))^2);
end
Luminosity_new = Luminosity;
Stars2 = Stars;
%% Loops of the TS Algorithm
for it = 1:maxcycle
%% Transit Phase
Transit = Transit0;
Luminosity = Luminosity_new;
for i = 1:ns
difference = (2*rand()-1).*(Stars(i).Location);
Noise = ((rand(1,nvar)).^3).*(unifrnd(Vmin,Vmax,1,nvar));
Stars2(i).Location = Stars(i).Location + difference - Noise;
Stars2(i).Location = max(Stars2(i).Location, Vmin);
Stars2(i).Location = min(Stars2(i).Location, Vmax);
Stars2(i).Cost = CostFunction(Stars2(i).Location);
end
for i = 1:ns
Stars_sorted(i,1) = Stars2(i).Cost;
end
Stars_sorted = sort (Stars_sorted);
for i = 1:ns
for ii = 1:ns
if Stars2(i).Cost == Stars_sorted(ii,1)
Stars_Ranks(i,1) = Ranks(1,ii);
Star_RanksNormal(i,1) = (Stars_Ranks(i,1))./ns;
end
end
Distance(i,1) = sum((Stars2(i).Location-Telescope.Location).^2).^0.5;
Luminosity_new(i,1) = Star_RanksNormal(i,1)/((Distance(i,1))^2);
if Luminosity_new(i,1) < Luminosity(i,1)
Transit (i,1) = 1; % Has transit been observed? 0 = No; 1 = Yes
end
end
Stars = Stars2;
%% Location Phase (Exploration)
for i = 1:ns
if Transit (i,1) == 1
% Determination of the Location of the Planet
Luminosity_Ratio = Luminosity_new(i,1)/Luminosity(i,1);
Planet.Location = (rand().*Telescope.Location + Luminosity_Ratio.*Stars(i).Location)./2;
for k = 1:SN
zone = randi(3);
if zone ==1
new.Location = Planet.Location - (2*rand()-1).*(unifrnd(Vmin,Vmax,1,nvar));
elseif zone ==2
new.Location = Planet.Location + (2*rand()-1).*(unifrnd(Vmin,Vmax,1,nvar));
else
new.Location = Planet.Location + (2.*rand(1,nvar)-1).*(unifrnd(Vmin,Vmax,1,nvar));
end
new.Location = max(new.Location, Vmin);
new.Location = min(new.Location, Vmax);
% new.Cost = CostFunction(new.Location);
SN_P(k) = new;
end
SUM = 0;
for k = 1:SN
SUM = SUM+SN_P(k).Location;
end
new.Location = SUM./SN;
new.Cost = CostFunction(new.Location);
if new.Cost < Best_Planets(i).Cost
Best_Planets(i) = new;
end
else % No Transit observed: Neighbouring planets
Neighbor.Location = (rand().*Stars(i).Location + rand().*(unifrnd(Vmin,Vmax,1,nvar)))./2;
for k = 1:SN
zone = randi(3);
if zone ==1
Neighbor.Location = Neighbor.Location - (2*rand()-1).*(unifrnd(Vmin,Vmax,1,nvar));
elseif zone ==2
Neighbor.Location = Neighbor.Location + (2*rand()-1).*(unifrnd(Vmin,Vmax,1,nvar));
else
Neighbor.Location = Neighbor.Location + (2.*rand(1,nvar)-1).*(unifrnd(Vmin,Vmax,1,nvar));
end
Neighbor.Location = max(Neighbor.Location, Vmin);
Neighbor.Location = min(Neighbor.Location, Vmax);
Neighbor.Cost = CostFunction (Neighbor.Location);
SN_P(k) = Neighbor;
end
SUM = 0;
for k = 1:SN
SUM = SUM+SN_P(k).Location;
end
Neighbor.Location = SUM./SN;
Neighbor.Cost = CostFunction (Neighbor.Location);
if Neighbor.Cost < Best_Planets(i).Cost
Best_Planets(i) = Neighbor;
end
end
end
%% Signal Amplification of the Best Planets (Exploitation)
for i = 1:ns
for k = 1:SN
RAND = randi(2 );
if RAND ==1
Power = randi(SN*ns);
Coefficient = 2*rand();
Noise = ((rand(1,nvar)).^Power).*(unifrnd(Vmin,Vmax,1,nvar));
else
Power = randi(SN*ns);
Coefficient = 2*rand();
Noise = -((rand(1,nvar)).^Power).*(unifrnd(Vmin,Vmax,1,nvar));
end
% new.Location = (rand().*Best_Planets(i).Location) - Coefficient.*Noise;
chance = randi(2);
if chance ==1
new.Location = Best_Planets(i).Location - Coefficient.*Noise;
else
new.Location = (rand().*Best_Planets(i).Location) - Coefficient.*Noise;
end
new.Location = max(new.Location, Vmin);
new.Location = min(new.Location, Vmax);
new.Cost = CostFunction(new.Location);
% new.Cost = Penalty(new,ConstraintFunction,CostFunction);
if new.Cost < Best_Planets(i).Cost
Best_Planets(i) = new;
best=Best_Planets(i).Location;
end
end
if Best_Planets(i).Cost < Best_Planet.Cost
Best_Planet = Best_Planets(i);
end
end
% Results
Bestss(it)=Best_Planet.Cost;
end
end