コード例 #1
0
        /// <summary>
        ///   Computes the squared distance in feature space
        ///   between two points given in input space.
        /// </summary>
        ///
        /// <param name="x">Vector <c>x</c> in input space.</param>
        /// <param name="y">Vector <c>y</c> in input space.</param>
        ///
        /// <returns>Squared distance between <c>x</c> and <c>y</c> in feature (kernel) space.</returns>
        ///
        public double Distance(Sparse <double> x, Sparse <double> y)
        {
            if (x == y)
            {
                return(0.0);
            }

            double sumx = constant + x.Dot(x);
            double sumy = constant + y.Dot(y);
            double sum  = constant + x.Dot(y);

            int d = degree;

            return(Math.Pow(sumx, d) + Math.Pow(sumy, d) - 2 * Math.Pow(sum, d));
        }
コード例 #2
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 double Function(Sparse <double> x, Sparse <double> y)
        {
            double sum = x.Dot(y);

            double value = Math.Tanh(alpha * sum + constant);

            return(value);
        }
コード例 #3
0
 /// <summary>
 /// The 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 double Function(double[] y, Sparse <double> x)
 {
     return(x.Dot(y) + constant);
 }
コード例 #4
0
 /// <summary>
 /// The 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 double Function(Sparse <double> x, Sparse <double> y)
 {
     return(x.Dot(y) + constant);
 }
コード例 #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 double Function(Sparse <double> x, Sparse <double> y)
        {
            double sum = x.Dot(y) + constant;

            return(Math.Pow(sum, degree));
        }