コード例 #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);
        }
コード例 #2
0
        public void SvmLayer_Forward()
        {
            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());

            var actual = sut.Forward(input);

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

            var expected = Matrix <float> .Build.Dense(batchSize, numberOfClasses, new float[] { 0.1234713f, 0.7669879f, -0.9698473f, 1.814438f, 0.2316814f, -0.05312517f, 0.5537131f, -0.2031853f, 0.01274186f, -0.4482329f });

            MatrixAsserts.AreEqual(expected, actual);
        }