Neural Network to predict weather not converging
Ältere Kommentare anzeigen
Hi,
I developed a code to predict weather using neural network without using toolbox. I used the following paper to develop the algorithm:
The problem I am facing in this code is it is not converging:
%-------------------------------------------%
% Reading temperature data
%-------------------------------------------%
filename='STL_2010.csv';
Temp_actual=csvread(filename,1,3,[1, 3, 8759, 3]);
Temp=Temp_actual.*0.001;
%-------------------------------------------%
% Neural Network
%-------------------------------------------%
%Initial temperatures
i=1;
temp24=Temp(i:i+23);
[fut_min_t,min_index]= min(temp24);
[fut_max_t,max_index]= max(temp24);
tempn24=Temp(i:i+23);
min_t_hat_p=fut_min_t;
max_t_hat_p=fut_max_t;
%Neural Network weight initialization
v=rand(28,60);
w1=rand(60,60);
w2=rand(60,60);
w3=rand(60,24);
B=ones(60,24);
k_v=0.0001;
alpha1=0.001;
alpha2=0.001;
alpha3=0.001;
% temp_hat(i:i+23)=rand(1,24);
%Adaptive Scaling
syms m b;
flag=0;
for i=24:24:8736
temp24=Temp(i:i+23);
past_min_t=fut_min_t;
past_max_t=fut_max_t;
fut_min_t= min(temp24);
fut_max_t= max(temp24);
z=[past_min_t;past_max_t;fut_min_t;fut_max_t;tempn24]; %Neural Network Input
%Neural Network
phi1=tanh(v'*z);
phi2=tanh(w1'*phi1);
phi3=tanh(w2'*phi2);
temp_hat(i:i+23)= w3'*phi3; %tanh(w2'*phi2);
error(i:i+23)=temp_hat(i:i+23)-Temp(i:i+23)';
%Adaptive scaling
%Formula: T_scaled=m*T_neural_o/p+bais
min_index_p=min_index;
max_index_p=max_index;
min_t_hat=min(temp_hat(i:i+23));
max_t_hat=max(temp_hat(i:i+23));
[min_t,min_index]=min(Temp(i:i+23));
[max_t,max_index]=max(Temp(i:i+23));
min_index=min_index+i;
max_index=max_index+i;
if min_index_p < max_index_p
[solm, solb] = solve(min_t_hat*m+b==100*fut_min_t, max_t_hat_p*m+b==100*past_max_t);
temp_hat(max_index_p:min_index)= solm*temp_hat(max_index_p:min_index)+solb;
[solm, solb] = solve(min_t_hat*m+b==100*fut_min_t, max_t_hat*m+b==100*fut_max_t);
temp_hat(min_index:max_index)= solm.*temp_hat(min_index:max_index)+solb;
%Error
e(max_index_p:max_index)=temp_hat(max_index_p:max_index)-0.1*Temp_actual(max_index_p:max_index)';
e1(max_index_p:max_index)=0.01.*e(max_index_p:max_index);
else
[solm, solb] = solve(max_t_hat*m+b==100*fut_max_t, min_t_hat_p*m+b==100*past_min_t);
temp_hat(min_index_p:max_index)= solm*temp_hat(min_index_p:max_index)+solb;
[solm, solb] = solve(min_t_hat*m+b==100*fut_min_t, max_t_hat*m+b==100*fut_max_t);
temp_hat(max_index:min_index)= solm*temp_hat(max_index:min_index)+solb;
%Error
e(min_index_p:min_index)=(temp_hat(min_index_p:min_index)-0.1*Temp_actual(min_index_p:min_index)');
e1(min_index_p:min_index)=0.01*e(min_index_p:min_index);
end
%Weight Update
w1=w1-alpha1*phi1*(w1'*phi1+k_v*B*e1(i-23:i)')';
w2=w2-alpha2*phi2*(w2'*phi2+k_v*B*e1(i-23:i)')';
w3=w3+alpha3*phi3*error(i:i+23);
min_t_hat_p=min_t_hat;
max_t_hat_p=max_t_hat;
%Temperature for next day calculation
tempn24=temp24;
flag=flag+1;
end
plot(temp_hat);
hold on;
plot(Temp_actual,'r');
end
If some body can help me diagnose the problem it will be great.
3 Kommentare
Star Strider
am 13 Dez. 2015
The paper is behind the IEEE paywall. I cannot access it.
Greg Heath
am 15 Dez. 2015
Why can't you use the NN Toolbox?
Siddharth Singh
am 27 Jan. 2016
Antworten (0)
Kategorien
Mehr zu Weather and Atmospheric Science finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!