Ejemplo n.º 1
0
        public void HellingerDistancePrimeTest()
        {
            var actual = new Matrix(4, 1);

            actual.InRandomize();
            var expected = new Matrix(4, 1);

            expected.InRandomize();

            var gradMatrix = actual.Duplicate();

            for (var i = 0; i < actual.Rows; i++)
            {
                for (var j = 0; j < actual.Columns; j++)
                {
                    gradMatrix[i, j] = (Math.Sqrt(actual[i, j]) - Math.Sqrt(expected[i, j])) / (Math.Sqrt(2) * Math.Sqrt(actual[i, j]));
                }
            }

            var cost             = new HellingerDistanceKernel();
            var calculatedMatrix = cost.Backward(actual, expected);

            Assert.IsTrue(gradMatrix == calculatedMatrix, "Hellinger Distance Derivative successful");
        }
Ejemplo n.º 2
0
        public void HellingerDistanceTest()
        {
            var error  = 0.0;
            var actual = new Matrix(4, 1);

            actual.InRandomize();
            var expected = new Matrix(4, 1);

            expected.InRandomize();

            for (var i = 0; i < actual.Rows; i++)
            {
                for (var j = 0; j < actual.Columns; j++)
                {
                    error += Math.Pow(Math.Sqrt(actual[i, j]) - Math.Sqrt(expected[i, j]), 2);
                }
            }
            error *= 1 / Math.Sqrt(2);

            var cost            = new HellingerDistanceKernel();
            var calculatedError = cost.Forward(actual, expected);

            Assert.IsTrue(Math.Abs(error - calculatedError) < 0.01f, "Hellinger Distance successful");
        }