Пример #1
0
    public double CalculateGradient(double?target = null)
    {
        if (target == null)
        {
            return(Gradient = OutputSynapses.Sum(a => a.OutputNeuron.Gradient * a.Weight) * Sigmoid.Derivative(Value));
        }

        return(Gradient = CalculateError(target.Value) * Sigmoid.Derivative(Value));
    }
Пример #2
0
    public float CalculateGradient(float?target = null)
    {
        if (target == null)
        {
            return(Gradient = OutputSynapses.Sum(x => x.OutputNeuton.Gradient * x.Weight) * Sigmoid.Derivative(Value));
        }

        return(Gradient = CalculateError(target.Value) * Sigmoid.Derivative(Value));
    }
        private void BackPropagation(double target)
        {
            OutputNeuron.Error =
                Sigmoid.Derivative(OutputNeuron.Output) *
                (target - OutputNeuron.Output);

            OutputNeuron.AdjustWeights();

            for (int h = 0; h < HiddenLayers; h++)
            {
                HiddenNeurons[h, 0].Error =
                    Sigmoid.Derivative(HiddenNeurons[h, 0].Output) *
                    OutputNeuron.Error *
                    OutputNeuron.Weights[0];

                HiddenNeurons[h, 1].Error =
                    Sigmoid.Derivative(HiddenNeurons[h, 1].Output) *
                    OutputNeuron.Error *
                    OutputNeuron.Weights[1];

                HiddenNeurons[h, 0].AdjustWeights();
                HiddenNeurons[h, 1].AdjustWeights();
            }
        }
Пример #4
0
 /// <summary>
 /// Updates the error of the output neuron based on some desired output and a sigmoid activation function.
 /// </summary>
 /// <param name="activation">The activation with which the output will be calculated/</param>
 /// <param name="desired">The desired output of this neuron for a given training set.</param>
 public override void UpdateError(Sigmoid activation, double desired)
 {
     Error = (this.Output - desired) * activation.Derivative(this.Net);
 }
Пример #5
0
 /// <summary>
 /// Updates the error of the neuron based on some activation function and some error coefficient (subject to change in Output Neurons).
 /// </summary>
 /// <param name="activation">The activation function with which the error will be calculated.</param>
 /// <param name="errorCoefficient">The standard coefficient of error for neurons.
 /// SUM (for I in Posterior Neurons) Error_i * W_ij. Where j is this neuron.</param>
 /// <returns>The neural error of the neuron.</returns>
 public virtual void UpdateError(Sigmoid activation, double errorCoefficient)
 {
     Error = activation.Derivative(Net) * errorCoefficient;
 }