Multilayer perceptron: Difference between revisions
No edit summary |
|||
Line 7: | Line 7: | ||
At first a cumulative input is calculated by the following equation: |
At first a cumulative input is calculated by the following equation: |
||
<math>s = \sum^{n}_{k=1} i_{k} \cdot w_{k}</math> |
:<math>s = \sum^{n}_{k=1} i_{k} \cdot w_{k}</math> |
||
Considering the ''BIAS'' value the equation is: |
|||
:<math>s = (\sum^{n}_{k=1} i_{k} \cdot w_{k}) + BIAS \cdot w_{k}</math> |
|||
:<math>BIAS</math> = 1 |
|||
=== Sigmoid activation function === |
=== Sigmoid activation function === |
||
<math>o = \rm{sig}(s) = \frac{1}{1 + \rm e^{-s}}</math> |
:<math>o = \rm{sig}(s) = \frac{1}{1 + \rm e^{-s}}</math> |
||
=== Hyperbolic tangent activation function === |
=== Hyperbolic tangent activation function === |
||
<math>o = tanh(s)</math> |
:<math>o = tanh(s)</math> |
||
using output range between -1 and 1, or |
using output range between -1 and 1, or |
||
<math>o = \frac{tanh(s) + 1}{2}</math> |
:<math>o = \frac{tanh(s) + 1}{2}</math> |
||
using output range between 0 and 1. |
using output range between 0 and 1. |
||
Line 33: | Line 39: | ||
If the neural network is initialized by random weights it has of course not the expected output. Therefore training is necessary. While supervised training known inputs and their corresponded output values are presented to the network. So it is possible to compare the real output with the desired output. The error is described as the following algorithm: |
If the neural network is initialized by random weights it has of course not the expected output. Therefore training is necessary. While supervised training known inputs and their corresponded output values are presented to the network. So it is possible to compare the real output with the desired output. The error is described as the following algorithm: |
||
<math>E={1\over2} \sum^{n}_{i=1} (t_{i}-o_{i})^{2}</math> |
:<math>E={1\over2} \sum^{n}_{i=1} (t_{i}-o_{i})^{2}</math> |
||
:<math>E</math> network error |
:<math>E</math> network error |
||
Line 44: | Line 50: | ||
The learning algorithm of a single layer perceptron is easy compared to a multilayer perceptron. The reason is that just the output layer is directly connected to the output, but not the hidden layers. Therefore the calculation of the right weights of the hidden layers is difficult mathematically. To get the right delta value for changing the weights of hidden neuron is described in the following equation: |
The learning algorithm of a single layer perceptron is easy compared to a multilayer perceptron. The reason is that just the output layer is directly connected to the output, but not the hidden layers. Therefore the calculation of the right weights of the hidden layers is difficult mathematically. To get the right delta value for changing the weights of hidden neuron is described in the following equation: |
||
<math>\Delta w_{ij}= -\alpha \cdot {\partial E \over \partial w_{ij}} = \alpha \cdot \delta_{j} \cdot x_{i}</math> |
:<math>\Delta w_{ij}= -\alpha \cdot {\partial E \over \partial w_{ij}} = \alpha \cdot \delta_{j} \cdot x_{i}</math> |
||
:<math>E</math> network error |
:<math>E</math> network error |
||
Line 58: | Line 64: | ||
In this PHP implementation of multilayer perceptron the following algorithm is used for weight changes in hidden layers: |
In this PHP implementation of multilayer perceptron the following algorithm is used for weight changes in hidden layers: |
||
<math>s_{kl} = \sum^{n}_{l=1} w_{k} \cdot \Delta w_{l} \cdot \beta</math> |
:<math>s_{kl} = \sum^{n}_{l=1} w_{k} \cdot \Delta w_{l} \cdot \beta</math> |
||
<math>\Delta w_{k} = o_{k} \cdot (1 - o_{k}) \cdot s_{kl}</math> |
:<math>\Delta w_{k} = o_{k} \cdot (1 - o_{k}) \cdot s_{kl}</math> |
||
<math>w_{mk} = w_{mk} + \alpha \cdot i_{m} \cdot \Delta w_{k}</math> |
:<math>w_{mk} = w_{mk} + \alpha \cdot i_{m} \cdot \Delta w_{k}</math> |
||
:<math>\alpha</math> learning rate |
:<math>\alpha</math> learning rate |
||
Line 77: | Line 83: | ||
== Choosing learning rate and momentum == |
== Choosing learning rate and momentum == |
||
The proper choosing of learning rate (<math>\alpha</math>) and momentum (<math>\beta</math>) is done by experience. Both values have a range between 0 and 1. This PHP implementation uses a default value of 0.5 for <math>\alpha</math> and 0.95 for <math>\beta</math>. Theses factors can be |
The proper choosing of learning rate (<math>\alpha</math>) and momentum (<math>\beta</math>) is done by experience. Both values have a range between 0 and 1. This PHP implementation uses a default value of 0.5 for <math>\alpha</math> and 0.95 for <math>\beta</math>. <math>\alpha</math> and <math>\beta</math> cannot be zero. Otherwise no weight change will be happen and the network would never reach an errorless level. Theses factors can be changed by runtime. |
||
== Binary and linear input == |
== Binary and linear input == |
||
Line 83: | Line 89: | ||
If binary input is used easily the input value is 0 for ''false'' and 1 for ''true''. |
If binary input is used easily the input value is 0 for ''false'' and 1 for ''true''. |
||
<math>0 : False</math> |
:<math>0 : False</math> |
||
<math>1 : True</math> |
:<math>1 : True</math> |
||
Using linear input values normalization is needed: |
Using linear input values normalization is needed: |
||
<math>i = \frac{f - f_{min}}{f_{max} - f_{min}}</math> |
:<math>i = \frac{f - f_{min}}{f_{max} - f_{min}}</math> |
||
:<math>i</math> input value for neural network |
:<math>i</math> input value for neural network |
||
Line 100: | Line 106: | ||
The interpretation of output values just makes sense for the output layer. The interpretation is depending on the use of the neural network. If the network is used for classification, so binary output is used. Binary has two states: True or false. The network will produce always linear output values. Therefore these values has to be converted to binary values: |
The interpretation of output values just makes sense for the output layer. The interpretation is depending on the use of the neural network. If the network is used for classification, so binary output is used. Binary has two states: True or false. The network will produce always linear output values. Therefore these values has to be converted to binary values: |
||
<math>o |
:<math>o < 0.5 : False</math> |
||
<math>o |
:<math>o >= 0.5 : True</math> |
||
:<math>o</math> output value |
:<math>o</math> output value |
||
Line 108: | Line 114: | ||
If using linear output the output values have to be normalized to a real value the network is trained for: |
If using linear output the output values have to be normalized to a real value the network is trained for: |
||
<math>f = o \cdot (f_{max} - f_{min}) + f_{min}</math> |
:<math>f = o \cdot (f_{max} - f_{min}) + f_{min}</math> |
||
:<math>f</math> real world value |
:<math>f</math> real world value |
||
Line 115: | Line 121: | ||
The same normalization equation for input values is used for output values while training the network. |
The same normalization equation for input values is used for output values while training the network. |
||
<math>o = \frac{f - f_{min}}{f_{max} - f_{min}}</math> |
:<math>o = \frac{f - f_{min}}{f_{max} - f_{min}}</math> |
||
:<math>o</math> desired output value for neural network |
:<math>o</math> desired output value for neural network |
Revision as of 17:00, 13 January 2008
General
A multilayer perceptron is a feedforward artificial neural network. This means the signal inside the neural network flows from input layer passing hidden layers to output layer. While training the error correction of neural weights are done in the opposite direction. This is done by the backpropagation algorithm.
Activation
At first a cumulative input is calculated by the following equation:
Considering the BIAS value the equation is:
- = 1
Sigmoid activation function
Hyperbolic tangent activation function
using output range between -1 and 1, or
using output range between 0 and 1.
- cumulative input
- weight of input
- value of input
- number of inputs
- number of neuron
Error of neural network
If the neural network is initialized by random weights it has of course not the expected output. Therefore training is necessary. While supervised training known inputs and their corresponded output values are presented to the network. So it is possible to compare the real output with the desired output. The error is described as the following algorithm:
- network error
- count of input patterns
- desired output
- calculated output
Backpropagation
The learning algorithm of a single layer perceptron is easy compared to a multilayer perceptron. The reason is that just the output layer is directly connected to the output, but not the hidden layers. Therefore the calculation of the right weights of the hidden layers is difficult mathematically. To get the right delta value for changing the weights of hidden neuron is described in the following equation:
- network error
- delta value of neuron connection to
- learning rate
- the error of neuron
- input of neuron
- desired output of output neuron
- real output of output neuron .
Programming solution of backpropagation
In this PHP implementation of multilayer perceptron the following algorithm is used for weight changes in hidden layers:
- learning rate
- momentum
- neuron k
- neuron l
- weight m
- input
- output
- count of neurons
To avoid overfitting of neural network the training procedure is finished if real output value has a fault tolerance of 1 per cent of desired output value.
Choosing learning rate and momentum
The proper choosing of learning rate () and momentum () is done by experience. Both values have a range between 0 and 1. This PHP implementation uses a default value of 0.5 for and 0.95 for . and cannot be zero. Otherwise no weight change will be happen and the network would never reach an errorless level. Theses factors can be changed by runtime.
Binary and linear input
If binary input is used easily the input value is 0 for false and 1 for true.
Using linear input values normalization is needed:
- input value for neural network
- real world value
This PHP implementation is supporting input normalization.
Binary and linear output
The interpretation of output values just makes sense for the output layer. The interpretation is depending on the use of the neural network. If the network is used for classification, so binary output is used. Binary has two states: True or false. The network will produce always linear output values. Therefore these values has to be converted to binary values:
- output value
If using linear output the output values have to be normalized to a real value the network is trained for:
- real world value
- real output value of neural network
The same normalization equation for input values is used for output values while training the network.
- desired output value for neural network
- real world value
This PHP implementation is supporting output normalization.