Algorithm-SVMLight

 view release on metacpan or  search on metacpan

SVMLight.patch  view on Meta::CPAN

+}
+
+void set_learning_defaults(LEARN_PARM *learn_parm, KERNEL_PARM *kernel_parm)
+{
+  learn_parm->type=CLASSIFICATION;
+  strcpy (learn_parm->predfile, "trans_predictions");
+  strcpy (learn_parm->alphafile, "");
+  learn_parm->biased_hyperplane=1;
+  learn_parm->sharedslack=0;
+  learn_parm->remove_inconsistent=0;
+  learn_parm->skip_final_opt_check=0;
+  learn_parm->svm_maxqpsize=10;
+  learn_parm->svm_newvarsinqp=0;
+  learn_parm->svm_iter_to_shrink=2;
+  learn_parm->maxiter=100000;
+  learn_parm->kernel_cache_size=40;
+  learn_parm->svm_c=0.0;
+  learn_parm->eps=0.1;
+  learn_parm->transduction_posratio=-1.0;
+  learn_parm->svm_costratio=1.0;
+  learn_parm->svm_costratio_unlab=1.0;
+  learn_parm->svm_unlabbound=1E-5;
+  learn_parm->epsilon_crit=0.001;
+  learn_parm->epsilon_a=1E-15;
+  learn_parm->compute_loo=0;
+  learn_parm->rho=1.0;
+  learn_parm->xa_depth=0;
+  learn_parm->costfunc=&costfunc;
+  learn_parm->costfunccustom=NULL;
+
+  kernel_parm->kernel_type=LINEAR;
+  kernel_parm->poly_degree=3;
+  kernel_parm->rbf_gamma=1.0;
+  kernel_parm->coef_lin=1;
+  kernel_parm->coef_const=1;
+  strcpy(kernel_parm->custom,"empty");
+}
+
+int check_learning_parms(LEARN_PARM *learn_parm, KERNEL_PARM *kernel_parm)
+{
+  if((learn_parm->skip_final_opt_check) 
+     && (kernel_parm->kernel_type == LINEAR)) {
+    printf("\nIt does not make sense to skip the final optimality check for linear kernels.\n\n");
+    learn_parm->skip_final_opt_check=0;
+  }    
+  if((learn_parm->skip_final_opt_check) 
+     && (learn_parm->remove_inconsistent)) {
+    printf("\nIt is necessary to do the final optimality check when removing inconsistent \nexamples.\n");
+    return 0;
+  }    
+  if((learn_parm->svm_maxqpsize<2)) {
+    printf("\nMaximum size of QP-subproblems not in valid range: %ld [2..]\n",learn_parm->svm_maxqpsize); 
+    return 0;
+  }
+  if((learn_parm->svm_maxqpsize<learn_parm->svm_newvarsinqp)) {
+    printf("\nMaximum size of QP-subproblems [%ld] must be larger than the number of\n",learn_parm->svm_maxqpsize); 
+    printf("new variables [%ld] entering the working set in each iteration.\n",learn_parm->svm_newvarsinqp); 
+    return 0;
+  }
+  if(learn_parm->svm_iter_to_shrink<1) {
+    printf("\nMaximum number of iterations for shrinking not in valid range: %ld [1,..]\n",learn_parm->svm_iter_to_shrink);
+    return 0;
+  }
+  if(learn_parm->svm_c<0) {
+    printf("\nThe C parameter must be greater than zero!\n\n");
+    return 0;
+  }
+  if(learn_parm->transduction_posratio>1) {
+    printf("\nThe fraction of unlabeled examples to classify as positives must\n");
+    printf("be less than 1.0 !!!\n\n");
+    return 0;
+  }
+  if(learn_parm->svm_costratio<=0) {
+    printf("\nThe COSTRATIO parameter must be greater than zero!\n\n");
+    return 0;
+  }
+  if(learn_parm->epsilon_crit<=0) {
+    printf("\nThe epsilon parameter must be greater than zero!\n\n");
+    return 0;
+  }
+  if(learn_parm->rho<0) {
+    printf("\nThe parameter rho for xi/alpha-estimates and leave-one-out pruning must\n");
+    printf("be greater than zero (typically 1.0 or 2.0, see T. Joachims, Estimating the\n");
+    printf("Generalization Performance of an SVM Efficiently, ICML, 2000.)!\n\n");
+    return 0;
+  }
+  if((learn_parm->xa_depth<0) || (learn_parm->xa_depth>100)) {
+    printf("\nThe parameter depth for ext. xi/alpha-estimates must be in [0..100] (zero\n");
+    printf("for switching to the conventional xa/estimates described in T. Joachims,\n");
+    printf("Estimating the Generalization Performance of an SVM Efficiently, ICML, 2000.)\n");
+    return 0;
+  }
+  return 1;
+}
+
 void nol_ll(char *file, long int *nol, long int *wol, long int *ll) 
      /* Grep through file and count number of lines, maximum number of
         spaces per line, and longest line. */
