AForge.Neuro.Layer.Compute C# (CSharp) Method

Compute() public method

Compute output vector of the layer.

The actual layer's output vector is determined by neurons, which comprise the layer - consists of output values of layer's neurons. The output vector is also stored in Output property.

The method may be called safely from multiple threads to compute layer's output value for the specified input values. However, the value of Output property in multi-threaded environment is not predictable, since it may hold layer's output computed from any of the caller threads. Multi-threaded access to the method is useful in those cases when it is required to improve performance by utilizing several threads and the computation is based on the immediate return value of the method, but not on layer's output property.

public Compute ( double input ) : double[]
input double Input vector.
return double[]
        public virtual double[] Compute( double[] input )
        {
            // local variable to avoid mutlithread conflicts
            double[] output = new double[neuronsCount];

            // compute each neuron
            for ( int i = 0; i < neurons.Length; i++ )
                output[i] = neurons[i].Compute( input );

            // assign output property as well (works correctly for single threaded usage)
            this.output = output;

            return output;
        }