Esempio n. 1
0
            public void ExponentialTest()
            {
                var actual   = new Matrix(4, 1);
                var expected = new Matrix(4, 1);

                actual.InRandomize();
                expected.InRandomize();

                var autoErr = new Exponential().Evaluate(actual, expected);
                var error   = 0.0;

                for (var i = 0; i < actual.Rows; i++)
                {
                    for (var j = 0; j < actual.Columns; j++)
                    {
                        error += Math.Exp(-expected[i, j] * actual[i, j]);
                    }
                }
                error /= actual.Rows * actual.Columns;
                Assert.IsTrue(Math.Abs(error - autoErr) < 0.01, new Exponential().Type().ToString() + " Forward!");

                var autoDErr = new Exponential().Backward(actual, expected);
                var dErr     = new Matrix(actual.Rows, actual.Columns);

                for (var i = 0; i < actual.Rows; i++)
                {
                    for (var j = 0; j < actual.Columns; j++)
                    {
                        dErr[i, j] = -1 * Math.Exp(-expected[i, j] * actual[i, j]);
                    }
                }
                Assert.IsTrue(Math.Abs(dErr.FrobeniusNorm() - autoDErr.FrobeniusNorm()) < 0.01, new Exponential().Type().ToString() + " Backward!");
            }
Esempio n. 2
0
        public void ExponentialPrimeTest()
        {
            var a = new Matrix(2, 2);

            a.InRandomize();
            var b = a.Duplicate();

            a = new Exponential().Backward(a);
            b.InMap(Math.Exp);
            Assert.IsTrue(Math.Abs(a.FrobeniusNorm() - b.FrobeniusNorm()) < 0.1,
                          new Exponential().Type().ToString() + " Derivative.");
        }