From: Amey Kulkarni on
Hi.. i am a student working on a project of weather forecast. I am using the data from site
http://www.wunderground.com/history/airport/VABB/2005/3/27/CustomHistory.html?dayend=27&monthend=3&yearend=2006&req_city=NA&req_state=NA&req_statename=NA

I am using a backpropagation algorithm. The data used is converted to excel sheets and used. the algorithm is not converging in my case.

can any one help me in this case?

i have used the average values of temperature,dewpt,humidity and pressure.

The architecture of my network is 4-3-4. The 4 inputs are temperature ,dewpt,humidity and pressure.

following is the code i have written...

-----------------------------------------------------------------------------------------------------------------------
%normalizing the inputs...
[nortemp]=normalize(temp);
[nordew]=normalize(dewpt);
[norhum]=normalize(humidity);
[norpre]=normalize(pressure);

%initializing weights of the links between input layer to hidden layer
%w1 stands for links coming out from first input layer...similar in case of
%w2,w3,w4..
w1=[0.1 0.1 0.1 ];
w2=[0.1 0.1 0.1 ];
w3=[0.1 0.1 0.1 ];
w4=[0.1 0.1 0.1 ];
%initializing the weights between the links hidden to output..
%ow1 stands for weights between first hidden node to all output nodes..
ow1=[0.1 0.1 0.1 0.1];
ow2=[0.1 0.1 0.1 0.1];
ow3=[0.1 0.1 0.1 0.1];

%E=1;

%while (E>)
E=0;
%its not converging.. hence for testing purpose using for loop and not the
%condition E>Emax
for m=1:25
E=0;

for i=1:25
%forward pass....

%using tangent function and -1 as bias
%calculating outpus of hidden nodes
for j=1:3
h(j)=1.7159*tanh(0.6667*(w1(j)*nortemp(i)+w2(j)*nordew(i)+w3(j)*norhum(i)+w4(j)*norpre(i)-1));
end

%calculating outpus of output nodes.. bias -1
for j=1:4
o(j)=1.7159*tanh(0.6667*(ow1(j)*h(1)+ow2(j)*h(2)+ow3(j)*h(3)-1));
end

%desired output is next day's weather
e(1)=nortemp(i+1)-o(1);
e(2)=nordew(i+1)-o(2);
e(3)=norhum(i+1)-o(3);
e(4)=norpre(i+1)-o(4);

%backward pass

%grad is the gradient of the output layer neurons..
for j=1:4
grad(j)=(0.6667/1.7159)*e(j)*(1.7159-o(j))*(1.7159+o(j));
end

%calculating the values of the new weights in links between hidden and output layer

%owts is a function that calculates weights...
for j=1:4
[ow1(j) ow2(j) ow3(j)]=owts(h,grad(j),ow1(j),ow2(j),ow3(j));
end

%gradin is the gradient of the hidden nodes
for j=1:3
gradin(j)=(0.6667/1.7159)*(1.7159-o(j))*(1.7159+o(j))*(ow1(1)*grad(1)+ow1(2)*grad(2)+ow1(3)*grad(3)+ow1(4)*grad(4));
end

%calculating the values of the new weights in links between input
%layer and hidden layer..
%htws is a function that calculates weights...
[w1(1) w1(2) w1(3)]=hwts(nortemp(i),gradin,w1(1),w1(2),w1(3));
[w2(1) w2(2) w2(3)]=hwts(nordew(i),gradin,w2(1),w2(2),w2(3));
[w3(1) w3(2) w3(3)]=hwts(norhum(i),gradin,w3(1),w3(2),w3(3));
[w4(1) w4(2) w4(3)]=hwts(norpre(i),gradin,w4(1),w4(2),w4(3));

%calculating error for this cycle
E=E+((e(1)^2)+(e(2)^2)+(e(3)^2)+(e(4)^2))/8;

end
disp('E=');disp(E);
disp('o=');disp(o);
end

---------------------------------------------------------------------------------------------------------------
function [m]=normalize(t)
a=t(1);b=t(1);

%calculating the highest and lowest values...
for i=1:1828
if (t(i)<a)
a=t(i);
end

if (t(i)>b)
b=t(i);
end
end

%normalizing the data..
for i=1:1828
m(i)=-1+2*(t(i)-a)/(b-a);
end
-------------------------------------------------------------------------------------------------------------------

function [a,b,c]=owts(h,g,p,q,r)
a=p+0.1*g*h(1);
b=q+0.1*g*h(2);
c=r+0.1*g*h(3);
end

-------------------------------------------------------------------------------------------------------------------
function [a,b,c]=hwts(h,g,p,q,r)
a=p+0.1*g(1)*h;
b=q+0.1*g(2)*h;
c=r+0.1*g(3)*h;
end

--------------------------------------------------------------------------------------------------------------------