Even though it is a very important (if not the most important) phase in the operation of a neural net, the recognition phase is a rather simple phase.
As we have noted earlier, recognition is done in the following steps:
- The input neurons receive the pixel data from the image.
- Each input neuron calculates its output.
- This output is fed directly to the neurons in the hidden layer.
- The neurons in the hidden layer calculate their output.
- This output is fed to the neurons in the output layer.
- The neurons in the output layer calculate their output.
- The output of the output layer is our result. We interpret it the way we want.
Let us go through the source code again:
// file: neuralNetwork.cpp
char neuralNetwork::Recognize(int * Input_Array){
Find_Output_InputLayer(Input_Array);
Find_Output_HiddenLayer();
Find_Output_OutputLayer();
return Output();
}
void neuralNetwork::Find_Output_InputLayer(int * Input_Array){
// The intput is fed directly to the output
for(int i=0; i<NO_INPUT; i++){
Output_Of_InputLayer[i] = (double)Input_Array[i];
}
}
void neuralNetwork::Find_Output_HiddenLayer(){
for(int i=0; i<NO_HIDDEN; i++){
Output_Of_HiddenLayer[i] =
hiddenNeurons[i].Output(Output_Of_InputLayer, NO_INPUT);
}
}
void neuralNetwork::Find_Output_OutputLayer(){
for(int i=0;i<NO_OUTPUT;i++){
Output_Of_OutputLayer[i] =
outputNeurons[i].Output(Output_Of_HiddenLayer, NO_HIDDEN);
}
}
// Returns an index to the array: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
int neuralNetwork::Output(){
int index = 0;
int i,j=1;
for(i = 0; i < NO_OUTPUT; i++,j *=2){
index += j * (Output_Of_OutputLayer[NO_OUTPUT-(i+1)] > 0.5 ? 1 : 0);
}
return index;
}
We can see that in the Recognize() method each layer starting from the input layer calculate it's output. When the output layer calculates it's output, the array Output_Of_OutputLayer[4 decimal numbers] contains the result of the neural net operation. What we mean by a layer calculating it's output is that each neuron in the layer calculates:
- The product of each input signal and weight assigned to the input node: Wi * Xi
- The sum of all products calculated in the first step: sum(Wi * Xi)
- Applies the sigmoid function to find the value of the output to be given.
