Example #1
0
        public void Have_bias_and_have_inputs_with_weights()
        {
            var perceptron = new ThresholdNeuron();

            //
            perceptron.bias.ShouldCompile();
            perceptron.Inputs.ShouldCompile();
        }
Example #2
0
        /// <summary>
        /// This method implements weight update procedure for the whole network for
        /// this learning rule
        /// </summary>
        /// <param name="patternError">
        ///            single pattern error vector
        ///
        /// if the output is 0 and required value is 1, increase rthe weights
        /// if the output is 1 and required value is 0, decrease the weights
        /// otherwice leave weights unchanged
        ///         </param>
        protected internal override void updateNetworkWeights(double[] patternError)
        {
            int           i             = 0;
            List <Neuron> outputNeurons = neuralNetwork.OutputNeurons;

            foreach (Neuron outputNeuron in outputNeurons)
            {
                ThresholdNeuron neuron      = (ThresholdNeuron)outputNeuron;
                double          outErr      = patternError[i];
                double          thresh      = neuron.Thresh;
                double          netInput    = neuron.NetInput;
                double          threshError = thresh - netInput;        // distance from zero
                // use output error to decide weathet to inrease, decrase or leave unchanged weights
                // add errorCorrection to threshError to move above or below zero
                double neuronError = outErr * (Math.Abs(threshError) + errorCorrection);

                // use same adjustment principle as PerceptronLearning,
                // just with different neuronError
                neuron.Error = neuronError;
                updateNeuronWeights(neuron);

                i++;
            }                             // for
        }