diff -urb svm_light/svm_common.h svm_light-new/svm_common.h
--- svm_light/svm_common.h	2008-10-08 15:34:58.000000000 -0500
+++ svm_light-new/svm_common.h	2008-11-18 14:06:33.000000000 -0600
@@ -27,8 +27,8 @@
 # include <time.h> 
 # include <float.h>
 
-# define VERSION       "V6.02"
-# define VERSION_DATE  "14.08.08"
+# define SVMLIGHT_VERSION       "V6.02"
+# define SVMLIGHT_VERSION_DATE  "14.08.08"
 
 # define CFLOAT  float       /* the type of float to use for caching */
                              /* kernel evaluations. Using float saves */
@@ -179,6 +179,8 @@
   double svm_unlabbound;
   double *svm_cost;            /* individual upper bounds for each var */
   long   totwords;             /* number of features */
+  double (*costfunc)(DOC **, double *, long, long, struct learn_parm *);
+  void   *costfunccustom;
 } LEARN_PARM;
 
 typedef struct kernel_parm {

SVMLight.patch  view on Meta::CPAN

-  learn_parm->skip_final_opt_check=0;
-  learn_parm->svm_maxqpsize=10;
-  learn_parm->svm_newvarsinqp=0;
-  learn_parm->svm_iter_to_shrink=-9999;
-  learn_parm->maxiter=100000;
-  learn_parm->kernel_cache_size=40;
-  learn_parm->svm_c=0.0;
-  learn_parm->eps=0.1;
-  learn_parm->transduction_posratio=-1.0;
-  learn_parm->svm_costratio=1.0;
-  learn_parm->svm_costratio_unlab=1.0;
-  learn_parm->svm_unlabbound=1E-5;
-  learn_parm->epsilon_crit=0.001;
-  learn_parm->epsilon_a=1E-15;
-  learn_parm->compute_loo=0;
-  learn_parm->rho=1.0;
-  learn_parm->xa_depth=0;
-  kernel_parm->kernel_type=0;
-  kernel_parm->poly_degree=3;
-  kernel_parm->rbf_gamma=1.0;
-  kernel_parm->coef_lin=1;
-  kernel_parm->coef_const=1;
-  strcpy(kernel_parm->custom,"empty");
   strcpy(type,"c");
 
+  set_learning_defaults(learn_parm, kernel_parm);
+
   for(i=1;(i<argc) && ((argv[i])[0] == '-');i++) {
     switch ((argv[i])[1]) 
       { 
@@ -221,74 +195,8 @@
     print_help();
     exit(0);
   }    
-  if((learn_parm->skip_final_opt_check) 
-     && (kernel_parm->kernel_type == LINEAR)) {
-    printf("\nIt does not make sense to skip the final optimality check for linear kernels.\n\n");
-    learn_parm->skip_final_opt_check=0;
-  }    
-  if((learn_parm->skip_final_opt_check) 
-     && (learn_parm->remove_inconsistent)) {
-    printf("\nIt is necessary to do the final optimality check when removing inconsistent \nexamples.\n");
-    wait_any_key();
-    print_help();
-    exit(0);
-  }    
-  if((learn_parm->svm_maxqpsize<2)) {
-    printf("\nMaximum size of QP-subproblems not in valid range: %ld [2..]\n",learn_parm->svm_maxqpsize); 
-    wait_any_key();
-    print_help();
-    exit(0);
-  }
-  if((learn_parm->svm_maxqpsize<learn_parm->svm_newvarsinqp)) {
-    printf("\nMaximum size of QP-subproblems [%ld] must be larger than the number of\n",learn_parm->svm_maxqpsize); 
-    printf("new variables [%ld] entering the working set in each iteration.\n",learn_parm->svm_newvarsinqp); 
-    wait_any_key();
-    print_help();
-    exit(0);
-  }
-  if(learn_parm->svm_iter_to_shrink<1) {
-    printf("\nMaximum number of iterations for shrinking not in valid range: %ld [1,..]\n",learn_parm->svm_iter_to_shrink);
-    wait_any_key();
-    print_help();
-    exit(0);
-  }
-  if(learn_parm->svm_c<0) {
-    printf("\nThe C parameter must be greater than zero!\n\n");
-    wait_any_key();
-    print_help();
-    exit(0);
-  }
-  if(learn_parm->transduction_posratio>1) {
-    printf("\nThe fraction of unlabeled examples to classify as positives must\n");
-    printf("be less than 1.0 !!!\n\n");
-    wait_any_key();
-    print_help();
-    exit(0);
-  }
-  if(learn_parm->svm_costratio<=0) {
-    printf("\nThe COSTRATIO parameter must be greater than zero!\n\n");
-    wait_any_key();
-    print_help();
-    exit(0);
-  }
-  if(learn_parm->epsilon_crit<=0) {
-    printf("\nThe epsilon parameter must be greater than zero!\n\n");
-    wait_any_key();
-    print_help();
-    exit(0);
-  }
-  if(learn_parm->rho<0) {
-    printf("\nThe parameter rho for xi/alpha-estimates and leave-one-out pruning must\n");
-    printf("be greater than zero (typically 1.0 or 2.0, see T. Joachims, Estimating the\n");
-    printf("Generalization Performance of an SVM Efficiently, ICML, 2000.)!\n\n");
-    wait_any_key();
-    print_help();
-    exit(0);
-  }
-  if((learn_parm->xa_depth<0) || (learn_parm->xa_depth>100)) {
-    printf("\nThe parameter depth for ext. xi/alpha-estimates must be in [0..100] (zero\n");
-    printf("for switching to the conventional xa/estimates described in T. Joachims,\n");
-    printf("Estimating the Generalization Performance of an SVM Efficiently, ICML, 2000.)\n");
+
+  if (!check_learning_parms(learn_parm, kernel_parm)) {
     wait_any_key();
     print_help();
     exit(0);
@@ -303,7 +211,7 @@
 
 void print_help()
 {
-  printf("\nSVM-light %s: Support Vector Machine, learning module     %s\n",VERSION,VERSION_DATE);
+  printf("\nSVM-light %s: Support Vector Machine, learning module     %s\n",SVMLIGHT_VERSION,SVMLIGHT_VERSION_DATE);
   copyright_notice();
   printf("   usage: svm_learn [options] example_file model_file\n\n");
   printf("Arguments:\n");
@@ -379,7 +287,7 @@
   wait_any_key();
   printf("\nMore details in:\n");
   printf("[1] T. Joachims, Making Large-Scale SVM Learning Practical. Advances in\n");
-  printf("    Kernel Methods - Support Vector Learning, B. Schölkopf and C. Burges and\n");



( run in 0.753 second using v1.01-cache-2.11-cpan-96521ef73a4 )