%编制人:adwjt
%编制时间:2020.9.19
%% 初始化
clear all;
close all
clc;
format long;
load_count=356;
dian_count=96;
load0=xlsread('zibo08.xls');
load=load0([1:load_count],[2:(dian_count+1)]);%因为quan.xls第一列增加了序号列
%对全体数据进行归一化处理
load_max=max(max(load));
load_min=min(min(load));
load=(load-load_min)./(load_max-load_min);
wen_max=load0([1:load_count],dian_count+2);
wen_min=load0([1:load_count],dian_count+3);
wen_aver=load0([1:load_count],dian_count+4);
wen_max=mapminmax(wen_max',0.1,0.9);
wen_min=mapminmax(wen_min',0.1,0.9);
wen_aver=mapminmax(wen_aver',0.1,0.9);
wen_max=wen_max';
wen_min=wen_min';
wen_aver=wen_aver';
load1=zeros(load_count,dian_count+6);
load1(1:load_count,1:dian_count)=load;
load1(1:load_count,dian_count+1)=wen_max;
load1(1:load_count,dian_count+2)=wen_min;
load1(1:load_count,dian_count+3)=wen_aver;
load=load1;%load已经进行归一化,而且数据很全,包括了温度和天气
%训练样本处理
%选择训练起始天d_start,终止天d_end
d_start=108;d_end=117;
p_train=zeros(96*(d_end-d_start+1),15);%【改】输入元素数量
t_train=zeros(96*(d_end-d_start+1),1);
k=0;%k是训练样本数
for i=d_start:1:d_end
for j=1:1:96
k=k+1;
if j==1
p_train(k,:)=[load(i-2,96),load(i-1,j),load(i-1,j+1),load(i-3,96),load(i-2,j),load(i-2,j+1),load(i-4,96),load(i-3,j),load(i-3,j+1),load(i,97),load(i,98),load(i,99),load(i,100),load(i,101),load(i,102)];
elseif j==96
p_train(k,:)=[load(i-1,j-1),load(i-1,j),load(i,1),load(i-2,j-1),load(i-2,j),load(i-1,1),load(i-3,j-1),load(i-3,j),load(i-2,1),load(i,97),load(i,98),load(i,99),load(i,100),load(i,101),load(i,102)];
else
p_train(k,:)=[load(i-1,j-1),load(i-1,j),load(i-1,j+1),load(i-2,j-1),load(i-2,j),load(i-2,j+1),load(i-3,j-1),load(i-3,j),load(i-3,j+1),load(i,97),load(i,98),load(i,99),load(i,100),load(i,101),load(i,102)];
end
t_train(k)=load(i,j);
end
end
k
p_train=p_train';
t_train=t_train';
%预测处理,同时处理预测天的全天真实负荷值real_d
%要预测第d_test天,第h_test个负荷点
p_test=zeros(96,15);%【改】输入元素数量
t_test=zeros(96,1);
k1=0;%k是预测负荷点的数量,此处取一天中96点
d_test=121;
for j1=1:1:96
k1=k1+1;
if j1==1
p_test(k1,:)=[load(d_test-2,96),load(d_test-1,j1),load(d_test-1,j1+1),load(d_test-3,96),load(d_test-2,j1),load(d_test-2,j1+1),load(d_test-4,96),load(d_test-3,j1),load(d_test-3,j1+1),load(d_test,97),load(d_test,98),load(d_test,99),load(d_test,100),load(d_test,101),load(d_test,102)];
elseif j1==96
p_test(k1,:)=[load(d_test-1,j1-1),load(d_test-1,j1),load(d_test,1),load(d_test-2,j1-1),load(d_test-2,j1),load(d_test-1,1),load(d_test-3,j1-1),load(d_test-3,j1),load(d_test-2,1),load(d_test,97),load(d_test,98),load(d_test,99),load(d_test,100),load(d_test,101),load(d_test,102)];
elseif j1==96
else
p_test(k1,:)=[load(d_test-1,j1-1),load(d_test-1,j1),load(d_test-1,j1+1),load(d_test-2,j1-1),load(d_test-2,j1),load(d_test-2,j1+1),load(d_test-3,j1-1),load(d_test-3,j1),load(d_test-3,j1+1),load(d_test,97),load(d_test,98),load(d_test,99),load(d_test,100),load(d_test,101),load(d_test,102)];
end
t_test(k1)=load(d_test,j1);
end
p_test=p_test';
t_test=t_test';
k1
%net=newff(p_train,t_train,31,{'tansig','logsig'},'traingdm');
net=newelm(minmax(p_train),[34,1],{'tansig','purelin',});%不用purelin函数
%,因为结果点上下波动太大
%newff([每个输入向量的范围],[每层神经元的个数],{'每一层传递函数(默认为tansig函数)'},BTF,BLF,PF);
%BTF:训练函数(默认为trainlm函数,此处使用的训练函数是traingdm函数);
%BLF:权值/阈值学习函数(默认为learngdm函数);
%PF:性能函数(默认为mse函数);
net.trainParam.show=100;
net.trainParam.lr=0.001;
net.trainParam.epochs=3000;
net.trainParam.goal=0.0001;
%调用TRAINGDM算法训练BP网络
net=train(net,p_train,t_train);
%对BP网络进行仿真
r=sim(net,p_test);%进行预测
m=r.*(load_max-load_min)+load_min;
n=load0(120,2:97);
cha=abs(m-n);%求绝对值
cha_xiangdui=cha./n;
cha_jun=(sum(cha_xiangdui))/96
cha1=abs(cha_xiangdui);
chamax=max(cha1)
figure(1)
plot(t_test,'r * -');
hold on;
plot(r,'g o -');
hold off
axis([0 100 0 0.8]);
title('+为真实值,*为预测值');
legend('真实值','预测值');
box off
AdAxesEdit=axes('Position',get(gca,'Position'),'XAxisLocation','top','YAxisLocation','right','Color','none','XColor','k','YColor','k');
set(AdAxesEdit,'XTick',[],'YTick',[]);
box off
扬辰鑫
- 粉丝: 1604
- 资源: 97
最新资源
- 基于javaweb的网上拍卖系统,采用Spring + SpringMvc+Mysql + Hibernate+ JSP技术
- polygon-mumbai
- Chrome代理 switchyOmega
- GVC-全球价值链参与地位指数,基于ICIO表,(Wang等 2017a)计算方法
- 易语言ADS指纹浏览器管理工具
- 易语言奇易模块5.3.6
- cad定制家具平面图工具-(FG)门板覆盖柜体
- asp.net 原生js代码及HTML实现多文件分片上传功能(自定义上传文件大小、文件上传类型)
- whl@pip install pyaudio ERROR: Failed building wheel for pyaudio
- Constantsfd密钥和权限集合.kt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