Exemplo n.º 1
0
        public void cntk_softmax_test()
        {
            using (var K = new CNTKBackend())
            {
                double[,] a = new double[, ] {
                    { -4, 2 }, { 0.02, 0.3 }
                };
                var ta = K.variable(array: (Array)a, name: "example_var");

                var tr = K.softmax(ta);
                double[,] r = (double[, ])tr.eval();

                AssertEx.AreEqual(new double[, ] {
                    { 0.0024726231566347748, 0.99752737684336534 },
                    { 0.430453776060771, 0.56954622393922893 }
                }, r, 1e-8);

                AssertEx.AreEqual(r.GetRow(0), Accord.Math.Special.Softmax(a.GetRow(0)), 1e-8);
                AssertEx.AreEqual(r.GetRow(1), Accord.Math.Special.Softmax(a.GetRow(1)), 1e-8);
            }
        }