Tutorial 4: AgielNN Forecasting

The final step of AgielNN is forecasting. This should be the easiest process in AgielNN. After finished douing some training and checking; and going with best match to actual data; forecasting can be made using the model by taking a step to “Forecasting” tab in AgielNN.Before that, make sure you are not bypassing the data preparation for forecasting as explained in the first tutorial of data preparation.

There are 2 choices we have to do the process.

Case 1: Use the matched model.

  1. In this case, you can simple select the “Use latest trained ANN” (selected by default).
  2. Select the data to be used in the combo box of “Data used”
  3. Select a number of column as input. Be sure that the number of column must be equal to the number of column used during training and checking.
  4. Click “Do Forecast”

Case 2: Use saved AgielNN model.

  1. In this case, select the “Use other ANN file”.
  2. Browse the ANN model saved from previous training and checking.  The ANN file model must be a model exported from AgielNN and should have *.ann extension. It is not compatible with another ANN file generated by another neural network software. The file can be exported thru menu File — Export — Artificial Neural Network — ANN Trained Model.
  3. Select the data to be used in the combo box of “Data used”
  4. Select a number of column as input. Be sure that the number of column must be equal to the number of column used during training and checking.
  5. Click “Do Forecast”

The screenshot of the software should be like this.

 

—————————————————————-

This is the end of tutorial. Should anybody have question, please mail me. Thanks.
Written by: Sugiyanto
28 June 2013.

Tutorial 3: AgielNN Training and Checking

Continuing the previous tutorial about neural network setup, now we have ready neural network model. To do a training and checking, please go to tab “Training Run”. There is nothing complicated here. All default parameters are already set. If you don’t have any idea about parameters; as i am he he…; just click “Do Train” and hopefully all of the problem solved..

However, in some cases, this simple training process is not that easy as it is looked. So, somehow, you might need to modify the value of those parameters to get the best solution.

Since I don’t have any clue at all about the parameters, here i would directly refers to FANN documentation as follows. Somebody with good mathematical background should understand better on this 🙂

Source: “fann_data.h”

—————————————–

The Training algorithms used when training. The incremental training looks alters the weights after each time it is presented an input pattern, while batch only alters the weights once after it has been presented to all the patterns.

## FANN_TRAIN_INCREMENTAL

Standard back-propagation algorithm, where the weights are updated after each training pattern. This means that the weights are updated many times during a single epoch. For this reason some problems, will train very fast with this algorithm, while other more advanced problems will not train very well.

## FANN_TRAIN_BATCH

Standard back-propagation algorithm, where the weights are updated after calculating the mean square error for the whole training set. This means that the weights are only updated once during a epoch. For this reason some problems, will train slower with this algorithm. But since the mean square error is calculated more correctly than in incremental training, some problems will reach a better solutions with this algorithm.

## FANN_TRAIN_RPROP

A more advanced batch training algorithm which achieves good results for many problems. The RPROP training algorithm is adaptive, and does therefore not use the learning_rate. Some other parameters can however be set to change the way the RPROP algorithm works, but it is only recommended for users with insight in how the RPROP training algorithm works. The RPROP training algorithm is described by [Riedmiller and Braun, 1993], but the actual learning algorithm used here is the iRPROP- training algorithm which is described by [Igel and Husken, 2000] which is an variety of the standard RPROP training algorithm.

## FANN_TRAIN_QUICKPROP

A more advanced batch training algorithm which achieves good results for many problems. The quickprop training algorithm uses the learning_rate parameter along with other more advanced parameters, but it is only recommended to change these advanced parameters, for users with insight in how the quickprop training algorithm works. The quickprop training algorithm is described by [Fahlman, 1988].”
——————————————
The activation functions used for the neurons during training. The activation functions can either be defined for a group of neurons by <fann_set_activation_function_hidden> and <fann_set_activation_function_output> or it can be defined for a single neuron by <fann_set_activation_function>. The steepness of an activation function is defined in the same way by <fann_set_activation_steepness_hidden>, <fann_set_activation_steepness_output> and fann_set_activation_steepness>.

The functions are described with functions where:
* x is the input to the activation function,
* y is the output,
* s is the steepness and
* d is the derivation.

FANN_LINEAR – Linear activation function.
* span: -inf < y < inf
* y = x*s, d = 1*s
* Can NOT be used in fixed point.

FANN_THRESHOLD – Threshold activation function.
* x < 0 -> y = 0, x >= 0 -> y = 1
* Can NOT be used during training.

