⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gabpfault.m

📁 短期负荷预测通常是指24小时的日负荷预测和168小时的周负荷预测
💻 M
字号:
tic, %开始计时
% 首先进行遗传算法
[P,T,R,S1,S2,S,meanp,stdp,meant,stdt]=nninit;
aa=ones(S,1)*[-1 1];
popu=400;
initPpp=initializega(popu,aa,'gabpEval');
gen=1000; % 遗传代数
% 遗传计算
[x endPop bPop trace]=ga(aa,'gabpEval',[],initPpp,[1e-6 1 1],'maxGenTerm',gen,...  'normGeomSelect',[0.08],['arithXover'],[3],'nonUnifMutation',[4 gen 3]);% x The best found
% Lets take a look at the performance of the ga during the run
subplot(2,1,1)plot(trace(:,1),1./trace(:,3),'r-')hold onplot(trace(:,1),1./trace(:,2),'b-')
xlabel('Generation');
ylabel('Sum-Squared Error');
subplot(2,1,2)plot(trace(:,1),trace(:,3),'r-')hold onplot(trace(:,1),trace(:,2),'b-')
xlabel('Generation');
ylabel('Fittness');
% 下面进行BP算法
figure(2)
% 将遗传算法的结果分解为BP网络所对应的权值、阈值
[W1 B1 W2 B2 P T A1 A2 SE val]=gadecod(x);
% BP网络训练的参数设置
disp_fqre=1000; max_epoch=20000;err_goal=0.0001;lr=0.001;
 TP=[disp_fqre  max_epoch err_goal lr];
[W1,B1,W2,B2,te,tr]=trainbp(W1,B1,'tansig',W2,B2,'purelin',P,T,TP);
% 仿真结果
TT=simuff(P,W1,B1,'tansig',W2,B2,'purelin')
E=sum((T-TT).^2)./10;
E=sqrt(E)
e1=(T-TT)./T
c=poststd(TT,meant,stdt)
toc  % 结束计时
%前面的网络训练过程可以是脚本文件运行
%后面的待预测的数据必须每次从命令窗口输入才是每次得到同一的预测结果 只有这样才是每次利用前面已经训练好的网络
%检验数据: 
%##########################################
  %xk1=input('     please input .....xk==')
  %pnew=xk1';
  %pnew=trastd(pnew,meanp,stdp);%将数据通过自标准化再用来输入网络
  %an=simuff(pnew,W1,B1,'tansig',W2,B2,'purelin')%网络模拟出来的值
  %anew=poststd(an,meant,stdt)%模拟出的值再线性返回样本预测值
  %tk1=input('     please input .....tk==')
  %e2=(tk1-anew)./tk1
  %xk2=input('     please input .....xk==')
  %data
  data2
  pnew=xk';
  pnew=trastd(pnew,meanp,stdp);%将数据通过自标准化再用来输入网络
  an=simuff(pnew,W1,B1,'tansig',W2,B2,'purelin');%网络模拟出来的值
  anew=poststd(an,meant,stdt)%模拟出的值再线性返回样本预测值
  %tk2=input('     please input .....tk==')
  tk=tk'
  e2=(tk-anew)./tk

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -