GetSample2HiddenLayerPerceptron() public static method

public static GetSample2HiddenLayerPerceptron ( ) : MultilayerPerceptron
return MultilayerPerceptron
Exemplo n.º 1
0
        public void ShouldCalculateGrads_TwoHiddenLayersCase()
        {
            // See MultilayerPerceptronTests.xlsx in this folder for calculations of
            // expected outputs.
            var nn     = SampleInputs.GetSample2HiddenLayerPerceptron();
            var result = nn.CalculateGradients(SampleInputs.GetSampleInputs(), SampleInputs.GetSampleTargets());

            result.Should().NotBeNullOrEmpty();
            result.Should().HaveCount(3);

            var expectedHidden1Grads = new[] { 0.00197922538436067, 0.00395845076872135, 0.0197922538436067, 0.00200603359153654, 0.00401206718307308, 0.0200603359153654, 0.00203160809301684, 0.00406321618603367, 0.0203160809301684 };
            var expectedHidden2Grads = new[] { 0.00976178390929107, 0.0100948877912437, 0.0104249927460735, 0.0290204923445045, 0.00720465406099808, 0.00745050033849661, 0.00769413326721845, 0.0214184835440782 };
            var expectedOutputGrads  = new[] { -0.390542035775992, -0.44184361704256, -0.561729160466126, 0.390542035775992, 0.44184361704256, 0.561729160466125 };

            result[2].ShouldApproximatelyEqual(expectedOutputGrads, 1e-12);
            result[1].ShouldApproximatelyEqual(expectedHidden2Grads, 1e-12);
            result[0].ShouldApproximatelyEqual(expectedHidden1Grads, 1e-12);
        }
Exemplo n.º 2
0
        public void ShouldCalculateCorrectly_TwoHiddenLayers()
        {
            var nn     = SampleInputs.GetSample2HiddenLayerPerceptron();
            var result = nn.FeedForward(SampleInputs.GetSampleInputs());

            result.HiddenLayers.Should().HaveCount(2);

            var expectedHidden1 = new[] { 0.336375544336332, 0.347853774202261, 0.359228665810271, 1.0 };

            result.HiddenLayers[0].ShouldApproximatelyEqual(expectedHidden1, 1e-12);

            var expectedHidden2 = new[] { 0.695249709756778, 0.78657767504168, 1 };

            result.HiddenLayers[1].ShouldApproximatelyEqual(expectedHidden2, 1e-12);

            var expectedOutput = new[] { 0.438270839533874, 0.561729160466125 };

            result.Output.ShouldApproximatelyEqual(expectedOutput, 1e-12);
        }