When implementing Artificial Neural Networks, should the input layer be ignored?

StackOverflow https://stackoverflow.com/questions/19385690

  •  30-06-2022
  •  | 
  •  

Question

I'm trying to implement artificial neural networks in c# but I don't completely understand what the purpose of the input layer is. It doesn't do any processing since the connection between its neurons and the input has no weights.

Consider the following code:

    //Network
    public void Compute(float[] input) {
        layers[0].Compute(input); 

        for (int i = 1; i < layers.Length; i++) {
            layers[i].Compute(layers[i - 1].Output);
        }
    }

    //Layer
    public void Compute(float[] input) {
        for (int i = 0; i < neurons.Length; i++) {
            output[i] = neurons[i].Compute(input);
        }
    }

    //Neuron
    public float Compute(float[] Input) {
        float output = 0.0f;
        for (int i = 0; i < Input.Length; i++) {
            output += Input[i] * weights[i];
        }

        return (output);
    }

When adding layers to the network, I don't need to add the input layer since the input array gets passed to the hidden/output layer directly. Is that correct? If it is, then it seems that the AForge.Net library is doing it wrong. The AForge library adds the input layer to the network but it also adds weights to the connection.

To sum up, take a look at these three network diagrams: enter image description here

Which one of the three diagrams is the correct one?

I guess you could say that I am implementing a virtual input layer (Not adding it into the network, but the array of input is basically the input layer). If that's the case, how would the hoppfield network be implemented? It has one layer which is both the input and the output layer. In that case my implementation would produce wrong results, since a virtual input layer would exist. That means that a completely different implementation of the input layer is required to allow neurons to have only 1 connection with the input.

This is getting really confusing, I hope someone can clarify things for me.

Was it helpful?

Solution

In traditional terminology, the "input layer" is a set of neurons that output the inputs, so they can be consumed by further layers that actually do computations. Input neurons don't do computations, since they don't have any input to do computations upon.

So your understanding is correct. In the "traditional" diagram, the input layer is not a "compute layer". You need to only implement the actual "compute layers".

From what I read in your post, it seems that the AForge library may simply be using different terminology, i.e. it may be refering to the first compute layer, the one that is reading the inputs, as the input layer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top