FANN_THRESHOLD_SYMMETRIC – Threshold activation function.
* x < 0 -> y = 0, x >= 0 -> y = 1
* Can NOT be used during training.

FANN_SIGMOID – Sigmoid activation function.
* One of the most used activation functions.
* span: 0 < y < 1
* y = 1/(1 + exp(-2*s*x))
* d = 2*s*y*(1 – y)

FANN_SIGMOID_STEPWISE – Stepwise linear approximation to sigmoid.
* Faster than sigmoid but a bit less precise.

FANN_SIGMOID_SYMMETRIC – Symmetric sigmoid activation function, aka. tanh.
* One of the most used activation functions.
* span: -1 < y < 1
* y = tanh(s*x) = 2/(1 + exp(-2*s*x)) – 1
* d = s*(1-(y*y))

FANN_SIGMOID_SYMMETRIC – Stepwise linear approximation to symmetric sigmoid.
* Faster than symmetric sigmoid but a bit less precise.

FANN_GAUSSIAN – Gaussian activation function.
* 0 when x = -inf, 1 when x = 0 and 0 when x = inf
* span: 0 < y < 1
* y = exp(-x*s*x*s)
* d = -2*x*s*y*s

FANN_GAUSSIAN_SYMMETRIC – Symmetric gaussian activation function.
* -1 when x = -inf, 1 when x = 0 and 0 when x = inf
* span: -1 < y < 1
* y = exp(-x*s*x*s)*2-1
* d = -2*x*s*(y+1)*s

FANN_ELLIOT – Fast (sigmoid like) activation function defined by David Elliott
* span: 0 < y < 1
* y = ((x*s) / 2) / (1 + |x*s|) + 0.5
* d = s*1/(2*(1+|x*s|)*(1+|x*s|))

FANN_ELLIOT_SYMMETRIC – Fast (symmetric sigmoid like) activation function defined by David Elliott
* span: -1 < y < 1
* y = (x*s) / (1 + |x*s|)
* d = s*1/((1+|x*s|)*(1+|x*s|))

FANN_LINEAR_PIECE – Bounded linear activation function.
* span: 0 <= y <= 1
* y = x*s, d = 1*s

FANN_LINEAR_PIECE_SYMMETRIC – Bounded linear activation function.
* span: -1 <= y <= 1
* y = x*s, d = 1*s

FANN_SIN_SYMMETRIC – Periodical sinus activation function.
* span: -1 <= y <= 1
* y = sin(x*s)
* d = s*cos(x*s)

FANN_COS_SYMMETRIC – Periodical cosinus activation function.
* span: -1 <= y <= 1
* y = cos(x*s)
* d = s*-sin(x*s)

FANN_SIN – Periodical sinus activation function.
* span: 0 <= y <= 1
* y = sin(x*s)/2+0.5
* d = s*cos(x*s)/2

FANN_COS – Periodical cosinus activation function.
* span: 0 <= y <= 1
* y = cos(x*s)/2+0.5
* d = s*-sin(x*s)/2

Source: “fann_train.h”

———————————

The learning rate is used to determine how aggressive training should be for some of the training algorithms (FANN_TRAIN_INCREMENTAL, FANN_TRAIN_BATCH, FANN_TRAIN_QUICKPROP). Do however note that it is not used in FANN_TRAIN_RPROP. The default learning rate is 0.7

Maximum epoch basically maximum number of trials to be conducted. The bigger value of maximum epoch should give the longer running time. Expected error is the targeted error to be pursued. The smaller value of expected error should also give the longer running time. And in many cases, this expected error somehow will never be achieved. So, don’t worry if you have never achieve a good expected error.

Actually, there are many parameters of FANN that have not yet supported in this version of AgielNN. If you like to know more about that, I really recommend you to directly access the FANN documentation. However, i am still working with the next version of AgielNN, so hopefully most of parameters of FANN could be supported in the next AgielNN releases.

Anyway, after you finish “playing” with parameters, please click “Do Training”. And you should get the comparison of training data vs training result, checking data vs checking result, in form of table and chart as show in this example.

Using those kind of result comparison, it might be easier to decide whether the training is “enough” or still need more training process.

And also one of the important result from this training process is the Training logs that is printed in the bottom part of the software. This log basically tells everything about steps of training process, including the final result of weights and biases.

So, the training and checking is basically finished. But again, this procedure might need to be conducted back and forth with network setup to make sure of getting the best match to real data.

This is the end of this tutorial. Should anybody have question, please don’t hesitate to contact my email.
——————————————————————–
Written by Sugiyanto Suwono
Bekasi, April 30, 2013

