コード例 #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)));
        }
コード例 #2
0
ファイル: SparseGaussian.cs プロジェクト: EnergonV/BestCS
        /// <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));
        }
コード例 #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)));
        }
コード例 #4
0
ファイル: SparseCauchy.cs プロジェクト: EnergonV/BestCS
        /// <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));
        }
コード例 #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));
        }
コード例 #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));
        }