Пример #1
0
    private static Dictionary <Node, double> UpdateOutputLayer(Layer outputLayer, double[] targetOutputs, ErrorFunctionType errorFunctionType, double learningRate, double momentumMagnitude)
    {
        var errorFunctionDifferential = ErrorFunctionResolver.ResolveErrorFunctionDifferential(errorFunctionType);

        var deltas = new Dictionary <Node, double>();

        for (var i = 0; i < outputLayer.Nodes.Count; i++)
        {
            var node  = outputLayer.Nodes[i];
            var delta = Math.MinMagnitude(errorFunctionDifferential.Invoke(targetOutputs[i], node.Output), 100)
                        * outputLayer.ActivationFunctionDifferential(node.Output)
                        * learningRate;
            deltas.Add(node, delta);
            foreach (var(prevNode, weightForPrevNode) in node.Weights)
            {
                UpdateNodeWeight(prevNode, weightForPrevNode, delta, momentumMagnitude);
            }

            foreach (var(_, weightForPrevLayer) in node.BiasWeights)
            {
                UpdateBiasNodeWeight(weightForPrevLayer, delta, momentumMagnitude);
            }
        }

        return(deltas);
    }
Пример #2
0
    private static Dictionary <Node, double> NegativeSampleOutput(Layer outputLayer, double targetOutput, int outputIndex, ErrorFunctionType errorFunctionType, double learningRate, double momentumMagnitude)
    {
        var errorFunctionDifferential = ErrorFunctionResolver.ResolveErrorFunctionDifferential(errorFunctionType);
        var outputNode = outputLayer.Nodes[outputIndex];

        var delta = errorFunctionDifferential.Invoke(targetOutput, outputNode.Output)
                    * outputLayer.ActivationFunctionDifferential(outputNode.Output)
                    * learningRate;

        foreach (var(prevNode, weightForPrevNode) in outputNode.Weights)
        {
            Backpropagation.UpdateNodeWeight(prevNode, weightForPrevNode, delta, momentumMagnitude);
        }
        foreach (var(_, weightForPrevLayer) in outputNode.BiasWeights)
        {
            Backpropagation.UpdateBiasNodeWeight(weightForPrevLayer, delta, momentumMagnitude);
        }

        return(new Dictionary <Node, double> {
            { outputNode, delta }
        });
    }