Exemplo n.º 1
0
        public void computeGaussianPerplexity2_larger()
        {
            var points = yinyang.Submatrix(null, 0, 1).ToJagged();

            double perplexity = 0.5;
            int    N          = points.Rows();
            int    D          = points.Columns();
            int    K          = (int)(3 * perplexity);

            double[,] X = points.ToMatrix();
            double[][] x = X.ToJagged();

            uint[]   expected_row = Vector.Zeros <uint>(200);
            uint[]   expected_col = Vector.Zeros <uint>(200);
            double[] expected_val = Vector.Zeros <double>(200);
            TSNEWrapper.computeGaussianPerplexity(X, N, D, expected_row, expected_col, expected_val, perplexity, K);

            int[]    actual_row = null;
            int[]    actual_col = null;
            double[] actual_val = null;
            TSNE.computeGaussianPerplexity(x, N, D, ref actual_row, ref actual_col, ref actual_val, perplexity, K);

            expected_row = expected_row.First(101);
            expected_col = expected_col.First(100);
            expected_val = expected_val.First(100);
            Assert.IsTrue(actual_row.IsEqual(expected_row));
            Assert.IsTrue(actual_col.IsEqual(expected_col));
            Assert.IsTrue(actual_val.IsEqual(expected_val, 1e-4));
        }
Exemplo n.º 2
0
        public void computeGaussianPerplexity_1()
        {
            double[][] points =
            {
                new double[] { 2, 3, 2 },
                new double[] { 5, 4, 5 },
                new double[] { 9, 6, 4 },
                new double[] { 4, 7, 5 },
                new double[] { 8, 1, 1 },
                new double[] { 1, 2, 4 },
            };

            double perplexity = 0.5;
            int    N          = points.Length;
            int    D          = 3;

            var X = points.ToMatrix();

            double[,] expected = new double[N, N];
            TSNEWrapper.computeGaussianPerplexity(X, N, D, expected, perplexity);

            double[][] actual = Jagged.Zeros(N, N);
            TSNE.computeGaussianPerplexity(points, N, D, ref actual, perplexity);

            Assert.IsTrue(actual.IsEqual(expected, rtol: 1e-5));
        }
Exemplo n.º 3
0
        public void computeGaussianPerplexity_larger()
        {
            var points = yinyang.Submatrix(null, 0, 1).ToJagged();

            double perplexity = 0.5;
            int    N          = points.Rows();
            int    D          = points.Columns();

            var X = points.ToMatrix();

            double[,] expected = new double[N, N];
            TSNEWrapper.computeGaussianPerplexity(X, N, D, expected, perplexity);

            double[][] actual = Jagged.Zeros(N, N);
            TSNE.computeGaussianPerplexity(points, N, D, ref actual, perplexity);

            Assert.IsTrue(actual.IsEqual(expected, rtol: 1e-5));
        }
Exemplo n.º 4
0
        public void computeGaussianPerplexity_2()
        {
            double[][] points =
            {
                new double[] { 2, 3,   20 },
                new double[] { 5, 4,    5 },
                new double[] { 9, 6,  500 },
                new double[] { 4, 7, -100 },
                new double[] { 8, 1,   67 },
                new double[] { 1, 2, -888 },
            };

            double perplexity = 0.5;
            int    N          = points.Length;
            int    D          = 3;
            int    K          = (int)(3 * perplexity);

            double[,] X = points.ToMatrix();
            double[][] x = X.ToJagged();

            uint[]   expected_row = Vector.Zeros <uint>(100);
            uint[]   expected_col = Vector.Zeros <uint>(100);
            double[] expected_val = Vector.Zeros <double>(100);
            TSNEWrapper.computeGaussianPerplexity(X, N, D, expected_row, expected_col, expected_val, perplexity, K);

            int[]    actual_row = null;
            int[]    actual_col = null;
            double[] actual_val = null;
            TSNE.computeGaussianPerplexity(x, N, D, ref actual_row, ref actual_col, ref actual_val, perplexity, K);

            expected_row = expected_row.First(7);
            expected_col = expected_col.First(6);
            expected_val = expected_val.First(6);
            Assert.IsTrue(actual_row.IsEqual(expected_row));
            Assert.IsTrue(actual_col.IsEqual(expected_col));
            Assert.IsTrue(actual_val.IsEqual(expected_val, 1e-4));
        }