Example #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)));
        }
Example #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));
        }
Example #3
0
        /// <summary>
        ///   Laplacian 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 * Math.Sqrt(norm)));
        }
Example #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);
            }

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

            return(1.0 / (1.0 + norm / Sigma));
        }
Example #5
0
        /// <summary>
        ///   Polynomial 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)
        {
            double sum = SparseLinear.Product(x, y) + constant;

            return(Math.Pow(sum, Degree));
        }
Example #6
0
        /// <summary>
        ///   Sigmoid 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)
        {
            double sum = SparseLinear.Product(x, y);

            return(System.Math.Tanh(Gamma * sum + Constant));
        }