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

Compute() public method

Computes output value of neuron.

The output value of activation neuron is equal to value of nueron's activation function, which parameter is weighted sum of its inputs plus threshold value. The output value is also stored in Output property.

The method may be called safely from multiple threads to compute neuron's output value for the specified input values. However, the value of Neuron.Output property in multi-threaded environment is not predictable, since it may hold neuron'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 neuron's output property.

Wrong length of the input vector, which is not /// equal to the expected value.
public Compute ( double input ) : double
input double Input vector.
return double
        public override double Compute( double[] input )
        {
            // check for corrent input vector
            if ( input.Length != inputsCount )
                throw new ArgumentException( "Wrong length of the input vector." );

            // initial sum value
            double sum = 0.0;

            // compute weighted sum of inputs
            for ( int i = 0; i < weights.Length; i++ )
            {
                sum += weights[i] * input[i];
            }
            sum += threshold;

            // local variable to avoid mutlithreaded conflicts
            double output = function.Function( sum );
            // assign output property as well (works correctly for single threaded usage)
            this.output = output;

            return output;
        }
    }