Accord.Tests.Interop.Math.TSNETest.computeGradient_1 C# (CSharp) Method

computeGradient_1() private method

private computeGradient_1 ( ) : void
return void
        public void computeGradient_1()
        {
            Accord.Math.Random.Generator.Seed = 0;

            double perplexity = 0.5;
            double theta = 0.5;
            int N = 100;
            int K = (int)(3 * perplexity);
            int D = 3;
            uint[] row_P = Vector.Create(N + 1, new uint[] { 0, 1, 2, 3, 4, 5, 6 });
            uint[] col_P = Vector.Create(N * K, new uint[] { 5, 3, 1, 1, 2, 1 });
            double[] val_P = Vector.Create(N * K, new double[] 
            { 
                0.83901046609114708, 
                0.39701047304189827,
                0.19501046869768451,
                0.59401047304189827,	
                0.49301046869768484,
                0.59901046869768451,
            });

            double[,] P = Matrix.Random(N, N, new NormalDistribution());
            double[][] p = P.ToJagged();

            double[,] Y = Matrix.Random(N, D, new NormalDistribution());
            double[][] y = Y.ToJagged();



            uint[] expected_row = Vector.Create(row_P);
            uint[] expected_col = Vector.Create(col_P);
            double[] expected_val = Vector.Create(val_P);
            double[,] expected = Matrix.Zeros(N, D);
            TSNEWrapper.computeGradient(P, expected_row, expected_col, expected_val, Y, N, D, expected, theta);

            int[] actual_row = row_P.To<int[]>();
            int[] actual_col = col_P.To<int[]>();
            double[] actual_val = (double[])val_P.Clone();
            double[][] actual = Jagged.Zeros(N, D);
            TSNE.computeGradient(p, actual_row, actual_col, actual_val, y, N, D, actual, theta);

            Assert.IsTrue(actual.IsEqual(expected));
            Assert.IsTrue(actual_row.IsEqual(expected_row));
            Assert.IsTrue(actual_col.IsEqual(expected_col));
            Assert.IsTrue(actual_val.IsEqual(expected_val, 1e-4));
        }