SquaredEuclidean() public static method

Computes the squared Euclidean distance of two vectors given in sparse representation.
public static SquaredEuclidean ( double x, double y ) : double
x double The first vector x.
y double The second vector y.
return double
Ejemplo n.º 1
0
        /// <summary>
        ///   Computes the distance in input space
        ///   between two points given in feature space.
        /// </summary>
        ///
        /// <param name="x">Vector <c>x</c> in feature (kernel) space.</param>
        /// <param name="y">Vector <c>y</c> in feature (kernel) space.</param>
        ///
        /// <returns>Distance between <c>x</c> and <c>y</c> in input space.</returns>
        ///
        public override double Distance(double[] x, double[] y)
        {
            if (x == y)
            {
                return(0.0);
            }

            double norm = SparseLinear.SquaredEuclidean(x, y);

            return(2 - 2 * Math.Exp(-gamma * Math.Sqrt(norm)));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Computes the squared distance in input space
        ///   between two points given in feature space.
        /// </summary>
        ///
        /// <param name="x">Vector <c>x</c> in feature (kernel) space.</param>
        /// <param name="y">Vector <c>y</c> in feature (kernel) space.</param>
        ///
        /// <returns>
        ///   Squared distance between <c>x</c> and <c>y</c> in input space.
        /// </returns>
        ///
        public double ReverseDistance(double[] x, double[] y)
        {
            if (x == y)
            {
                return(0.0);
            }

            double norm = SparseLinear.SquaredEuclidean(x, y);

            return(-(1.0 / gamma) * Math.Log(1.0 - 0.5 * norm));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gaussian Kernel function.
        /// </summary>
        ///
        /// <param name="x">Vector <c>x</c> in input space.</param>
        /// <param name="y">Vector <c>y</c> in input space.</param>
        /// <returns>Dot product in feature (kernel) space.</returns>
        ///
        public override double Function(double[] x, double[] y)
        {
            // Optimization in case x and y are
            // exactly the same object reference.

            if (x == y)
            {
                return(1.0);
            }

            double norm = SparseLinear.SquaredEuclidean(x, y);

            return(Math.Exp(-gamma * norm));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Cauchy Kernel Function
        /// </summary>
        ///
        /// <param name="x">Vector <c>x</c> in input space.</param>
        /// <param name="y">Vector <c>y</c> in input space.</param>
        ///
        /// <returns>Dot product in feature (kernel) space.</returns>
        ///
        public override double Function(double[] x, double[] y)
        {
            // Optimization in case x and y are
            // exactly the same object reference.

            if (x == y)
            {
                return(1.0);
            }
#pragma warning disable 0618

            double norm = SparseLinear.SquaredEuclidean(x, y);

            return(1.0 / (1.0 + norm / Sigma));
        }