public void BackPropagateNoBias_2NeuronTest() { double expectedWeight = 3; double actualWeight = 2; double inputData = 2; double expectedOutput = inputData * expectedWeight; double actualOutput = inputData * actualWeight; var layer = new DenseLayerNoBias(1, 1, new IdentityActivation(), new Distance()); layer.Initialize(); layer.Weights[0, 0] = actualWeight; var input = new double[] { inputData }; layer.Evaluate(input); Assert.AreEqual(actualOutput, layer.Output[0]); var inputError = new NNArray(1); layer.BackPropagate(input, new double[] { expectedOutput }, 1, inputError); double expectedErrorInput = (expectedOutput - actualOutput) * actualWeight; // I don't understand should be (expectedOutput - actualOutput) / actualWeight but docmentation show different Assert.AreEqual(expectedErrorInput, inputError[0]); }
public void LinearRegressionNeuronNoBiasTest() { // y = ax + b double a = -12, b = 0; int count = 5; int epoc; var layer = new DenseLayerNoBias(1, 1, new IdentityActivation(), new SquaredDistance()); layer.Initialize(); TrainRegression(a, b, count, layer, out epoc); Assert.IsTrue(epoc < 1000); Assert.IsTrue(Math.Abs(layer.Weights[0, 0] - a) / a < 0.01); // 1% error margin }