|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
我用matlab的神经网络工具newrb建立了一个径向基网络模型用于预测风速。代码如下:
clear;
%======================
%code for the 'test05b'
temp=load('C:\temp.txt');
wind_speed_ori=temp(:,1);%load the original wind speed data into the varibal wind_speed_ori
[wind_speed_nor,minp,maxp]=premnmx(wind_speed_ori); %normalize the wind_speed_ori to[-1,1] as wind_speed_nor
for scale=1:100 %build the training samples 'wind_speed_train' from the varible 'wind_speed_nor'; scale is the number of samples
for i=1:9 %the samples is constructed by 8-input data and 1-output data
wind_speed_train(i,scale)=wind_speed_nor(scale-1+i,1);
end
end
%=======================
%RBF径向基网络
net_rbf=newrb(wind_speed_train(1:8,:),wind_speed_train(9,:)); %建立径向基网络,采用8个最近的历史数据作输入训练
simu_rbf=sim(net_rbf,wind_speed_train(1:8,:)); %对输入进行仿真
err_rbf=simu_rbf-wind_speed_train(9,:); %误差向量
perf_rbf=mse(err_rbf,net_rbf); %性能函数
perf_rbf
%===========
%to build a query data for prediction
longth_of_history=length(wind_speed_nor); % get the length of history data
for i=1:8 %build a query data sequence 'wind_speed_now'for the prediction
wind_speed_for_pre(i,1)=wind_speed_nor(longth_of_history-32+i,1);
end
%=======================
%to call the predict function to predict 24 data which saved to
%wind_speed_for_pre[9]~wind_speed_for_pre[32]
for i=1:24
wind_speed_for_pre(8+i,1)=sim(net_rbf,wind_speed_for_pre(i:7+i,1));%rbfpredict(model,wind_speed_train(1:8,:)',wind_speed_now(i:7+i,1)');
end
wind_speed_pre=postmnmx(wind_speed_for_pre,minp,maxp); %to turn 'wind_speed_now' back to normal wind speed from:[-1,1]->[0,max]
% ======================
%用历史数据的倒数32-25位的8个数据作预测的输入数据,每次预测得到的一个预测值再加上前7个最近历史数据作为下次预测的输入值,依次作24次预测,再和历史数据的倒数24-1位的数据作比较
err_rbf_pre=wind_speed_pre(9:32,1)-wind_speed_ori(longth_of_history-23:longth_of_history,1);
perf_rbf=mse(err_rbf_pre,net_rbf);
figure;
plot(wind_speed_pre(9:32,1),'-o');
hold on;
plot(wind_speed_ori(longth_of_history-23:longth_of_history,1),'r-*');
hold off
print(gcf,'-djpeg','abc.jpeg');
perf_rbf
%===============================
以上代码得到的预测结果的前4位预测值比较符合历史比较数据,如图1。
我想问问大家:
1,如何改进代码提高预测精度?
2,我采用每次预测一个数值,然后依次用最近的历史数据加上最近的预测值构成8个输入用于下次预测的方法,大家有没有更使用的预测方法?
3,大家有没有做这种预测算法的,请谈谈你们的经验,谢谢! |
-
图1:预测结果与历史比较
|