資源簡介
里面包含了MATLAB實例代碼以及相關數據,適合做神經網絡的參考
代碼片段和文件信息
%%?Matlab神經網絡43個案例分析
%?基于Elman神經網絡的電力負荷預測模型研究
%?by?王小川(@王小川_matlab)
%?http://www.matlabsky.com
%?Email:sina363@163.com
%?http://weibo.com/hgsz2003
%%?清空環境變量
clc;
clear?all
close?all
nntwarn?off;
%%?數據載入
load?data;
a=data;
%%?選取訓練數據和測試數據
for?i=1:6
????p(i:)=[a(i:)a(i+1:)a(i+2:)];
end
%?訓練數據輸入
p_train=p(1:5:);
%?訓練數據輸出
t_train=a(4:8:);
%?測試數據輸入
p_test=p(6:);
%?測試數據輸出
t_test=a(9:);
%?為適應網絡結構?做轉置
p_train=p_train‘;
t_train=t_train‘;
p_test=p_test‘;
%%?網絡的建立和訓練
%?利用循環,設置不同的隱藏層神經元個數
nn=[7?11?14?18];
for?i=1:4
????threshold=[0?1;0?1;0?1;0?1;0?1;0?1;0?1;0?1;0?1];
????%?建立Elman神經網絡?隱藏層為nn(i)個神經元
????net=newelm(threshold[nn(i)3]{‘tansig‘‘purelin‘});
????%?設置網絡訓練參數
????net.trainparam.epochs=1000;
????net.trainparam.show=20;
????%?初始化網絡
????net=init(net);
????%?Elman網絡訓練
????net=train(netp_traint_train);
????%?預測數據
????y=sim(netp_test);
????%?計算誤差
????error(i:)=y‘-t_test;
end
%%?通過作圖?觀察不同隱藏層神經元個數時,網絡的預測效果
plot(1:1:3error(1:)‘-ro‘‘linewidth‘2);
hold?on;
plot(1:1:3error(2:)‘b:x‘‘linewidth‘2);
hold?on;
plot(1:1:3error(3:)‘k-.s‘‘linewidth‘2);
hold?on;
plot(1:1:3error(4:)‘c--d‘‘linewidth‘2);
title(‘Elman預測誤差圖‘)
set(gca‘Xtick‘[1:3])
legend(‘7‘‘11‘‘14‘‘18‘‘location‘‘best‘)
xlabel(‘時間點‘)
ylabel(‘誤差‘)
hold?off;
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????6159??2013-08-21?07:25??chapter1\BPDLX.m
?????文件???????3896??2013-08-21?07:15??chapter1\chapter1_1.asv
?????文件???????4030??2013-08-21?07:18??chapter1\chapter1_1.m
?????文件??????93015??2009-08-29?16:54??chapter1\data1.mat
?????文件??????92845??2009-08-29?16:54??chapter1\data2.mat
?????文件??????92937??2009-08-29?16:54??chapter1\data3.mat
?????文件??????93438??2009-08-29?16:54??chapter1\data4.mat
?????目錄??????????0??2013-08-21?07:51??chapter1
-----------?---------??----------?-----??----
???????????????386320????????????????????8
- 上一篇:維也納大學LTE的系統仿真代碼
- 下一篇:MATLAB程序設計基礎與應用.pdf
評論
共有 條評論