示例#1
0
        public void SvmLayer_Backward()
        {
            var batchSize       = 1;
            var width           = 28;
            var height          = 28;
            var depth           = 3;
            var numberOfClasses = 10;
            var random          = new Random(232);

            var sut = new SvmLayer(numberOfClasses);

            sut.Initialize(width, height, depth, batchSize, Initialization.GlorotUniform, random);

            var input = Matrix <float> .Build.Random(batchSize, numberOfClasses, random.Next());

            sut.Forward(input);

            var delta = Matrix <float> .Build.Random(batchSize, numberOfClasses, random.Next());

            var actual = sut.Backward(delta);

            Trace.WriteLine(string.Join(", ", actual.ToColumnMajorArray()));

            var expected = Matrix <float> .Build.Dense(batchSize, numberOfClasses, new float[] { 1f, 1f, 1f, 1f, 1f, -9f, 1f, 1f, 1f, 1f });

            MatrixAsserts.AreEqual(expected, actual);
        }