Example #1
0
        public override float Product(SparseVec element1, SparseVec element2)
        {
            float dot = linKernel.Product(element1, element2);

            float prod = (float)Math.Pow((Gamma * dot + Coef), Degree);

            return(prod);
        }
Example #2
0
        /// <summary>
        /// Computes rbf product, use base calass LinearKernel to compute normal dot product
        /// </summary>
        /// <param name="element1"></param>
        /// <param name="element2"></param>
        /// <returns></returns>
        public override float Product(SparseVec element1, SparseVec element2)
        {
            // epx(-g*|x-y|^2) =exp(-g*dot(x-y,x-y))= exp(-g*[ (x1-y1)^2+ ....(xN-yN)^2])
            //=exp(-g*( x1^2+...+xN^2 + y1^2+...+yN^2 -2x1y1+...+ -2xNyN))

            //float x1Squere = linKernel.Product(element1, element1);
            //float x2Squere = linKernel.Product(element2, element2);

            float x1Squere = (float)element1.DotProduct();
            float x2Squere = (float)element2.DotProduct();

            float dot = linKernel.Product(element1, element2);

            float prod = (float)Math.Exp(-Gamma * (x1Squere + x2Squere - 2 * dot));

            return(prod);
        }