diff --git a/modules/ml/doc/pics/SVM_Comparison.png b/modules/ml/doc/pics/SVM_Comparison.png new file mode 100644 index 000000000..4bb3dabab Binary files /dev/null and b/modules/ml/doc/pics/SVM_Comparison.png differ diff --git a/modules/ml/doc/support_vector_machines.rst b/modules/ml/doc/support_vector_machines.rst index bf88ec68c..7fd4fa01d 100644 --- a/modules/ml/doc/support_vector_machines.rst +++ b/modules/ml/doc/support_vector_machines.rst @@ -115,9 +115,13 @@ The constructors. * **CvSVM::SIGMOID** Sigmoid kernel: :math:`K(x_i, x_j) = \tanh(\gamma x_i^T x_j + coef0)`. + * **CvSVM::CHI2** Exponential Chi2 kernel, similar to the RBF kernel: :math:`K(x_i, x_j) = e^{-\gamma \chi^2(x_i,x_j)}, \chi^2(x_i,x_j) = (x_i-x_j)^2/(x_i+x_j), \gamma > 0`. + + * **CvSVM::INTER** Histogram intersection kernel. A fast kernel. :math:`K(x_i, x_j) = min(x_i,x_j)`. + :param degree: Parameter ``degree`` of a kernel function (POLY). - :param gamma: Parameter :math:`\gamma` of a kernel function (POLY / RBF / SIGMOID). + :param gamma: Parameter :math:`\gamma` of a kernel function (POLY / RBF / SIGMOID / CHI2). :param coef0: Parameter ``coef0`` of a kernel function (POLY / SIGMOID). @@ -142,6 +146,10 @@ The default constructor initialize the structure with following values: term_crit = cvTermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 1000, FLT_EPSILON ); } +A comparison of different kernels on the following 2D test case with four classes. Four C_SVC SVMs have been trained (one against rest) with auto_train. Evaluation on three different kernels (CHI2, INTER, RBF). The color depicts the class with max score. Bright means max-score > 0, dark means max-score < 0. + +.. image:: pics/SVM_Comparison.png + CvSVM diff --git a/modules/ml/src/svm.cpp b/modules/ml/src/svm.cpp index c7e41b700..be662f459 100644 --- a/modules/ml/src/svm.cpp +++ b/modules/ml/src/svm.cpp @@ -351,7 +351,7 @@ void CvSVMKernel::calc_chi2( int vcount, int var_count, const float** vecs, double chi2 = 0; for(k = 0 ; k < var_count; k++ ) { - double d = sample[k]*another[k]; + double d = sample[k]-another[k]; double devisor = sample[k]+another[k]; /// if devisor == 0, the Chi2 distance would be zero, but calculation would rise an error because of deviding by zero if (devisor != 0) @@ -359,7 +359,7 @@ void CvSVMKernel::calc_chi2( int vcount, int var_count, const float** vecs, chi2 += d*d/devisor; } } - results[j] = (Qfloat) (gamma*(1.0-2*chi2)); + results[j] = (Qfloat) (gamma*chi2); } if( vcount > 0 ) cvExp( &R, &R );