コード例 #1
0
        public void Fowardの式が正しい()
        {
            var testInput = new Variable(DenseMatrix.OfArray(new float[, ] {
                { -100, -1, 0.5f, 1, 100 }
            }));
            var testOutput = ReLU.ForwardStatic(testInput);
            var expected   = DenseMatrix.OfArray(new float[, ] {
                { 0, 0, 0.5f, 1f, 100f }
            });                                                                        // by chainer

            chainer.Helper.AssertMatrixAlmostEqual(testOutput.Value, expected);
        }
コード例 #2
0
        public void Backardの式が正しい()
        {
            var testInput = new Variable(DenseMatrix.OfArray(new float[, ] {
                { 1, 2, 3 }
            }));
            var target = new Variable(DenseMatrix.OfArray(new float[, ] {
                { 0.5f, 0.5f, 0.5f }
            }));
            var loss = MeanSquaredError.ForwardStatic(
                ReLU.ForwardStatic(testInput),
                target
                );

            loss.Backward();
            chainer.Helper.AssertMatrixAlmostEqual(
                DenseMatrix.OfArray(new float[, ] {
                { 0.33333334f, 1f, 1.66666675f }
            }),                                                                     // by chainer.py
                testInput.Grad
                );
        }