COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Backpropagation algorithm for weather prediction

• Follow

```Hi, I am working on a project of weather forecasting.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 have converted that data to excel sheets and using only average values of temperature,dew point,humidity and pressure.i have written following code using backpropagation algorithm.The algorithm is not converging in the written code.Can anyone help in thios case?

%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:365
%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

------------------------------------------------------------------------------------------------------------------
% normalization

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

-------------------------------------------------------------------------------------------------------------------
```
 0
Reply Amey 3/27/2010 1:02:07 PM

```I have used 4-3-4 architecture in this case..
```
 1
Reply Amey 3/27/2010 1:19:07 PM

1 Replies
483 Views

(page loaded in 0.413 seconds)

Similiar Articles:

7/26/2012 2:16:52 PM

 Reply: