Exemplo n.º 1
0
        /// <summary>
        /// Feeds the network forward achieving an output for a given set of inputs.
        /// </summary>
        /// <param name="input">The set of inputs to be given to the input neurons.</param>
        public void FeedForward(double[] inputs)
        {
            //Make sure input is same length.
            if (inputs.Length != Neurons[0].Length)
            {
                throw new ArgumentException("Input not same count as neural input layer");
            }

            //Reset neurons
            foreach (Neuron[] layer in Neurons)
            {
                foreach (Neuron n in layer)
                {
                    n.Reset();
                }
            }

            //Set the inputs
            for (int i = 0; i < inputs.Length; i++)
            {
                Neurons[0][i].Net = inputs[i];
            }

            //Establish the bias
            Bias.UpdateOutput(Sigmoid.HyperbolicTangent);

            //Feed Forward
            for (int layer = 0; layer < Neurons.Length; layer++)
            {
                //Update the output
                foreach (Neuron neuron in Neurons[layer])
                {
                    if (layer == 0)
                    {
                        (neuron as InputNeuron).UpdateOutput(this.Activations[layer]);
                    }
                    else
                    {
                        neuron.UpdateOutput(this.Activations[layer]);
                    }
                }

                //Feed the connections forward unless on the last layer.
                if (layer != Neurons.Length - 1)
                {
                    foreach (Connection connection in Connections[layer])
                    {
                        connection.FeedForward();
                    }
                }
            }
        }