Esempio n. 1
0
        public static void SparseTest(KernelBase denseKernel, KernelBase sparseKernel)
        {
            double[][] sparse =
            {
                new double[] {   },
                new double[] {2, 1 },
                new double[] {1, 1 },
                new double[] {1, 1, 2, 1 }
            };

            double[][] dense =
            {
                new double[] { 0, 0 },
                new double[] { 0, 1 },
                new double[] { 1, 0 },
                new double[] { 1, 1 },
            };

            for (int i = 0; i < sparse.Length; i++)
            {
                for (int j = 0; j < sparse.Length; j++)
                {
                    double expected = denseKernel.Function(dense[i], dense[j]);
                    double actual   = sparseKernel.Function(sparse[i], sparse[j]);

                    Assert.AreEqual(expected, actual);
                }
            }

            for (int i = 0; i < sparse.Length; i++)
            {
                for (int j = 0; j < sparse.Length; j++)
                {
                    double expected = denseKernel.Distance(dense[i], dense[j]);
                    double actual   = sparseKernel.Distance(sparse[i], sparse[j]);

                    Assert.AreEqual(expected, actual);
                }
            }
        }