Application Center - Maplesoft

App Preview:

A Feedforward Neural Network Forecasting Exercise

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

 

 

 

 

 

 

 

 

Image 

 

A Feedforward Neural Network Forecasting Excercise 

 

 

The following was implemented in Maple by Marcus Davidsson (2008)

davidsson_marcus@hotmail.com
 

and is based upon the work Mercado, Kendrick & Amman (2006)

Computational Economics, Princeton University Press
 

 

 

 

 

 

 

 

 

The basic structure of our feedforward neural network can be seen in the figure below.. 

 

 

 

We can see that our network has one output layer, one hidden layer and one input layer. 

 

 

 

 

Image 

 

 

 

 

 

 

← Output Layer 

 

 

 

← Hidden Layer 

 

 

 

 

 

 

← Input Layer 

 

 

 

 

We now note that the hidden layer represented by S(z1) and S(z2) takes the form of a sigmoid function ( also called a "squasher" ) as seen below 

 

 



 

Plot_2d  
 

 

 

 

The sigmoid function compresses the independent data points ( x ) into a 0-1 interval as seen above 

 

 

We can see that when x is large and positive z will be close to 1 and when x is large and negative z will be close to 0 

 

 

 

We now note that in our particular case the sigmoid functions take the following form: 

 

 

  where      

 

 

    where          

 

 

 

we should also note that the output layer y(hat) is given by 

 

 

 

 

 

where are the parameter values that minimize the Norm where the Norm is defined by: 

 

 

 

 

 

Note that the Norm is simply the sum of the absolute difference between y and the predicted value of y ( y(hat) ) 

 

 

which means that we select the parameter values so that the error of our predicted value is minimized. 

 

 

 

We can now load our dataset 

 

 






 

(1)
 

 

 

 

We now note that we will only use the data from 1990 to 1999 to train our neural network (find optimal parameter values )
 


and then we will try use these optimal parameter values to predict the data for "y" from 2000 to 2002. 

 

 

 

We can now write a procedure that will accomplish this as follows:  

 

 



































 

 

 

 

 

Matrix(%id = 80986704)
 
[5.53404460051471947, [w1 = .285150771417812088, w2 = 20.1862663548799937, w3 = -15.4984159921287042, w4 = .99999999999877954, w5 = .99999999998761336, theta0 = -.315435905768009116, theta1 = 3.607529...
[5.53404460051471947, [w1 = .285150771417812088, w2 = 20.1862663548799937, w3 = -15.4984159921287042, w4 = .99999999999877954, w5 = .99999999998761336, theta0 = -.315435905768009116, theta1 = 3.607529...
[5.53404460051471947, [w1 = .285150771417812088, w2 = 20.1862663548799937, w3 = -15.4984159921287042, w4 = .99999999999877954, w5 = .99999999998761336, theta0 = -.315435905768009116, theta1 = 3.607529...
(2)
 

 

 

 

 

These are the local optimal parameter values that will minimize Norm. We can now do some forecasting: 

 

 

assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
assign(out[2]); -1; for i from `+`(Nr, `-`(2)) to Nr do `assign`(z1[i], `+`(`*`(w1, `*`(A[i, 2])), `*`(w2, `*`(A[i, 3])), `*`(w3, `*`(A[i, 4])))); `assign`(Sz1[i], `/`(1, `*`(`+`(1, exp(`+`(`-`(z1[i])...
 

 

 

 

 

 

 

 

 

 

 

 

 

[`*`(Actual, `*`(y)) = 2.82, `*`(Predicted, `*`(y)) = 2.98, Difference = -.16]
[`*`(Actual, `*`(y)) = 1.82, `*`(Predicted, `*`(y)) = 2.98, Difference = -1.16]
[`*`(Actual, `*`(y)) = 1.49, `*`(Predicted, `*`(y)) = 2.98, Difference = -1.49]
 
[MeanStandardError = 1.20]
 
Plot_2d