public void TestForward() { var parameterGenerator = new ActionParameterGenerator(() => 0.1, () => 1.0); var neuronFactor = new NeuronFactory(parameterGenerator); var synapseFactory = new SynapseFactory(parameterGenerator); var n = NetworkFactory.CreateMultilayerPerceptron(new[] { 2, 2, 1 }, ActivationFunction.Sigmoid, ActivationFunction.Identity, null, neuronFactor, synapseFactory); var x = new Vector(3, 5); Assert.IsTrue(Math.Abs(n.Compute(x)[0] - 2.0993931) < 0.001); }
public void TestBack() { var parameterGenerator = new ActionParameterGenerator(() => 0.1, () => 1.0); var neuronFactor = new NeuronFactory(parameterGenerator); var synapseFactory = new SynapseFactory(parameterGenerator); var network = NetworkFactory.CreateMultilayerPerceptron(new[] { 2, 2, 1, 1 }, ActivationFunction.Sigmoid, ActivationFunction.Identity, null, neuronFactor, synapseFactory); var networkTrainer = new NetworkTrainer(network); var x = new Vector(3, 5); network.Compute(x); networkTrainer.Back(42.0); var n = network.OutputLayer[0].Inputs[0].Source; Console.WriteLine(n.InputDerivative); Console.WriteLine(n.OutputDerivative); Console.WriteLine(n.InputDerivativeCount); Assert.IsTrue(Math.Abs(-3.987764 - n.InputDerivative) < 0.01); Assert.IsTrue(Math.Abs(-41.009155 - n.OutputDerivative) < 0.01); Assert.AreEqual(1, n.InputDerivativeCount); }