⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ginitrain.cpp

📁 SVM经典调试程序,内有说明,应用简便,可用做回归分类方面的计算
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************/// NAME  :        svmtest.cpp// // DESCRIPTION :  A sample svmtest file that demonstrate the usage of//                GINI SVM interface./////*****************************************************************************/#define _GINI_COUT_PRESENT_#define _HMMSVM_DEBUGON_#include<ginisvm.h>#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>//---------------------------------------------------------------------------// Print the Help for this code.//---------------------------------------------------------------------------void PrintHelp(){   printf("#------------------------------------------------------------------#\n");   printf("#         GINISVM VERSION 1.2                                      #\n");   printf("#   ( Center for Language and Speech Processing,JHU )              #\n");    printf("#------------------------------------------------------------------#\n");   printf("#------------------------------------------------------------------#\n");   printf("# Usage: ginitrain [cmdline] <inputfile> <configfile>              #\n");   printf("#                                                                  #\n");   printf("# Command Line arguments :                                         #\n");   printf("# -k <ktype>     0 -> Polynomial Kernel (a+b(x.y))^c               #\n");   printf("#                1 -> Gaussian Kernel  exp(-a ||x-y||^2)           #\n");   printf("#                2 -> DTK string kernel exp(-a*Leven(x,y))         #\n");   printf("#                                    ( b -> ins/del  penalty )     #\n");   printf("#                                    ( c -> same ins  penalty )    #\n");   printf("#                                    ( d -> subst  penalty )       #\n");   printf("#                3 -> Tanh Kernel  tanh(a(x.y))                    #\n");   printf("#                                                                  #\n");   printf("# -p1            Kernel parameter (a)                              #\n");   printf("# -p2            Kernel parameter (b)                              #\n");   printf("# -p3            Kernel parameter (c)                              #\n");   printf("# -p4            Kernel parameter (d)                              #\n");   printf("#                                                                  #\n");   printf("# -C             Regularization Constant ( default: 1 )            #\n");   printf("#                                                                  #\n");   printf("# -sp            sparse data format ( default: non-sparse )        #\n");   printf("#                                                                  #\n");   printf("# -precomp       Precomputes the kernel ( default: NO )            #\n");   printf("#                                                                  #\n");   printf("# -cflag         Flag to indicate weight of each data point        #\n");   printf("#                is read from the training file. The effective     #\n");   printf("#                value of C_i for that data is C*weight            #\n");   printf("#                                                                  #\n");   printf("# -pflag         Flag to indicate instead of the label, prior      #\n");   printf("#                probabilities for each data point  is specified.  #\n");   printf("#                                                                  #\n");   printf("# -B     <value> Rate-distortion factor ( default: M/(M-1)logM  )  #\n");   printf("#                M : numofclass ( Read from the training file )    #\n");   printf("#                                                                  #\n");   printf("# -cache <size>  Kernel Cache size [ number of data points ]       #\n");   printf("#                ( default: 5000 )                                 #\n");   printf("#                                                                  #\n");   printf("# -aeps  <value> Tolerance Value for training coefficients (0.001) #\n");   printf("#                                                                  #\n");   printf("# -keps  <value> Tolerance Value for KKT condition (0.1)           #\n");   printf("#                                                                  #\n");   printf("# -win   <value> Search Window for Random optimization (0)       #\n");   printf("#                                                                  #\n");   printf("# -ceps  <value> Tolerance Value for decrease in cost (0.00001)    #\n");   printf("#                                                                  #\n");   printf("# -niter <value> Number of passes through data before cost is      #\n");   printf("#                computed ( 10 ).                                  #\n");   printf("#                                                                  #\n");   printf("# -nhits <value> Number of cache hits by a data point before       #\n");   printf("#                the kernel cache is updated ( 0 )                 #\n");   printf("#                                                                  #\n");   printf("# -srch  <value> Maximum number of sv to be searched before        #\n");   printf("#                giving up on the data point (100)                 #\n");   printf("#                                                                  #\n");   printf("# -liter <value> Threshold in percentage of optimization failures #\n");   printf("#                before kkt tolerance is doubled                   #\n");   printf("#                                                                  #\n");   printf("# -fpass <value> Number of passes through the entire data before   #\n");   printf("#                working with the smaller subset. This paramenter  #\n");   printf("#                is important because it ensures that most of the  #\n");   printf("#                svs have been identified (5)                      #\n");   printf("#                                                                  #\n");   printf("# -v             Verbose flag to print detail optimization info    #\n");   printf("#                                                                  #\n");   printf("#------------------------------------------------------------------#\n");   printf("# <inputfile>   Input training file                                #\n");   printf("# <configfile> File where training parameters are stored           #\n");   printf("#------------------------------------------------------------------#\n");   printf("# Sample Usage :                                                   #\n");   printf("# ginisvm -k 0 -p1 1 -p2 1 -p3 2  train.dat train.cfg              #\n");   printf("#------------------------------------------------------------------#\n");   printf("#   Bug Reports: shantanu@jhu.edu                                  #\n");   printf("#------------------------------------------------------------------#\n");}// -------------------------------------------------------------------------//   Main Routine.// -------------------------------------------------------------------------int main(int argc, char** argv){   GINISVMKernelType ktype = GINISVMPOLY;   GINI_double p1 = 0;   GINI_double p2 = 1;   GINI_double p3 = 1;   GINI_double p4 = 1;   GINI_double B  = 0.0;   GINI_double C  = 1.0;   GINI_bool   sp = GINI_FALSE;   GINI_bool   cflag = GINI_FALSE;   GINI_bool   pflag = GINI_FALSE;   GINI_bool   precomp = GINI_FALSE;   GINI_bool   verbose = GINI_FALSE;   GINI_u32    csize = 5000;   GINI_double aeps  = 0.001;   GINI_double keps  = 0.01;   GINI_double ceps  = 0.00001;   GINI_u32    win   = 0;   GINI_u32    niter = 10;   GINI_u32    nhits = 0;   GINI_u32    srch = 0;   GINI_u32    liter = 75;   GINI_u32    fpass = 5;   GINI_u32    SVM_DIMENSION;   GINI_u32    SVM_CLASS;   GINI_u32    SVM_DATA;   GINI_SVMKernel *kernel = (GINI_SVMKernel*) GINI_NULL;   GINI_int    count = 1;   // Check the number of input parameters.   if ( argc <= 3 )   {      PrintHelp();      return 1;   }   GINI_bool validarg;   // Kernel definition goes here   while ( count < argc-2 )   {      validarg = GINI_FALSE;      if ( strcmp(argv[count],"-k") == 0 )      {         count++;         if ( strcmp(argv[count],"0") == 0 )		 ktype = GINISVMPOLY;	 else if ( strcmp(argv[count],"1") == 0 )		 ktype = GINISVMGAUSSIAN;	 else if ( strcmp(argv[count],"2") == 0 )		 ktype = GINISVMDTK;	 else if ( strcmp(argv[count],"3") == 0 )		 ktype = GINISVMTANH;	 else          {	     PrintHelp();	     return 1;         }	 validarg = GINI_TRUE;	 count++;      }         if ( strcmp(argv[count],"-p1") == 0 )      {         count++;	 p1 = atof(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-p2") == 0 )      {         count++;	 p2 = atof(argv[count++]);	 validarg = GINI_TRUE;      }       if ( strcmp(argv[count],"-p3") == 0 )      {         count++;	 p3 = atof(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-p4") == 0 )      {         count++;	 p4 = atof(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-sp") == 0 )      {         sp = GINI_TRUE;	 count++;	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-precomp") == 0 )      {         precomp = GINI_TRUE;	 count++;	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-v") == 0 )      {         verbose = GINI_TRUE;	 count++;	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-cflag") == 0 )      {         cflag = GINI_TRUE;	 count++;	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-pflag") == 0 )      {         pflag = GINI_TRUE;	 count++;	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-B") == 0 )      {         count++;	 B = atof(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-C") == 0 )      {         count++;	 C = atof(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-cache") == 0 )      {         count++;	 csize = atoi(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-aeps") == 0 )      {         count++;	 aeps = atof(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-keps") == 0 )      {         count++;	 keps = atof(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-ceps") == 0 )      {         count++;	 ceps = atof(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-win") == 0 )      {         count++;	 win = (GINI_u32)atoi(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-niter") == 0 )      {         count++;	 niter = (GINI_u32)atoi(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-liter") == 0 )      {         count++;	 liter = (GINI_u32)atoi(argv[count++]);	 validarg = GINI_TRUE;      }      if ( strcmp(argv[count],"-nhits") == 0 )      {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -