Exemple #1
0
        public void CrossEntropyTest()
        {
            var crossEntropyOH = new CrossEntropyOneHot();
            var crossEntropy   = new CrossEntropy();

            int nb = 10;

            double[] input  = new double[nb];
            double[] output = new double[nb];
            for (int i = 0; i < nb; i++)
            {
                input[i] = Math.PI * rnd.NextDouble();
            }

            var softmax = new Softmax();

            softmax.Activate(input, output);

            double[] expectedOutput = new double[nb];
            expectedOutput[output.ArgMax()] = 1;

            double[] errors    = new double[nb];
            double   entropyOH = crossEntropyOH.Evaluate(output, expectedOutput, errors);
            double   entropy   = crossEntropy.Evaluate(output, expectedOutput, errors);

            Assert.AreEqual(entropyOH, entropy);
        }