Accord.Statistics.Kernels.Quadratic.ReverseDistance C# (CSharp) Method

ReverseDistance() public method

Computes the distance in input space between two points given in feature space.
public ReverseDistance ( double x, double y ) : double
x double Vector x in feature (kernel) space.
y double Vector y in feature (kernel) space.
return double
        public double ReverseDistance(double[] x, double[] y)
        {
            double sumx = 0;
            double sumy = 0;
            double sum = 0;

            for (int i = 0; i < x.Length; i++)
            {
                sumx += x[i] * x[i];
                sumy += y[i] * y[i];
                sum += x[i] * y[i];
            }


            return Math.Sqrt(sumx) + Math.Sqrt(sumy) - 2.0 * Math.Sqrt(sum);
        }

Usage Example

Example #1
0
        public void ExpandReverseDistanceWithConstantTest()
        {
            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 d = Distance.SquareEuclidean(x, y);
            double phi_d = kernel.ReverseDistance(phi_x, phi_y);

            Assert.AreEqual(5.48, phi_d, 1e-10);
            Assert.AreEqual(5.48, d);

            Assert.IsFalse(double.IsNaN(phi_d));
            Assert.IsFalse(double.IsNaN(d));
        }
All Usage Examples Of Accord.Statistics.Kernels.Quadratic::ReverseDistance