Tutorial 2: AgielNN Network Preparation

Continuing the previous tutorial about data preparation, now we have 3 data, training, checking,and forecasting. In this tutorial, I will specifically discuss about how to create artificial neural network using those data.

To do that, please go to tab “Network Setup”, and you should find the blank panels in the right. The left most panel is training panel, while the middle panel is checking panel, and the right most panel is network diagram panel.

In the training panel, please select “Data-1 Training”. Since we want to use the first 2 column as input and last column as output, please select the appropriate column in the “Input” and “Output”. Repeat the procedure for Testing panel. Please remember, number of column selected in Training have to be equal to selected column in the Testing panel. However, if somehow you don’t have checking data, you could ignore the checking panel.

In the bottom of Training panel, there is an input of hidden layers. Please specify the preferred number of hidden layers. Each hidden layer must have hidden nodes inside it. The more hidden layers and hidden nodes each layer, the more complicated the network and the longer time to run the training. It is not guaranteed that the more number of hidden layers and nodes will give a better match during training. So, in the next training step, you should try to change this configuration to get the best match of neural network system.

By pressing “Build Network”, you should get this kind of network in the right panel. This figure is an example of neural network diagram build using 2 input nodes, 2 hidden layers, 10 nodes in hidden layer 1 and 2, and 1 output node. Please notice that the “not shown” bullets like node number 2, 13, and 24 are biases node. Please refers to others detailed Artificial Neural Network tutorial to understand the term of bias and weight like in http://www.learnartificialneuralnetworks.com.

So, network preparation is basically finished. But, this procedure might should be conducted back and forth during training and checking to make sure of getting the best match to real data.

 

This is the end of this tutorial. Should anybody have question, please don’t hesitate to contact my email.
——————————————————————–
Written by Sugiyanto Suwono
Bekasi, March 13, 2013

Tutorial 1: AgielNN Data Preparation

AgielNN is basically used to make a prediction of unknown result based on specific input parameters. However, AgielNN requires to be trained first before it ready to conduct any of forecasting. And to make sure that the training is going well, it is also recommended to conduct checking or testing using blind test. So, in general we need 3 kinds of data which are data training, data checking, and data forecasting. 

Data Training & Checking.
Data training and checking must have the same format, which by means of having similar number of column. And those two data are ideally coming from the same data source which is actual data from the field. For example, i want to make a prediction of parameter Z which is estimated to be a function of X, Y, and i have 120 real data from experience as you can see in this SampleANN1.XLS. For simplicity, the data can be divided in to training and checking data by portion of 75:25.  Before inputting to AgielNN, those divided data then must be copied to text editor (Notepad of other similar software) and saved as 2 separated files namely Sample1_train.txt and Sample1_check.txt.

 

Data for Forecasting
Since we want to forecast from 2 variables input, so the data for forecasting must have 2 column only. For example, please refers to this Sample1_Forecast.txt. Must be noted that all input data for forecast must in the range of data input used in the training. For example, if A in the training have minimum value = 0 and maximum = 100, then all A data that will be used for forecasting must lying on 0 to 100. Otherwise, the forecast might goes wrong since the neural network system is only trained for the specific range of data.

!!!REMARKS!!!
AgielNN doesn’t require normalization data since it is automatically do normalization. However, data variation should have linear variation and not exponential or logarithmic or else. For example, if you have variable Z as a function of Log(A), then it is recommended to convert A to C first, where C=Log(A), and use C as input for forecasting the Z.

 

Inputting Data to AgielNN
This is a simple task actually, just go to “Data Source Preparation” window, and click and you will be prompted with this kind of dialog. Fill the name of the data, let say “Data1_Training” and click OK.

A new data source will be created. After that, click the data name. And you will get an empty table on the right panel. To import table from the data that we have prepared previously, simply right click inside the table, and select “Import the File”, or just click the button “Import Table from File” below the table. Browse the Sample1_Train.txt and open. Repeat the procedure for Sample1_Check.txt and Sample1_Forecast.txt named as “Data1_Check” and “Data1_Forecast”. By doing that, now you should have 3 data source, Data1_Check which has 3 columns, Data1_Train 3 columns, and Data1_Forecast 2 columns and this kind of interface.

So, data preparation is finished. This should be a very easy data preparation.. 🙂

This is the end of this tutorial. Should anybody have question, please don’t hesitate to contact my email.
——————————————————————–
Written by Sugiyanto Suwono
Bekasi, March 13, 2013