Пример #1
0
        public void DistanceTest()
        {
            Quadratic target = new Quadratic(1);

            double[] x = new double[] { 1, 1 };
            double[] y = new double[] { 1, 1 };

            double expected = 0;
            double actual   = target.Distance(x, y);

            Assert.AreEqual(expected, actual);


            x = new double[] { 0.5, 2.0 };
            y = new double[] { 1.3, -0.2 };

            expected = 31.8904;
            actual   = target.Distance(x, y);

            Assert.AreEqual(expected, actual);


            target = new Quadratic(3);

            x = new double[] { 9.4, 22.1 };
            y = new double[] { -6.21, 4 };

            expected = 337265.44515681011;
            actual   = target.Distance(x, y);
            Assert.AreEqual(expected, actual);
        }
Пример #2
0
        public void ExpandDistanceTest()
        {
            Quadratic kernel = new Quadratic(0);

            var x = new double[] { 0.5, 2.0 };
            var y = new double[] { 1.3, -0.2 };

            var phi_x = kernel.Transform(x);
            var phi_y = kernel.Transform(y);

            double phi_d = Distance.SquareEuclidean(phi_x, phi_y);
            double d     = kernel.Distance(x, y);

            Assert.AreEqual(phi_d, d);
        }
Пример #3
0
        public void ExpandDistanceWithConstantTest()
        {
            Quadratic kernel = new Quadratic(4.2);

            var x = new double[] { 0.5, 2.0 };
            var y = new double[] { 1.3, -0.2 };

            var phi_x = kernel.Transform(x);
            var phi_y = kernel.Transform(y);

            double d1 = Distance.SquareEuclidean(phi_x, phi_y);
            double d2 = kernel.Distance(x, y);
            double d3 = Accord.Statistics.Tools.Distance(kernel, x, y);

            Assert.AreEqual(66.9624, d1);
            Assert.AreEqual(66.9624, d2, 1e-10);
            Assert.AreEqual(66.9624, d3, 1e-10);

            Assert.IsFalse(double.IsNaN(d1));
            Assert.IsFalse(double.IsNaN(d2));
            Assert.IsFalse(double.IsNaN(d3));
        }