Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

const char* svm_check_parameter ( const svm_problem prob,
const svm_parameter param 
)

Definition at line 2652 of file svm.cpp.

References svm_parameter::C, C_SVC, svm_parameter::cache_size, svm_parameter::eps, EPSILON_SVR, svm_parameter::kernel_type, svm_problem::l, Malloc, min, svm_parameter::nu, NU_SVC, NU_SVR, ONE_CLASS, svm_parameter::p, svm_model::param, POLY, svm_parameter::probability, RBF, svm_parameter::shrinking, SIGMOID, SVM_LINEAR, svm_parameter::svm_type, and svm_problem::y.

02653 {
02654         // svm_type
02655 
02656         int svm_type = param->svm_type;
02657         if(svm_type != C_SVC &&
02658            svm_type != NU_SVC &&
02659            svm_type != ONE_CLASS &&
02660            svm_type != EPSILON_SVR &&
02661            svm_type != NU_SVR)
02662                 return "unknown svm type";
02663         
02664         // kernel_type
02665         
02666         int kernel_type = param->kernel_type;
02667         if(kernel_type != SVM_LINEAR &&
02668            kernel_type != POLY &&
02669            kernel_type != RBF &&
02670            kernel_type != SIGMOID)
02671                 return "unknown kernel type";
02672 
02673         // cache_size,eps,C,nu,p,shrinking
02674 
02675         if(param->cache_size <= 0)
02676                 return "cache_size <= 0";
02677 
02678         if(param->eps <= 0)
02679                 return "eps <= 0";
02680 
02681         if(svm_type == C_SVC ||
02682            svm_type == EPSILON_SVR ||
02683            svm_type == NU_SVR)
02684                 if(param->C <= 0)
02685                         return "C <= 0";
02686 
02687         if(svm_type == NU_SVC ||
02688            svm_type == ONE_CLASS ||
02689            svm_type == NU_SVR)
02690                 if(param->nu < 0 || param->nu > 1)
02691                         return "nu < 0 or nu > 1";
02692 
02693         if(svm_type == EPSILON_SVR)
02694                 if(param->p < 0)
02695                         return "p < 0";
02696 
02697         if(param->shrinking != 0 &&
02698            param->shrinking != 1)
02699                 return "shrinking != 0 and shrinking != 1";
02700 
02701         if(param->probability != 0 &&
02702            param->probability != 1)
02703                 return "probability != 0 and probability != 1";
02704 
02705         if(param->probability == 1 &&
02706            svm_type == ONE_CLASS)
02707                 return "one-class SVM probability output not supported yet";
02708 
02709 
02710         // check whether nu-svc is feasible
02711         
02712         if(svm_type == NU_SVC)
02713         {
02714                 int l = prob->l;
02715                 int max_nr_class = 16;
02716                 int nr_class = 0;
02717                 int *label = Malloc(int,max_nr_class);
02718                 int *count = Malloc(int,max_nr_class);
02719 
02720                 int i;
02721                 for(i=0;i<l;i++)
02722                 {
02723                         int this_label = (int)prob->y[i];
02724                         int j;
02725                         for(j=0;j<nr_class;j++)
02726                                 if(this_label == label[j])
02727                                 {
02728                                         ++count[j];
02729                                         break;
02730                                 }
02731                         if(j == nr_class)
02732                         {
02733                                 if(nr_class == max_nr_class)
02734                                 {
02735                                         max_nr_class *= 2;
02736                                         label = (int *)realloc(label,max_nr_class*sizeof(int));
02737                                         count = (int *)realloc(count,max_nr_class*sizeof(int));
02738                                 }
02739                                 label[nr_class] = this_label;
02740                                 count[nr_class] = 1;
02741                                 ++nr_class;
02742                         }
02743                 }
02744         
02745                 for(i=0;i<nr_class;i++)
02746                 {
02747                         int n1 = count[i];
02748                         for(int j=i+1;j<nr_class;j++)
02749                         {
02750                                 int n2 = count[j];
02751                                 if(param->nu*(n1+n2)/2 > min(n1,n2))
02752                                 {
02753                                         free(label);
02754                                         free(count);
02755                                         return "specified nu is infeasible";
02756                                 }
02757                         }
02758                 }
02759                 free(label);
02760                 free(count);
02761         }
02762 
02763         return NULL;
02764 }


Generated on Fri Mar 19 10:17:15 2010 for ImpalaSrc by  doxygen 1.5.1