📄 exampleprecipgsn.m
字号:
dmn=readDomain('Spain');
CP=getEOF(dmn,'ncp',10);
Example.Network={'GSN'};
Example.Stations={'Spain.stn'};
Example.Variable={'Precip'};
[data,Example]=loadStations(Example,'dates',{dmn.startDate,dmn.endDate},'ascfile',1);
Example.Info.Name(4,:)
data=data(:,4); %we take data for Navacerrada station
j=find(isnan(data)==0); % Selecting days with no missing data
X=CP(j,:)';
Y=data(j,:)';
minY=min(Y);
maxY=max(Y);
Y2=(Y-minY)./(maxY-minY);
[X,mX,dX,Y,mY,dY]=prestd(X,Y); % Data standarization
e=fix(size(X,2)*0.75); % Selecting 75 percent of data for training
Xt=X(:,1:e);
Yt=Y(:,1:e);
Y2t=Y2(:,1:e);
disp('Entrenando la red de salida lineal');
net=mlp(size(X,1),5,size(Y,1),'linear');
net=mlptrain(net,Xt',Yt',500);
%Forecasting using the neural network
P=mlpfwd(net,X');
%Getting back the original dimensions
Pred=((P'.*repmat(dY,[1 size(P,2)]))+repmat(mY,[1 size(P,2)]))';
disp('Entrenando la red de salida logistica');
net2=mlp(size(X,1),5,size(Y,1),'logistic');
net2=mlptrain(net2,Xt',Y2t',500);
%Forecasting using the neural network
P2=mlpfwd(net2,X');
%Getting back the original dimensions
Pred2=(P2.*(maxY-minY))+minY;
%regresion lineal
disp('regresi髇 lineal')
Xr=[ones(1,size(X,2));X];
Xrt=Xr(:,1:e);
b= regress(Yt',Xrt');
%Forecasting
P3=Xr'*b;
%Getting back the original dimensions
Pred3=((P3'.*repmat(dY,[1 size(P,2)]))+repmat(mY,[1 size(P,2)]))';
neg=find(Pred3(:,1)<0);
Pred3(neg,:)=0;
%usando la toolbox de redes neuronales
('Entrenando la red con la toolbox neuralnetworks')
net4=newff([min(Xt,[],2),max(Xt,[],2)],[2 2 1],{'logsig','logsig','purelin'});
net4=train(net4,Xt,Yt);
%Forecasting using the neural network
P4=sim(net4,X);
%Getting back the original dimensions
Pred4=((P4.*repmat(dY,[1 size(P,2)]))+repmat(mY,[1 size(P,2)]))';
Obsr=data(j,:);
disp('Calculando errores de las predicciones sobre el conjunto de validacion')
mse1=mse(Obsr(e+1:end,:)-Pred(e+1:end,:));
mse2=mse(Obsr(e+1:end,:)-Pred2(e+1:end,:));
mse3=mse(Obsr(e+1:end,:)-Pred3(e+1:end,:));
mse4=mse(Obsr(e+1:end,:)-Pred4(e+1:end,:));
disp('Dibujando las predicciones sobre el conjunto de validacion')
%Drawing the predictions for the test data
figure
plot(Obsr(e+1:end,:),'b');
hold on
plot(Pred(e+1:end,:),'r');
plot(Pred2(e+1:end,:),'g');
plot(Pred3(e+1:end,:),'c');
plot(Pred4(e+1:end,:),'k');
legend('mse',num2str(mse1),num2str(mse2),num2str(mse3),num2str(mse4));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -