Commits

Qian Zhu  committed c777235 Merge

Merge

  • Participants
  • Parent commits a30734b, 638dee0

Comments (0)

Files changed (7)

File src/libsvm.cpp

 namespace LIBSVM {
 
 #include "libsvm.h"
+  struct svm_node* CLIBSVM::x_space = NULL;
 
-bool CLIBSVM::initialize() {
+  bool CLIBSVM::initialize() {
 
-	/* set default */
+    /* set default */
 
-        parm.cache_size = 100;
-        parm.C = 0.01;
-	parm.eps = 1e-3;
-        parm.svm_type = C_SVC;
-        parm.p = 0.1;
-        parm.shrinking = 1;
-        parm.nr_weight = 0;
-        parm.weight_label = NULL;
-        parm.weight = NULL;
-        parm.probability = 0;
-        parm.nu = 0.5;
-        parm.coef0 = 0;
-        parm.gamma = 0;
-        parm.degree = 3;
-        parm.kernel_type = LINEAR;
+    parm.cache_size = 100;
+    parm.C = 0.01;
+    parm.eps = 1e-3;
+    parm.svm_type = C_SVC;
+    parm.p = 0.1;
+    parm.shrinking = 1;
+    parm.nr_weight = 0;
+    parm.weight_label = NULL;
+    parm.weight = NULL;
+    parm.probability = 0;
+    parm.nu = 0.5;
+    parm.coef0 = 0;
+    parm.gamma = 0;
+    parm.degree = 3;
+    parm.kernel_type = LINEAR;
 
-	return true;
-}
+    model = NULL;
 
-bool CLIBSVM::parms_check() {
-	if (parm.C < 0) {
-		fprintf(
-				stderr,
-				"\nTrade-off between training error and margin is not set (C<0)!\nC value will be set to default value. Clight = Cpef * 100 / n \n");
-		fprintf(stderr, "be less than 1.0 !!!\n\n");
-		return false;
-	}
-	if (parm.eps <= 0) {
-		fprintf(stderr,
-				"\nThe epsilon parameter must be greater than zero!\n\n");
-		return false;
-	}
+    balance = 0;//Off
 
-        //TODO: add more parameter checks 
+    return true;
+  }
 
-	return true;
-}
+  bool CLIBSVM::parms_check() {
+    if (parm.C < 0) {
+      fprintf(
+          stderr,
+          "\nTrade-off between training error and margin is not set (C<0)!\nC value will be set to default value. Clight = Cpef * 100 / n \n");
+      fprintf(stderr, "be less than 1.0 !!!\n\n");
+      return false;
+    }
+    if (parm.eps <= 0) {
+      fprintf(stderr,
+          "\nThe epsilon parameter must be greater than zero!\n\n");
+      return false;
+    }
 
-SAMPLE * CLIBSVM::CreateSample(Sleipnir::CPCL& PCL, vector<SVMLabel> SVMLabels) {
-	size_t i, j, k, iGene, iProblem, numFeatures, numLabels, max_index;
-        float d;
+    if (parm.nu < 0 | parm.nu > 1) {
+      fprintf(stderr, "nu parameter must be between 0 and 1");
+      return false;
+    }
 
-        struct svm_problem* prob;
-        struct svm_node* x_space;
+    //TODO: add more parameter checks 
 
-        prob = Malloc(struct svm_problem,1);
+    return true;
+  }
 
-//        prob->l = 0;//number of labels in PCL
-        numFeatures = PCL.GetExperiments();
-        numLabels = 0;
+  void CLIBSVM::SetXSpace(Sleipnir::CPCL& PCL) {
+    size_t j, k, iGene, numFeatures, numLabels;
+    std::vector<std::string> vecGeneNames;
+    string GeneName;
+    float d;
 
-        cout << "number of features: " << numFeatures << endl;
-	
-        iProblem = 0;
+    numFeatures = PCL.GetExperiments();
+    numLabels = PCL.GetGenes();
+    vecGeneNames = PCL.GetGeneNames();
 
-	for (i = 0; i < SVMLabels.size(); i++) {
-                if (!SVMLabels[i].hasIndex){
-                  SVMLabels[i].SetIndex(PCL.GetGene(SVMLabels[i].GeneName));
-                }
-		iGene = SVMLabels[i].index;
-		if (iGene != -1) {
-                  numLabels++;
-		}
-	}
- 
-        prob->l = numLabels;
-        prob->y = Malloc(double,numLabels);
-        prob->x = Malloc(struct svm_node *, numLabels);
-        x_space = Malloc(struct svm_node, (1+numFeatures) * numLabels);
+    cerr << "total data" << endl;
+    cerr << "number of features (columns) used: " << numFeatures << endl;
+    cerr << "number of labels in data: " << numLabels << endl;
+    cerr << "number of gene (rows) names: " << vecGeneNames.size() << endl;
 
+    x_space = Malloc(struct svm_node, (1+numFeatures) * numLabels);
 
-        max_index = numFeatures;
+    j = 0;//element index
 
-        j = 0;//element index
+    for ( std::vector<std::string>::iterator it = vecGeneNames.begin(); it != vecGeneNames.end(); ++it) {
+      GeneName = *it;
+      iGene = PCL.GetGene(GeneName); 
 
-        for (i = 0; i < SVMLabels.size(); i++) {
-            iGene = SVMLabels[i].index;
+      for ( k = 0; k < numFeatures; k++){
+        x_space[j].index = k;
+        if (!Sleipnir::CMeta::IsNaN(d = PCL.Get(iGene, k))) {
+          x_space[j].value = d;
+        }else{
+          // impute 0 for missing values
+          x_space[j].value = 0;
+        }
+        j++;
+      }
 
-            if (iGene != -1){
-              (prob->x)[i] = &x_space[j];
-              (prob->y)[i] = SVMLabels[i].Target;
+      x_space[j].index = -1;
+      j++;
+    }
 
-              for(k = 0; k < numFeatures; k++){
-                x_space[j].index = k;
-                if (!Sleipnir::CMeta::IsNaN(d = PCL.Get(iGene, k))) {
-                  x_space[j].value = d;
-                }else{
-                  x_space[j].value = 1; //TODO: make this a flag!!!
-                  //if missing value??? SVMPerf imputes 0 ... what about gene i to gene i ? should impute 1?
-                }
-                j++;
-              }         
-              x_space[j].index = -1;
-              j++;
 
-            }
-        }
+  }
 
-        SAMPLE* pSample = new SAMPLE;
-//        pSample = Malloc(SAMPLE,1);
+  SAMPLE * CLIBSVM::CreateSample(Sleipnir::CPCL& PCL, vector<SVMLabel> SVMLabels) {
+    size_t i, j, k, s, iGene, iProblem, numFeatures, numLabels, max_index;
+    float d;
 
-        pSample->n = prob->l;//number of labels
-        pSample->problems = prob;
-        pSample->numFeatures = numFeatures;
-        
-        cout << ((pSample->problems)->y)[0] << endl;
-        cout << ((pSample->problems)->y)[1] << endl;
-PrintSample(*pSample);
-	return pSample;
-}
+    struct svm_problem* prob;
 
+    prob = Malloc(struct svm_problem,1);
 
-/*
-SAMPLE * CLIBSVM::CreateSample(Sleipnir::CDat& Dat, vector<SVMLabel> SVMLabels) {
-	size_t i, j, k, iGene, iProblem, numFeatures, max_index;
-        float d;
+    numFeatures = PCL.GetExperiments();
+    numLabels = 0;
 
-        struct svm_problem* prob;
-        struct svm_node *x_space;
+    iProblem = 0;
 
-        prob->l = 0;//number of labels in Dat
-        numFeatures = Dat.GetGenes();
-        iProblem = 0;
+    for (i = 0; i < SVMLabels.size(); i++) {
+      if (!SVMLabels[i].hasIndex){
+        SVMLabels[i].SetIndex(PCL.GetGene(SVMLabels[i].GeneName));
+      }
+      iGene = SVMLabels[i].index;
+      if (iGene != -1) {
+        numLabels++;
+      }
+    }
 
-	for (i = 0; i < SVMLabels.size(); i++) {
-          iGene = Dat.GetGene(SVMLabels[i].GeneName);
-          if (iGene != -1) {
-            (prob->l)++;
-          }
-	}
+    cerr << "sampled data" << endl;
+    cerr << "number of features used: " << numFeatures << endl;
+    cerr << "number of labels given: " << SVMLabels.size() << endl;
+    cerr << "number of labels in data: " << numLabels << endl;
 
- 
-        prob->y = Malloc(double,prob->l);
-        prob->x = Malloc(struct svm_node *, prob->l);
-        x_space = Malloc(struct svm_node, numFeatures * (prob->l));
+    prob->l = numLabels;
+    prob->y = Malloc(double,numLabels);
+    prob->x = Malloc(struct svm_node *, numLabels);
 
-        max_index = numFeatures;
-        j = 0;
+    if(x_space == NULL) {
+      SetXSpace(PCL);
+    }
 
-        for (i = 0; i < SVMLabels.size(); i++) {
-            iGene = Dat.GetGene(SVMLabels[i].GeneName);
-            if (iGene != -1){
-              (prob->x)[i] = &x_space[j];
-              (prob->y)[i] = SVMLabels[i].Target;
-              for(k = 0; k < numFeatures; k++){
-                x_space[j].index = k;
-                if (!Sleipnir::CMeta::IsNaN(d = Dat.Get(iGene, k))) {
-                  x_space[j].value = d;
-                }else{
-                  x_space[j].value = 1; //TODO: make this a flag!!!
-                  //if missing value??? SVMPerf imputes 0 ... what about gene i to gene i ? should impute 1?
-                }
-              }
-              j++;
-            }
-        }
+    max_index = numFeatures;
 
-        SAMPLE* pSample;
-        pSample = Malloc(SAMPLE,1);
-        
-        pSample->n = prob->l;
-        pSample->problems = prob;
+    s = 0;//sample index
+    for (i = 0; i < SVMLabels.size(); i++) {
+      iGene = SVMLabels[i].index;
 
-	return pSample;
-}*/
+      if (iGene != -1){
+        (prob->x)[s] = &x_space[iGene*(1+numFeatures)];
+        (prob->y)[s] = SVMLabels[i].Target;
+        s++;
+      }
+    }
 
+    SAMPLE* pSample = new SAMPLE;
 
-vector<Result> CLIBSVM::Classify(Sleipnir::CPCL &PCL,
-        vector<SVMLabel> SVMLabels) {
+    pSample->n = prob->l;//number of labels
+    pSample->problems = prob;
+    pSample->numFeatures = numFeatures;
+    return pSample;
+  }
+
+  //TODO: create sample for dab/dat files
+  //
+
+  vector<Result> CLIBSVM::Classify(Sleipnir::CPCL &PCL,
+      vector<SVMLabel> SVMLabels) {
     size_t i, j, iGene;
     double predict_label;
     double* dec_values;
     int svm_type = svm_get_svm_type(model);
     int nr_class = svm_get_nr_class(model);
 
-cerr << nr_class << endl;
-cerr << pSample->n << endl;;
-
     dec_values = Malloc(double, nr_class*(nr_class-1)/2);
     vecResult.resize(pSample->n);
 
-cerr << "number of samples: " << vecResult.size() << endl;
-cerr << "length of svm labels: " << SVMLabels.size() << endl;
-
     j= 0; //pSample index
     for(i = 0 ; i < SVMLabels.size() ; i++){
       if(!SVMLabels[i].hasIndex){//assume createSample sequentially added to pSample TODO: currently hacky
       if (iGene != -1 ) {    
         x = pSample->problems->x[j];
         predict_label = svm_predict_values(model,x, dec_values);
-        dec_value = dec_values[0]; //assume that positive class is the first class TODO: currently hackly
+        dec_value = dec_values[0]; //assume that positive class is the first class TODO: currently hacklyi
 
         vecResult[j].GeneName = SVMLabels[i].GeneName;
         vecResult[j].Target = SVMLabels[i].Target;
         vecResult[j].Value = dec_value;
-        
+
         j++;
 
       }
     }
+
+    free(pSample);
+    //delete pSample ;
     free(dec_values);
+    return vecResult;
+  }
 
-    return vecResult;
-}
 
-    
-//TODO: classify for dab/dat files
-//
+  //TODO: classify for dab/dat files
+  //
 
 }

File src/libsvm.h

 
 namespace LIBSVM {
 
-extern "C" {
+
+  extern "C" {
 #define class Class2
 #include <libsvm/svm.h>
 #undef class
 
-}
-
-typedef struct sample { /* a sample is a set of examples */
-   size_t     n;            /* n is the total number of examples */
-   size_t  numFeatures; 
-   struct svm_problem *problems;
-} SAMPLE;
- 
-
-class SVMLabel {
-public:
-	string GeneName;
-	double Target;
-	size_t index;
-	bool hasIndex;
-	SVMLabel(std::string name, double target) {
-		GeneName = name;
-		Target = target;
-		hasIndex = false;
-		index = -1;
-	}
-
-	SVMLabel() {
-		GeneName = "";
-		Target = 0;
-	}
-	void SetIndex(size_t i) {
-		index = i;
-		hasIndex = true;
-	}
-};
-
-class Result {
-public:
-	std::string GeneName;
-	double Target;
-	double Value;
-	int CVround;
-	int Rank;
-	Result() {
-		GeneName = "";
-		Target = 0;
-		Value = Sleipnir::CMeta::GetNaN();
-	}
-
-	Result(std::string name, int cv = -1) {
-		GeneName = name;
-		Target = 0;
-		Value = 0;
-		CVround = cv;
-		Rank = -1;
-	}
-	string toString() {
-		stringstream ss;
-		ss << GeneName << '\t' << Target << '\t' << Value << '\t' << "CV"
-				<< CVround;
-		if (Rank != -1) {
-			ss << '\t' << Rank;
-		}
-		return ss.str();
-	}
-
-};
-
-enum EFilter {
-	EFilterInclude = 0, EFilterExclude = EFilterInclude + 1,
-};
-
-//this class encapsulates the model and parameters and has no associated data
-
-class CLIBSVM {
-public:
-  //struct svm_parameter parm;
-  struct svm_model* model;
-  struct svm_parameter parm;
-  
-
-  CLIBSVM() {
-    initialize();
   }
 
-  void SetSVMType(int type) {
-    parm.svm_type = type;
-  }
-  //void SetLossFunction(size_t loss_f) {
-    //libsvm has only one loss function
-  //}
-
-  void SetTradeoff(double tradeoff) {
-    parm.C = tradeoff; //TODO: only applicable for vanilla svm
-  }
-
-  void SetKernel(int K) {
-    parm.kernel_type = K;
-  }
-
-  void SetPolyD(int D) {
-    parm.degree = D;
-  }
-
-  //void UseCPSP() { // unavailabe for libsvm
-  //}
-  //
-
-  void SetRBFGamma(double g) {
-    parm.gamma = g;
-    //UseCPSP not available for libsvm
-  }
-
-  //void UseSlackRescaling(){  }
-  //void UseMarginRescaling() { }
-  //void SetPrecisionFraction(double frac) { }
-
-  void ReadModel(char* model_file) {
-    FreeModel();
-    model = svm_load_model(model_file); 
-  }
-
-  void FreeModel() {
-    svm_free_and_destroy_model(&model);
-  }
-
-  void WriteModel(char* model_file) {
-    svm_save_model(model_file, model);
-  }
-  
-
-  //static members process data
-  //single gene predictions
-
-  //TODO: add functions to handle PCL files
-  //creates a svm_problem for a given gene index in a microarray set
-  //static svm_problem* CreateProblem(Sleipnir::CPCLSet &PCLSet, size_t iGene, size_t iProblem);
-
-  //creates a svm_problem for a given gene in a Dat file using all other genes as features
-  //static svm_problem* CreateProblem(Sleipnir::CDat& Dat, size_t iGene, size_t iProblem);
-
-  //Creates a sample using a PCLset and SVMlabels Looks up genes by name.
-  //static SAMPLE* CreateSample(Sleipnir::CPCLSet &PCLSet,
-  //			vector<SVMLabel> SVMLabels);
-
-  //Creates a sample of svm_problems using a single PCL and SVMlabels Looks up genes by name.
-  static SAMPLE* CreateSample(Sleipnir::CPCL &PCL, vector<SVMLabel> SVMLabels);
-
-  //Same as above except creates bootstrap samples and does not duplicate data
-  //static SAMPLE** CreateSampleBootStrap(Sleipnir::CPCL &PCL,
-  //	vector<SVMLabel>& SVMLabels, 
-  //      vector<vector<size_t> > vecvecIndex);
-
-  //Creates a sample using a Dat and SVMlabels. Looks up genes by name
-  static SAMPLE* CreateSample(Sleipnir::CDat& CDat,
-			vector<SVMLabel> SMVLabels);
-
-  //Classify single genes
-  vector<Result> Classify(Sleipnir::CPCL& PCL, vector<SVMLabel> SVMLabels);
-  //vector<Result> Classify(Sleipnir::CPCLSet& PCLSet,
-  //			vector<SVMLabel> SVMLabels);
-  vector<Result> Classify(Sleipnir::CDat& Dat, vector<SVMLabel> SVMLabels);
-
-  //MEMBER functions wraps learning
-  void Learn(SAMPLE &sample) {
-    //only L2 for LibSVM
-    //cerr << "SLACK NORM =" << struct_parm.slack_norm << endl;
-    //slack_norm = type of regularization
-
-    //Take care of the labels here
-    size_t i;
-    size_t numn, nump;
-
-
-    struct svm_problem* prob = sample.problems;
-
-    cout << "alsdjfaslkfjd" << endl;
-
-    numn = nump = 0;
-
-    for(i = 0; i < sample.n; i++){
-      if (((*prob).y)[i] > 0){
-        nump ++;
-      }else{
-        numn ++;
-      }
+  typedef struct sample { /* a sample is a set of examples */
+    size_t     n;            /* n is the total number of examples */
+    size_t  numFeatures; 
+    struct svm_problem *problems;
+    sample() {
+      n = 0;
+      numFeatures = 0;
+      problems = NULL;
     }
 
-cout << "number of positives: " << nump << endl;
-cout << "number of negatives: " << numn << endl;
-cout << "cache size: " << parm.cache_size << endl;
-cout << "kernel_type: " << parm.kernel_type << endl;
-cout << "svm_type: " << parm.svm_type << endl;
-const char* output = svm_check_parameter( prob, &parm ) ;//returns null if no issues..
-printf("%s | ", output);
-cout << "an svm_node index: " << (((*prob).x)[0][0]).index << endl;
-cout << "an svm_node value: " << (((*prob).x)[0][0]).value << endl;
-cout.flush();
-//cout <<      svm_check_parameter(prob,&parm) << endl;
-    //no need for rescaling labels because only one loss function for libsvm\
+    ~sample(){
+      //no destructor for problem struct
+      free(problems->y);
+      free(problems->x);
+      problems = NULL;
+    }
+  } SAMPLE;
 
-    if(parms_check()){
-//cout <<      svm_check_parameter(prob,&parm) << endl;
-//      struct svm_problem* prob = sample.problems;        //sample.problem
-//      cout << "here: " << (*prob).l << endl;
-      model = svm_train(prob,&parm);
-      cerr << "done learning model" << endl;
-cout << svm_get_svm_type(model) << endl;
-    }else{
-      cerr << "invalid parms" << endl;
-    }
-  }
 
-  static void FreeSample(SAMPLE s){
-cerr << "free sample: " << endl;
-PrintSample(s);
+  class SVMLabel {
+    public:
+      string GeneName;
+      double Target;
+      size_t index;
+      bool hasIndex;
 
-    FreeProblem(s.problems, s.numFeatures);
-    //free(&s);    
-  }
+      SVMLabel(std::string name, double target) {
+        GeneName = name;
+        Target = target;
+        hasIndex = false;
+        index = -1;
+      }
 
-  static void FreeProblem(svm_problem *prob, size_t numFeatures){
-    //int i = prob->l; //number of examples
-    size_t i, j ;
-    i = j = 0;
+      SVMLabel() {
+        GeneName = "";
+        Target = 0;
+      }
+      void SetIndex(size_t i) {
+        index = i;
+        hasIndex = true;
+      }
+  };
 
-//PrintProblem(prob);
+  class Result {
+    public:
+      std::string GeneName;
+      double Target;
+      double Value;
+      int CVround;
+      int Rank;
+      Result() {
+        GeneName = "";
+        Target = 0;
+        Value = Sleipnir::CMeta::GetNaN();
+      }
 
-    free(prob->y);
+      Result(std::string name, int cv = -1) {
+        GeneName = name;
+        Target = 0;
+        Value = 0;
+        CVround = cv;
+        Rank = -1;
+      }
+      string toString() {
+        stringstream ss;
+        ss << GeneName << '\t' << Target << '\t' << Value << '\t' << "CV"
+          << CVround;
+        if (Rank != -1) {
+          ss << '\t' << Rank;
+        }
+        return ss.str();
+      }
 
-    free(prob->x);
+  };
 
-//    for(i = 0 ; i < prob->l ; i++){
-//      for(j = 0 ; j < numFeatures ; j ++){
+  enum EFilter {
+    EFilterInclude = 0, EFilterExclude = EFilterInclude + 1,
+  };
 
-//PrintNode((prob->x)[i][j]);
+  //this class encapsulates the model and parameters and has no associated data
 
-//        free((prob->x)[i]);
-//      }
-//    }
+  class CLIBSVM {
+    public:
+      struct svm_model* model;
+      struct svm_parameter parm;
+      int balance;
 
-//    free(prob); ??? why can't i free?
-    return;
-  }
+      static struct svm_node *x_space;
 
-  static void PrintSample(SAMPLE s){
-    PrintProblem(s.problems);
-cerr << "number of labels: " << s.n << endl;
-  }
+      CLIBSVM() {
+        initialize();
+      }
 
-  static void PrintProblem(svm_problem *prob){
-    size_t i, j ;
-    i = j = 0;
+      ~CLIBSVM() {
+        svm_free_and_destroy_model( &model );
+        model = NULL;
+      }
 
-//    free(prob->y);
+      void SetBalance(int bal){
+        balance = bal;
+      }
 
-    for(i = 0 ; i < 3 ; i++){
-cerr << "label: " << (prob->y)[i] << endl;
-      for(j = 0 ; j < 2 ; j ++){
+      void SetSVMType(int type) {
+        parm.svm_type = type;
+      }
 
-PrintNode((prob->x)[i][j]);
+      void SetTradeoff(double tradeoff) {
+        parm.C = tradeoff; //TODO: only applicable for vanilla svm
+      }
 
-//        free(&((prob->x)[i][j]));
+      void SetKernel(int K) {
+        parm.kernel_type = K;
       }
-    }
 
-//    free(prob);
-    return;
-  }
+      void SetPolyD(int D) {
+        parm.degree = D;
+      }
 
-  static void PrintNode(svm_node node){
-    cerr << "index: " << node.index << endl;
-    cerr << "value: " << node.value << endl;
-  }
+      void SetRBFGamma(double g) {
+        parm.gamma = g;
+      }
 
+      void SetNu(double nu) {
+        parm.nu = nu;
+      }
 
-  //no pairwise learning for libSVM wrapper
+      void ReadModel(char* model_file) {
+        FreeModel();
+        model = svm_load_model(model_file); 
+      }
 
-  bool parms_check();
-  bool initialize();
-	
-  // functions to convert probablity
-  //void sigmoid_train(Sleipnir::CDat& Results, vector<SVMLabelPair*>& SVMLabels, float& A, float& B);
-  //void sigmoid_predict(Sleipnir::CDat& Results, vector<SVMLabelPair*>& SVMLabels, float A, float B);
-        
-        //not sure exactly what this does in svmperf compare to just ReadModel
-	// read in a SVM model file that's only has the w vector written out for linear kernel
-/*	void ReadModelLinear(char* model_file) {
-	  FreeModel();
-	  structmodel = read_struct_model_w_linear(model_file, &struct_parm);
-	}*/
-	
-	//STRUCTMODEL read_struct_model_w_linear(char *file, STRUCT_LEARN_PARM *sparm);
-};
+      void FreeModel() {
+        svm_free_and_destroy_model(&model);
+      }
+
+      void WriteModel(char* model_file) {
+        svm_save_model(model_file, model);
+      }
+
+
+      //static members process data
+      //
+
+      static void SetXSpace(Sleipnir::CPCL& PCL);
+
+      //single gene predictions
+
+      //TODO: add functions to handle PCL files
+
+      //Creates a sample of svm_problems using a single PCL and SVMlabels Looks up genes by name.
+      static SAMPLE* CreateSample(Sleipnir::CPCL &PCL, vector<SVMLabel> SVMLabels);
+
+      //TODO: Same as above except creates bootstrap samples and does not duplicate data
+
+      //Creates a sample using a Dat and SVMlabels. Looks up genes by name
+      static SAMPLE* CreateSample(Sleipnir::CDat& CDat,
+          vector<SVMLabel> SMVLabels);
+
+      //Classify single genes
+      vector<Result> Classify(Sleipnir::CPCL& PCL, vector<SVMLabel> SVMLabels);
+
+
+      //MEMBER functions wraps learning
+      void Learn(SAMPLE &sample) {
+        //only L2 for LibSVM
+        //cerr << "SLACK NORM =" << struct_parm.slack_norm << endl;
+        //slack_norm = type of regularization
+
+        //Take care of the labels here
+        size_t i;
+        size_t numn, nump;
+
+        struct svm_problem* prob = sample.problems;
+
+        numn = nump = 0;
+
+        for(i = 0; i < sample.n; i++){
+          if (((*prob).y)[i] > 0){
+            nump ++;
+          }else{
+            numn ++;
+          }
+        }
+
+        if (balance) {
+          cerr << "balancing the weights between postivies and negatives. " << endl;
+          parm.nr_weight = 2;
+          parm.weight_label = (int *) realloc(parm.weight_label, sizeof(int)*parm.nr_weight);
+          parm.weight = (double *) realloc(parm.weight, sizeof(double)*parm.nr_weight);
+          parm.weight_label[0] = 1;
+          parm.weight[0] = numn;
+          parm.weight_label[1] = -1;
+          parm.weight[1] = nump;
+        }
+
+        if(parms_check()){
+          model = svm_train(prob,&parm);
+        }else{
+        }
+        prob = NULL;
+
+      }
+
+      static void PrintSample(SAMPLE s){
+        PrintProblem(s.problems);
+      }
+
+      static void PrintProblem(svm_problem *prob){
+        size_t i, j ;
+        i = j = 0;
+
+        for(i = 0 ; i < 3 ; i++){
+          for(j = 0 ; j < 2 ; j ++){
+            PrintNode((prob->x)[i][j]);
+          }
+        }
+
+        return;
+      }
+
+      static void PrintNode(svm_node node){
+        cerr << "index: " << node.index << endl;
+        cerr << "value: " << node.value << endl;
+      }
+
+
+      //no pairwise learning for libSVM wrapper
+
+      bool parms_check();
+      bool initialize();
+
+      //TODO: functions to convert probablity
+
+  };
 }
 
 #endif // NO_SVM_LIBSVM

File tools/LibSVMer/LibSVMer.cpp

 
 using namespace LIBSVM;
 
-
 vector<LIBSVM::SVMLabel> ReadLabels(ifstream & ifsm) {
 
-	static const size_t c_iBuffer = 1024;
-	char acBuffer[c_iBuffer];
-	vector<string> vecstrTokens;
-	vector<LIBSVM::SVMLabel> vecLabels;
-	size_t numPositives, numNegatives;
-	numPositives = numNegatives = 0;
-	while (!ifsm.eof()) {
-		ifsm.getline(acBuffer, c_iBuffer - 1);
-		acBuffer[c_iBuffer - 1] = 0;
-		vecstrTokens.clear();
-		CMeta::Tokenize(acBuffer, vecstrTokens);
-		if (vecstrTokens.empty())
-			continue;
-		if (vecstrTokens.size() != 2) {
-			cerr << "Illegal label line (" << vecstrTokens.size() << "): "
-					<< acBuffer << endl;
-			continue;
-		}
-		vecLabels.push_back(LIBSVM::SVMLabel(vecstrTokens[0], atof(
-				vecstrTokens[1].c_str())));
-		if (vecLabels.back().Target > 0)
-			numPositives++;
-		else
-			numNegatives++;
-	}
-	return vecLabels;
+  static const size_t c_iBuffer = 1024;
+  char acBuffer[c_iBuffer];
+  vector<string> vecstrTokens;
+  vector<LIBSVM::SVMLabel> vecLabels;
+  size_t numPositives, numNegatives;
+  numPositives = numNegatives = 0;
+  while (!ifsm.eof()) {
+    ifsm.getline(acBuffer, c_iBuffer - 1);
+    acBuffer[c_iBuffer - 1] = 0;
+    vecstrTokens.clear();
+    CMeta::Tokenize(acBuffer, vecstrTokens);
+    if (vecstrTokens.empty())
+      continue;
+    if (vecstrTokens.size() != 2) {
+      cerr << "Illegal label line (" << vecstrTokens.size() << "): "
+        << acBuffer << endl;
+      continue;
+    }
+    vecLabels.push_back(LIBSVM::SVMLabel(vecstrTokens[0], atof(
+            vecstrTokens[1].c_str())));
+    if (vecLabels.back().Target > 0)
+      numPositives++;
+    else
+      numNegatives++;
+  }
+  return vecLabels;
 }
 
 
 struct SortResults {
 
-	bool operator()(const LIBSVM::Result& rOne, const LIBSVM::Result & rTwo) const {
-		return (rOne.Value > rTwo.Value);
-	}
+  bool operator()(const LIBSVM::Result& rOne, const LIBSVM::Result & rTwo) const {
+    return (rOne.Value > rTwo.Value);
+  }
 };
 
 
 size_t PrintResults(vector<LIBSVM::Result> vecResults, ofstream & ofsm) {
-	sort(vecResults.begin(), vecResults.end(), SortResults());
-	int LabelVal;
-	for (size_t i = 0; i < vecResults.size(); i++) {
-		ofsm << vecResults[i].GeneName << '\t' << vecResults[i].Target << '\t'
-				<< vecResults[i].Value << endl;
-	}
+  sort(vecResults.begin(), vecResults.end(), SortResults());
+  int LabelVal;
+  for (size_t i = 0; i < vecResults.size(); i++) {
+    ofsm << vecResults[i].GeneName << '\t' << vecResults[i].Target << '\t'
+      << vecResults[i].Value << endl;
+  }
 };
 
 struct ParamStruct {
-	vector<float> vecK, vecTradeoff;
-	vector<size_t> vecLoss;
-	vector<char*> vecNames;
+  vector<float> vecK, vecTradeoff;
+  vector<size_t> vecLoss;
+  vector<char*> vecNames;
 };
 
-ParamStruct ReadParamsFromFile(ifstream& ifsm, string outFile) {
-	static const size_t c_iBuffer = 1024;
-	char acBuffer[c_iBuffer];
-	char* nameBuffer;
-	vector<string> vecstrTokens;
-	size_t extPlace;
-	string Ext, FileName;
-	if ((extPlace = outFile.find_first_of(".")) != string::npos) {
-		FileName = outFile.substr(0, extPlace);
-		Ext = outFile.substr(extPlace, outFile.size());
-	} else {
-		FileName = outFile;
-		Ext = "";
-	}
-	ParamStruct PStruct;
-	size_t index = 0;
-	while (!ifsm.eof()) {
-		ifsm.getline(acBuffer, c_iBuffer - 1);
-		acBuffer[c_iBuffer - 1] = 0;
-		vecstrTokens.clear();
-		CMeta::Tokenize(acBuffer, vecstrTokens);
-		if (vecstrTokens.empty())
-			continue;
-		if (vecstrTokens.size() != 3) {
-			cerr << "Illegal params line (" << vecstrTokens.size() << "): "
-					<< acBuffer << endl;
-			continue;
-		}
-		if (acBuffer[0] == '#') {
-			cerr << "skipping " << acBuffer << endl;
-		} else {
-			PStruct.vecLoss.push_back(atoi(vecstrTokens[0].c_str()));
-			PStruct.vecTradeoff.push_back(atof(vecstrTokens[1].c_str()));
-			PStruct.vecK.push_back(atof(vecstrTokens[2].c_str()));
-			PStruct.vecNames.push_back(new char[c_iBuffer]);
-			if (PStruct.vecLoss[index] == 4 || PStruct.vecLoss[index] == 5)
-				sprintf(PStruct.vecNames[index], "%s_l%d_c%4.6f_k%4.3f%s",
-						FileName.c_str(), PStruct.vecLoss[index],
-						PStruct.vecTradeoff[index], PStruct.vecK[index],
-						Ext.c_str());
-			else
-				sprintf(PStruct.vecNames[index], "%s_l%d_c%4.6f%s",
-						FileName.c_str(), PStruct.vecLoss[index],
-						PStruct.vecTradeoff[index], Ext.c_str());
-			index++;
-		}
+int main(int iArgs, char** aszArgs) {
 
-	}
-	return PStruct;
-}
+  gengetopt_args_info sArgs;
 
-int main(int iArgs, char** aszArgs) {
-//	cout << "blah" << endl;
+  CPCL PCL;//data
+  LIBSVM::CLIBSVM SVM;//model
 
-	gengetopt_args_info sArgs;
+  size_t i, j, iGene, jGene;
+  ifstream ifsm;
 
-	CPCL PCL;
-	LIBSVM::CLIBSVM SVM;
+  if (cmdline_parser(iArgs, aszArgs, &sArgs)) {
+    cmdline_parser_print_help();
+    return 1;
+  }
 
-	size_t i, j, iGene, jGene;
-	ifstream ifsm;
-	if (cmdline_parser(iArgs, aszArgs, &sArgs)) {
-		cmdline_parser_print_help();
-		return 1;
-	}
+  //Set model parameters
 
-        //TODO: update documentation and cmdline .. doesn't use most parameters
-	//SVM.SetVerbosity(sArgs.verbosity_arg); // no verbosity param for libsvm TODO: update documentation
-	//SVM.SetLossFunction(sArgs.error_function_arg); //libsvm only has one loss function TODO: update documentation
-        
-	
-	if (sArgs.cross_validation_arg < 1){
-	  cerr << "cross_valid is <1. Must be set at least 1" << endl;
-	  return 1;
-	}
-	else if(sArgs.cross_validation_arg < 2){
-	  cerr << "cross_valid is set to 1. No cross validation holdouts will be run." << endl;
-	}
-	
-	SVM.SetTradeoff(sArgs.tradeoff_arg);
+  if (sArgs.cross_validation_arg < 1){
+    cerr << "cross_valid is <1. Must be set at least 1" << endl;
+    return 1;
+  }
+  else if(sArgs.cross_validation_arg < 2){
+    cerr << "cross_valid is set to 1. No cross validation holdouts will be run." << endl;
+    if(sArgs.num_cv_runs_arg > 1){
+      cerr << "number of cv runs is > 1.  When no cv holdouts, must be set to 1." << endl;
+      return 1;
+    }
+  }
 
+  if (sArgs.num_cv_runs_arg < 1){
+    cerr << "number of cv runs is < 1. Must be set at least 1" << endl;
+    return 1;
+  }
 
-	if (!SVM.parms_check()) {
-		cerr << "Sanity check failed, see above errors" << endl;
-		return 1;
-	}
 
-	//  cout << "there are " << vecLabels.size() << " labels processed" << endl;
-	size_t iFile;
-	vector<string> PCLs;
-	if (sArgs.input_given) {//TODO: allow PCL file inputs
-//          cerr << "PCL as input not yet available" << endl;
 
-//          return 1;
-          
-		if (!PCL.Open(sArgs.input_arg, sArgs.skip_arg, sArgs.mmap_flag)) {
-			cerr << "Could not open input PCL" << endl;
-			return 1;
-		}
-	}
+  SVM.SetTradeoff(sArgs.tradeoff_arg);
+  SVM.SetNu(sArgs.nu_arg);
+  SVM.SetSVMType(sArgs.svm_type_arg);
+  SVM.SetBalance(sArgs.balance_flag);
 
-//cout << "here1: " << svm_get_svm_type(SVM.model) << endl;
-//cout << SVM.parm.C << endl;
+  if (!SVM.parms_check()) {
+    cerr << "Sanity check failed, see above errors" << endl;
+    return 1;
+  }
 
-	vector<LIBSVM::SVMLabel> vecLabels;
-	set<string> setLabeledGenes;
-	if (sArgs.labels_given) {
-		ifsm.clear();
-		ifsm.open(sArgs.labels_arg);
-		if (ifsm.is_open())
-			vecLabels = ReadLabels(ifsm);
-		else {
-			cerr << "Could not read label file" << endl;
-			return 1;
-		}
-		for (i = 0; i < vecLabels.size(); i++)
-			setLabeledGenes.insert(vecLabels[i].GeneName);
-	}
+  //TODO: allow multiple PCL files
+  //size_t iFile; //TODO
+  // vector<string> PCLs; //TODO
 
-	LIBSVM::SAMPLE* pTrainSample;
-	vector<LIBSVM::SVMLabel> pTrainVector[sArgs.cross_validation_arg];
-	vector<LIBSVM::SVMLabel> pTestVector[sArgs.cross_validation_arg];
-	vector<LIBSVM::Result> AllResults;
-	vector<LIBSVM::Result> tmpAllResults;
+  //check data file
+  if (sArgs.input_given) {
+    if (!PCL.Open(sArgs.input_arg, sArgs.skip_arg, sArgs.mmap_flag)) {
+      cerr << "Could not open input PCL" << endl;
+      return 1;
+    }
+  }
 
-	if (sArgs.model_given && sArgs.labels_given) { //learn once and write to file
-		pTrainSample = CLIBSVM::CreateSample(PCL, vecLabels);
-		SVM.Learn(*pTrainSample);
-		SVM.WriteModel(sArgs.model_arg);
-	} else if (sArgs.model_given && sArgs.output_given) { //read model and classify all
-		vector<SVMLabel> vecAllLabels;
+  //read label files
+  vector<LIBSVM::SVMLabel> vecLabels;
+  set<string> setLabeledGenes;
+  if (sArgs.labels_given) {
+    ifsm.clear();
+    ifsm.open(sArgs.labels_arg);
+    if (ifsm.is_open())
+      vecLabels = ReadLabels(ifsm);
+    else {
+      cerr << "Could not read label file" << endl;
+      return 1;
+    }
+    for (i = 0; i < vecLabels.size(); i++)
+      setLabeledGenes.insert(vecLabels[i].GeneName);
+  }
+  
+  if (sArgs.model_given && sArgs.labels_given) { //learn once and write to file
+    //TODO
+    cerr << "not yet implemented: learn once and write to file" << endl;
+    /*
+    pTrainSample = CLIBSVM::CreateSample(PCL, vecLabels);
+    SVM.Learn(*pTrainSample);
+    SVM.WriteModel(sArgs.model_arg);
+    */
 
-		for (size_t i = 0; i < PCL.GetGenes(); i++)
-			vecAllLabels.push_back(SVMLabel(PCL.GetGene(i), 0));
+  } else if (sArgs.model_given && sArgs.output_given) { //read model and classify all
+    //TODO
+    cerr << "not yet implemetned: read model and classify all" << endl;
+    /*
+    vector<SVMLabel> vecAllLabels;
+    for (size_t i = 0; i < PCL.GetGenes(); i++)
+      vecAllLabels.push_back(SVMLabel(PCL.GetGene(i), 0));
 
-		SVM.ReadModel(sArgs.model_arg);
-		AllResults = SVM.Classify(PCL, vecAllLabels);
-		ofstream ofsm;
-		ofsm.open(sArgs.output_arg);
-		if (ofsm.is_open())
-			PrintResults(AllResults, ofsm);
-		else {
-			cerr << "Could not open output file" << endl;
-		}
-	} else if (sArgs.output_given && sArgs.labels_given) {
-		//do learning and classifying with cross validation
-	        if( sArgs.cross_validation_arg > 1){	    
-		  for (i = 0; i < sArgs.cross_validation_arg; i++) {
-		    pTestVector[i].reserve((size_t) vecLabels.size()
-					   / sArgs.cross_validation_arg + sArgs.cross_validation_arg);
-		    pTrainVector[i].reserve((size_t) vecLabels.size()
-					    / (sArgs.cross_validation_arg)
-					    * (sArgs.cross_validation_arg - 1)
-					    + sArgs.cross_validation_arg);
-		    for (j = 0; j < vecLabels.size(); j++) {
-		      if (j % sArgs.cross_validation_arg == i) {
-			pTestVector[i].push_back(vecLabels[j]);
-		      } else {
-			pTrainVector[i].push_back((vecLabels[j]));
-		      }
-		    }
-		  }
-		}
-		else{ // if you have less than 2 fold cross, no cross validation is done, all train genes are used and predicted
-		  
-		  // no holdout so train is the same as test gene set
-		  pTestVector[0].reserve((size_t) vecLabels.size() + sArgs.cross_validation_arg);
-		  pTrainVector[0].reserve((size_t) vecLabels.size() + sArgs.cross_validation_arg);
-		  
-		  for (j = 0; j < vecLabels.size(); j++) {
-		    pTestVector[0].push_back(vecLabels[j]);		      
-		    pTrainVector[0].push_back(vecLabels[j]);		    
-		  }
-		}
-		
-		
-		vector<SVMLabel> vec_allUnlabeledLabels;
-		vector<Result> vec_allUnlabeledResults;
-		vector<Result> vec_tmpUnlabeledResults;
-		if (sArgs.all_flag) {
-			vec_allUnlabeledLabels.reserve(PCL.GetGenes());
-			vec_allUnlabeledResults.reserve(PCL.GetGenes());
-			for (i = 0; i < PCL.GetGenes(); i++) {
-				if (setLabeledGenes.find(PCL.GetGene(i))
-						== setLabeledGenes.end()) {
-					vec_allUnlabeledLabels.push_back(
-							SVMLabel(PCL.GetGene(i), 0));
-					vec_allUnlabeledResults.push_back(Result(PCL.GetGene(i)));
-				}
-			}
-		}
-		if (sArgs.params_given) { //reading paramters from file
-			ifsm.close();
-			ifsm.clear();
-			ifsm.open(sArgs.params_arg);
-			if (!ifsm.is_open()) {
-				cerr << "Could not open: " << sArgs.params_arg << endl;
-				return 1;
-			}
-			ParamStruct PStruct;
-			string outFile(sArgs.output_arg);
-			PStruct = ReadParamsFromFile(ifsm, outFile);
+    SVM.ReadModel(sArgs.model_arg);
+    AllResults = SVM.Classify(PCL, vecAllLabels);
+    ofstream ofsm;
+    ofsm.open(sArgs.output_arg);
+    if (ofsm.is_open())
+      PrintResults(AllResults, ofsm);
+    else {
+      cerr << "Could not open output file" << endl;
+    }
+    */
 
-			size_t iParams;
-			ofstream ofsm;
-			LIBSVM::SAMPLE * ppTrainSample[sArgs.cross_validation_arg];
-			
-			//build all the samples since they are being reused
-			for (i = 0; i < sArgs.cross_validation_arg; i++)
-				ppTrainSample[i] = LIBSVM::CLIBSVM::CreateSample(PCL,
-						pTrainVector[i]);
-			
-			for (iParams = 0; iParams < PStruct.vecTradeoff.size(); iParams++) {
-			//	SVM.SetLossFunction(PStruct.vecLoss[iParams]);
-				SVM.SetTradeoff(PStruct.vecTradeoff[iParams]);
-			//	SVM.SetPrecisionFraction(PStruct.vecK[iParams]);
-				for (j = 0; j < vec_allUnlabeledResults.size(); j++)
-					vec_allUnlabeledResults[j].Value = 0;
-				for (i = 0; i < sArgs.cross_validation_arg; i++) {
-					cerr << "Cross Validation Trial " << i << endl;
-					SVM.Learn(*ppTrainSample[i]);
-					
-					cerr << "Learned" << endl;					
-					
-					tmpAllResults = SVM.Classify(PCL, pTestVector[i]);
-					cerr << "Classified " << tmpAllResults.size()
-							<< " examples" << endl;
-					AllResults.insert(AllResults.end(), tmpAllResults.begin(),
-							tmpAllResults.end());
-					tmpAllResults.resize(0);
-					if (sArgs.all_flag && vec_allUnlabeledLabels.size() > 0) {
-						vec_tmpUnlabeledResults = SVM.Classify(PCL,
-								vec_allUnlabeledLabels);
-						for (j = 0; j < vec_tmpUnlabeledResults.size(); j++)
-							vec_allUnlabeledResults[j].Value
-									+= vec_tmpUnlabeledResults[j].Value;
-					}
+  } else if (sArgs.output_given && sArgs.labels_given) {
+ 
+    LIBSVM::SAMPLE* pTrainSample;//sampled data
+    size_t numSample;//number of sampling
 
-				}
+    numSample = sArgs.cross_validation_arg * sArgs.num_cv_runs_arg;
+  
+    vector<LIBSVM::SVMLabel> pTrainVector[numSample];
+    vector<LIBSVM::SVMLabel> pTestVector[numSample];
+    vector<LIBSVM::Result> AllResults;
+    vector<LIBSVM::Result> testResults;
 
+    //set train and test label vectors
+    //
+    if( sArgs.cross_validation_arg > 1 && sArgs.num_cv_runs_arg >= 1 ){
+      //do learning and classifying with cross validation
+      //
+      size_t ii, index;
 
-				ofsm.open(PStruct.vecNames[iParams]);
-				if (sArgs.all_flag) { //add the unlabeled results
-					for (j = 0; j < vec_tmpUnlabeledResults.size(); j++)
-						vec_allUnlabeledResults[j].Value
-								/= sArgs.cross_validation_arg;
-					AllResults.insert(AllResults.end(),
-							vec_allUnlabeledResults.begin(),
-							vec_allUnlabeledResults.end());
-				}
+      for (ii = 0; ii < sArgs.num_cv_runs_arg; ii++) {
+        if(ii > 0)
+          std::random_shuffle(vecLabels.begin(), vecLabels.end());
 
-				PrintResults(AllResults, ofsm);
-				ofsm.close();
-				ofsm.clear();
-				if (i > 0 || iParams > 0)
-					SVM.FreeModel();
-				AllResults.resize(0);
-			}
-		} else { //run once
-			for (i = 0; i < sArgs.cross_validation_arg; i++) {
-				pTrainSample = LIBSVM::CLIBSVM::CreateSample(PCL, //TODO: make more efficient
-						pTrainVector[i]);
-//                                LIBSVM::CLIBSVM::PrintSample(*pTrainSample);
-//				LIBSVM::CLIBSVM::FreeSample(*pTrainSample);
-//                                continue;
+        for (i = 0; i < sArgs.cross_validation_arg; i++) {                  
+          index = sArgs.cross_validation_arg * ii + i;
+          pTestVector[index].reserve((size_t) vecLabels.size()
+              / sArgs.cross_validation_arg + sArgs.cross_validation_arg);
+          pTrainVector[index].reserve((size_t) vecLabels.size()
+              / (sArgs.cross_validation_arg)
+              * (sArgs.cross_validation_arg - 1)
+              + sArgs.cross_validation_arg);
+          for (j = 0; j < vecLabels.size(); j++) {
+            if (j % sArgs.cross_validation_arg == i) {
+              pTestVector[index].push_back(vecLabels[j]);
+            } else {
+              pTrainVector[index].push_back(vecLabels[j]);
+            }
+          }
+        }
 
-//cout << "here2: " << svm_get_svm_type(SVM.model) << endl;
-//cout << "here3: " << SVM.parm.C << endl;
+      }
+    }  
+    else{ 
+      // if you have less than 2 fold cross, no cross validation is done, 
+      // all train genes are used and predicted
+      //
+      cerr << "no holdout so train is the same as test" << endl;
+      pTestVector[0].reserve((size_t) vecLabels.size() + sArgs.cross_validation_arg);
+      pTrainVector[0].reserve((size_t) vecLabels.size() + sArgs.cross_validation_arg);
 
-//                                cerr << "number of training labels: " << pTrainVector[i].size() << endl;
-//                                cerr << "number of training samples: " << pTrainSample->n << endl;
-//                                cerr << "number of testing labels: " << pTestVector[i].size() << endl;
-				
-//continue;
-//for( std::vector<LIBSVM::SVMLabel>::const_iterator q = pTestVector[i].begin(); q != pTestVector[i].end(); ++q)
-//      std::cout << (*q).GeneName << ' ';
+      for (j = 0; j < vecLabels.size(); j++) {
+        pTestVector[0].push_back(vecLabels[j]);		      
+        pTrainVector[0].push_back(vecLabels[j]);		    
+      }
+    }
 
-//                                cout << pTrainSample->problems
-//sleep(15);
-//cout << PCL.GetFeatures() << endl;
-//cout << PCL.GetGenes() << endl;
+    //if want to make predictions for genes (row) with no label information
+    //
+    vector<SVMLabel> vec_allUnlabeledLabels;
+    vector<Result> vec_allUnlabeledResults;
+    vector<Result> tmpUnlabeledResults;
+    if (sArgs.all_flag) {
+      vec_allUnlabeledLabels.reserve(PCL.GetGenes());
+      vec_allUnlabeledResults.reserve(PCL.GetGenes());
+      for (i = 0; i < PCL.GetGenes(); i++) {
+        if (setLabeledGenes.find(PCL.GetGene(i))
+            == setLabeledGenes.end()) { // if gene with no label information
 
+          vec_allUnlabeledLabels.push_back(SVMLabel(PCL.GetGene(i), 0));
+          vec_allUnlabeledResults.push_back(Result(PCL.GetGene(i)));
+        }
+      }
+    }
 
-				cerr << "Cross Validation Trial " << i << endl;
+    bool added;//flag for merging testResults and AllResults
 
-				SVM.Learn(*pTrainSample);
-				cerr << "Learned" << endl;
+    //for each sample
+    for (i = 0; i < numSample; i++) {
+      pTrainSample = LIBSVM::CLIBSVM::CreateSample(PCL, pTrainVector[i]);
+      cerr << "Trial " << i << endl;
 
+      SVM.Learn(*pTrainSample);
+      cerr << "Learned" << endl;
 
-				tmpAllResults = SVM.Classify(PCL,
-						pTestVector[i]);
-				cerr << "Classified " << tmpAllResults.size() << " examples"
-						<< endl;
-				AllResults.insert(AllResults.end(), tmpAllResults.begin(),
-						tmpAllResults.end());
-				tmpAllResults.resize(0);
-				if (sArgs.all_flag) {
-					vec_tmpUnlabeledResults = SVM.Classify(
-							PCL, vec_allUnlabeledLabels);
-					for (j = 0; j < vec_tmpUnlabeledResults.size(); j++)
-						vec_allUnlabeledResults[j].Value
-								+= vec_tmpUnlabeledResults[j].Value;
+      testResults = SVM.Classify(PCL, pTestVector[i]);
+      cerr << "Classified " << testResults.size() << " test examples" << endl;
 
-				}
-                                LIBSVM::CLIBSVM::PrintSample(*pTrainSample);
+      // merge testResults and AllResults
+      // TODO: make more efficent
+      for(std::vector<LIBSVM::Result>::iterator it = testResults.begin() ; 
+          it != testResults.end() ; it ++){
 
-				if (i > 0) {
-					LIBSVM::CLIBSVM::FreeSample(*pTrainSample);
-				}
-			}
+        added = false;
+        for(std::vector<LIBSVM::Result>::iterator ita = AllResults.begin() ; 
+            ita != AllResults.end() ; ita ++){
 
-			if (sArgs.all_flag) { //add the unlabeled results
-				for (j = 0; j < vec_allUnlabeledResults.size(); j++)
-					vec_allUnlabeledResults[j].Value
-							/= sArgs.cross_validation_arg;
-				AllResults.insert(AllResults.end(),
-						vec_allUnlabeledResults.begin(),
-						vec_allUnlabeledResults.end());
-			}
+          if ( (*it).GeneName.compare((*ita).GeneName) == 0 ){
 
-			ofstream ofsm;
-			ofsm.clear();
-			ofsm.open(sArgs.output_arg);
-			PrintResults(AllResults, ofsm);
-			return 0;
-		}
-	} else {
-		cerr << "More options are needed" << endl;
-	}
+            (*ita).Value += (*it).Value;
+            added = true;
+            break;
+          }
+
+        }
+
+        if(!added)
+          AllResults.push_back((*it));
+
+      }
+      testResults.clear();
+
+      // classify genes with no label information
+      if (sArgs.all_flag) {
+        tmpUnlabeledResults = SVM.Classify(
+            PCL, vec_allUnlabeledLabels);//make predictions
+        for (j = 0; j < tmpUnlabeledResults.size(); j++)
+          vec_allUnlabeledResults[j].Value
+            += tmpUnlabeledResults[j].Value;
+      }
+
+      if (i > 0) {
+        //LIBSVM::CLIBSVM::FreeSample(*pTrainSample);
+        free(pTrainSample);
+      }
+
+      //mem = CMeta::GetMemoryUsage();
+      
+      cerr << "end of trail" << endl;
+
+    }
+
+    // average results (svm outputs) from multiple cv runs
+    for(std::vector<LIBSVM::Result>::iterator it = AllResults.begin();
+        it != AllResults.end(); ++ it){
+      (*it).Value /= sArgs.num_cv_runs_arg;
+
+    }
+
+    if (sArgs.all_flag) { //add the unlabeled results
+      for (j = 0; j < vec_allUnlabeledResults.size(); j++)
+        vec_allUnlabeledResults[j].Value
+          /= (sArgs.cross_validation_arg * sArgs.num_cv_runs_arg);
+      AllResults.insert(AllResults.end(),
+          vec_allUnlabeledResults.begin(),
+          vec_allUnlabeledResults.end());
+    }
+
+    ofstream ofsm;
+    ofsm.clear();
+    ofsm.open(sArgs.output_arg);
+    PrintResults(AllResults, ofsm);
+    return 0;
+
+  } else {
+    cerr << "More options are needed" << endl;
+  }
 
 }
 

File tools/LibSVMer/LibSVMer.ggo

 option  "all"       			a   "Always classify all genes in PCLs"  
 										flag off
 
-option  "slack"       			S   "Use slack rescaling (not implemented for ROC loss)"
-										flag off
-
 section "Options"
-option "verbosity"  			v   "Sets the svm_struct verbosity"
-										int default="0" no
 option "skip"      				s   "Number of columns to skip in input pcls"
 										int default="2" no
 option	"normalize"				n	"Normalize PCLS to 0 mean 1 variance"
 										flag	off
 option	"cross_validation"		c	"Number of cross-validation sets ( arg of 1 will turn off cross-validation )"
 										int default="5" no
-option "error_function" 		e   "Sets the loss function for SVM learning: Choice of:
-0\tZero/one loss: 1 if vector of predictions contains error, 0 otherwise.
-1\tF1: 100 minus the F1-score in percent.
-2\tErrorrate: Percentage of errors in prediction vector.
-3\tPrec/Rec Breakeven: 100 minus PRBEP in percent.
-4\tPrec@k: 100 minus precision at k in percent.
-5\tRec@k: 100 minus recall at k in percent.
-10\tROCArea: Percentage of swapped pos/neg pairs (i.e. 100 - ROCArea).\n" 
-										int default="10" no
-
-option "k_value"    			k   "Value of k parameter used for Prec@k and Rec@k in (0,1)"
-										float default="0.5" no
-option "tradeoff"    			t   "SVM tradeoff constant C"
+option  "num_cv_runs"                   r       "Number of cross-validation runs"
+                                                                                int default="1" no
+option "svm_type"                       v       "Sets type of SVM (default 0)
+0\tC-SVC
+1\tnu-SVC
+2\tone-class SVM\n"
+                                                                                int default="0" no
+option "balance"         b   "weight classes such that C_P * n_P = C_N * n_N"
+                                                                                flag off
+option "tradeoff"    			t   "SVM tradeoff constant C of C-SVC"
 										float default="1" no
-option "params"   				p   "Parameter file"
-										string  typestr="filename"   no
+option "nu"                             u   "nu parameter of nu-SVC, one-class SVM"
+                                                                                float default="0.5" no
 option	"mmap"					M	"Memory map binary input"
 										flag	off

File tools/LibSVMer/cmdline.c

   "  -i, --input=filename        Input PCL file ",
   "  -m, --model=filename        Model file",
   "  -a, --all                   Always classify all genes in PCLs  (default=off)",
-  "  -S, --slack                 Use slack rescaling (not implemented for ROC \n                                loss)  (default=off)",
   "\nOptions:",
-  "  -v, --verbosity=INT         Sets the svm_struct verbosity  (default=`0')",
   "  -s, --skip=INT              Number of columns to skip in input pcls  \n                                (default=`2')",
   "  -n, --normalize             Normalize PCLS to 0 mean 1 variance  \n                                (default=off)",
   "  -c, --cross_validation=INT  Number of cross-validation sets ( arg of 1 will \n                                turn off cross-validation )  (default=`5')",
-  "  -e, --error_function=INT    Sets the loss function for SVM learning: Choice \n                                of:\n\n                                0\tZero/one loss: 1 if vector of predictions \n                                contains error, 0 otherwise.\n\n                                1\tF1: 100 minus the F1-score in percent.\n\n                                2\tErrorrate: Percentage of errors in \n                                prediction vector.\n\n                                3\tPrec/Rec Breakeven: 100 minus PRBEP in \n                                percent.\n\n                                4\tPrec@k: 100 minus precision at k in percent.\n\n                                5\tRec@k: 100 minus recall at k in percent.\n\n                                10\tROCArea: Percentage of swapped pos/neg \n                                pairs (i.e. 100 - ROCArea).\n                                  (default=`10')",
-  "  -k, --k_value=FLOAT         Value of k parameter used for Prec@k and Rec@k in \n                                (0,1)  (default=`0.5')",
-  "  -t, --tradeoff=FLOAT        SVM tradeoff constant C  (default=`1')",
-  "  -p, --params=filename       Parameter file",
+  "  -r, --num_cv_runs=INT       Number of cross-validation runs  (default=`1')",
+  "  -v, --svm_type=INT          Sets type of SVM (default 0)\n\n                                0\tC-SVC\n\n                                1\tnu-SVC\n\n                                2\tone-class SVM\n                                  (default=`0')",
+  "  -b, --balance               weight classes such that C_P * n_P = C_N * n_N  \n                                (default=off)",
+  "  -t, --tradeoff=FLOAT        SVM tradeoff constant C of C-SVC  (default=`1')",
+  "  -u, --nu=FLOAT              nu parameter of nu-SVC, one-class SVM  \n                                (default=`0.5')",
   "  -M, --mmap                  Memory map binary input  (default=off)",
     0
 };
   args_info->input_given = 0 ;
   args_info->model_given = 0 ;
   args_info->all_given = 0 ;
-  args_info->slack_given = 0 ;
-  args_info->verbosity_given = 0 ;
   args_info->skip_given = 0 ;
   args_info->normalize_given = 0 ;
   args_info->cross_validation_given = 0 ;
-  args_info->error_function_given = 0 ;
-  args_info->k_value_given = 0 ;
+  args_info->num_cv_runs_given = 0 ;
+  args_info->svm_type_given = 0 ;
+  args_info->balance_given = 0 ;
   args_info->tradeoff_given = 0 ;
-  args_info->params_given = 0 ;
+  args_info->nu_given = 0 ;
   args_info->mmap_given = 0 ;
 }
 
   args_info->model_arg = NULL;
   args_info->model_orig = NULL;
   args_info->all_flag = 0;
-  args_info->slack_flag = 0;
-  args_info->verbosity_arg = 0;
-  args_info->verbosity_orig = NULL;
   args_info->skip_arg = 2;
   args_info->skip_orig = NULL;
   args_info->normalize_flag = 0;
   args_info->cross_validation_arg = 5;
   args_info->cross_validation_orig = NULL;
-  args_info->error_function_arg = 10;
-  args_info->error_function_orig = NULL;
-  args_info->k_value_arg = 0.5;
-  args_info->k_value_orig = NULL;
+  args_info->num_cv_runs_arg = 1;
+  args_info->num_cv_runs_orig = NULL;
+  args_info->svm_type_arg = 0;
+  args_info->svm_type_orig = NULL;
+  args_info->balance_flag = 0;
   args_info->tradeoff_arg = 1;
   args_info->tradeoff_orig = NULL;
-  args_info->params_arg = NULL;
-  args_info->params_orig = NULL;
+  args_info->nu_arg = 0.5;
+  args_info->nu_orig = NULL;
   args_info->mmap_flag = 0;
   
 }
   args_info->input_help = gengetopt_args_info_help[5] ;
   args_info->model_help = gengetopt_args_info_help[6] ;
   args_info->all_help = gengetopt_args_info_help[7] ;
-  args_info->slack_help = gengetopt_args_info_help[8] ;
-  args_info->verbosity_help = gengetopt_args_info_help[10] ;
-  args_info->skip_help = gengetopt_args_info_help[11] ;
-  args_info->normalize_help = gengetopt_args_info_help[12] ;
-  args_info->cross_validation_help = gengetopt_args_info_help[13] ;
-  args_info->error_function_help = gengetopt_args_info_help[14] ;
-  args_info->k_value_help = gengetopt_args_info_help[15] ;
-  args_info->tradeoff_help = gengetopt_args_info_help[16] ;
-  args_info->params_help = gengetopt_args_info_help[17] ;
-  args_info->mmap_help = gengetopt_args_info_help[18] ;
+  args_info->skip_help = gengetopt_args_info_help[9] ;
+  args_info->normalize_help = gengetopt_args_info_help[10] ;
+  args_info->cross_validation_help = gengetopt_args_info_help[11] ;
+  args_info->num_cv_runs_help = gengetopt_args_info_help[12] ;
+  args_info->svm_type_help = gengetopt_args_info_help[13] ;
+  args_info->balance_help = gengetopt_args_info_help[14] ;
+  args_info->tradeoff_help = gengetopt_args_info_help[15] ;
+  args_info->nu_help = gengetopt_args_info_help[16] ;
+  args_info->mmap_help = gengetopt_args_info_help[17] ;
   
 }
 
   free_string_field (&(args_info->input_orig));
   free_string_field (&(args_info->model_arg));
   free_string_field (&(args_info->model_orig));
-  free_string_field (&(args_info->verbosity_orig));
   free_string_field (&(args_info->skip_orig));
   free_string_field (&(args_info->cross_validation_orig));
-  free_string_field (&(args_info->error_function_orig));
-  free_string_field (&(args_info->k_value_orig));
+  free_string_field (&(args_info->num_cv_runs_orig));
+  free_string_field (&(args_info->svm_type_orig));
   free_string_field (&(args_info->tradeoff_orig));
-  free_string_field (&(args_info->params_arg));
-  free_string_field (&(args_info->params_orig));
+  free_string_field (&(args_info->nu_orig));
   
   
 
     write_into_file(outfile, "model", args_info->model_orig, 0);
   if (args_info->all_given)
     write_into_file(outfile, "all", 0, 0 );
-  if (args_info->slack_given)
-    write_into_file(outfile, "slack", 0, 0 );
-  if (args_info->verbosity_given)
-    write_into_file(outfile, "verbosity", args_info->verbosity_orig, 0);
   if (args_info->skip_given)
     write_into_file(outfile, "skip", args_info->skip_orig, 0);
   if (args_info->normalize_given)
     write_into_file(outfile, "normalize", 0, 0 );
   if (args_info->cross_validation_given)
     write_into_file(outfile, "cross_validation", args_info->cross_validation_orig, 0);
-  if (args_info->error_function_given)
-    write_into_file(outfile, "error_function", args_info->error_function_orig, 0);
-  if (args_info->k_value_given)
-    write_into_file(outfile, "k_value", args_info->k_value_orig, 0);
+  if (args_info->num_cv_runs_given)
+    write_into_file(outfile, "num_cv_runs", args_info->num_cv_runs_orig, 0);
+  if (args_info->svm_type_given)
+    write_into_file(outfile, "svm_type", args_info->svm_type_orig, 0);
+  if (args_info->balance_given)
+    write_into_file(outfile, "balance", 0, 0 );
   if (args_info->tradeoff_given)
     write_into_file(outfile, "tradeoff", args_info->tradeoff_orig, 0);
-  if (args_info->params_given)
-    write_into_file(outfile, "params", args_info->params_orig, 0);
+  if (args_info->nu_given)
+    write_into_file(outfile, "nu", args_info->nu_orig, 0);
   if (args_info->mmap_given)
     write_into_file(outfile, "mmap", 0, 0 );
   
         { "input",	1, NULL, 'i' },
         { "model",	1, NULL, 'm' },
         { "all",	0, NULL, 'a' },
-        { "slack",	0, NULL, 'S' },
-        { "verbosity",	1, NULL, 'v' },
         { "skip",	1, NULL, 's' },
         { "normalize",	0, NULL, 'n' },
         { "cross_validation",	1, NULL, 'c' },
-        { "error_function",	1, NULL, 'e' },
-        { "k_value",	1, NULL, 'k' },
+        { "num_cv_runs",	1, NULL, 'r' },
+        { "svm_type",	1, NULL, 'v' },
+        { "balance",	0, NULL, 'b' },
         { "tradeoff",	1, NULL, 't' },
-        { "params",	1, NULL, 'p' },
+        { "nu",	1, NULL, 'u' },
         { "mmap",	0, NULL, 'M' },
         { NULL,	0, NULL, 0 }
       };
 
-      c = getopt_long (argc, argv, "hVl:o:i:m:aSv:s:nc:e:k:t:p:M", long_options, &option_index);
+      c = getopt_long (argc, argv, "hVl:o:i:m:as:nc:r:v:bt:u:M", long_options, &option_index);
 
       if (c == -1) break;	/* Exit from `while (1)' loop.  */
 
             goto failure;
         
           break;
-        case 'S':	/* Use slack rescaling (not implemented for ROC loss).  */
-        
-        
-          if (update_arg((void *)&(args_info->slack_flag), 0, &(args_info->slack_given),
-              &(local_args_info.slack_given), optarg, 0, 0, ARG_FLAG,
-              check_ambiguity, override, 1, 0, "slack", 'S',
-              additional_error))
-            goto failure;
-        
-          break;
-        case 'v':	/* Sets the svm_struct verbosity.  */
-        
-        
-          if (update_arg( (void *)&(args_info->verbosity_arg), 
-               &(args_info->verbosity_orig), &(args_info->verbosity_given),
-              &(local_args_info.verbosity_given), optarg, 0, "0", ARG_INT,
-              check_ambiguity, override, 0, 0,
-              "verbosity", 'v',
-              additional_error))
-            goto failure;
-        
-          break;
         case 's':	/* Number of columns to skip in input pcls.  */
         
         
             goto failure;
         
           break;
-        case 'e':	/* Sets the loss function for SVM learning: Choice of:
-        0\tZero/one loss: 1 if vector of predictions contains error, 0 otherwise.
-        1\tF1: 100 minus the F1-score in percent.
-        2\tErrorrate: Percentage of errors in prediction vector.
-        3\tPrec/Rec Breakeven: 100 minus PRBEP in percent.
-        4\tPrec@k: 100 minus precision at k in percent.
-        5\tRec@k: 100 minus recall at k in percent.
-        10\tROCArea: Percentage of swapped pos/neg pairs (i.e. 100 - ROCArea).\n.  */
+        case 'r':	/* Number of cross-validation runs.  */
         
         
-          if (update_arg( (void *)&(args_info->error_function_arg), 
-               &(args_info->error_function_orig), &(args_info->error_function_given),
-              &(local_args_info.error_function_given), optarg, 0, "10", ARG_INT,
+          if (update_arg( (void *)&(args_info->num_cv_runs_arg), 
+               &(args_info->num_cv_runs_orig), &(args_info->num_cv_runs_given),
+              &(local_args_info.num_cv_runs_given), optarg, 0, "1", ARG_INT,
               check_ambiguity, override, 0, 0,
-              "error_function", 'e',
+              "num_cv_runs", 'r',
               additional_error))
             goto failure;
         
           break;
-        case 'k':	/* Value of k parameter used for Prec@k and Rec@k in (0,1).  */
+        case 'v':	/* Sets type of SVM (default 0)
+        0\tC-SVC
+        1\tnu-SVC
+        2\tone-class SVM\n.  */
         
         
-          if (update_arg( (void *)&(args_info->k_value_arg), 
-               &(args_info->k_value_orig), &(args_info->k_value_given),
-              &(local_args_info.k_value_given), optarg, 0, "0.5", ARG_FLOAT,
+          if (update_arg( (void *)&(args_info->svm_type_arg), 
+               &(args_info->svm_type_orig), &(args_info->svm_type_given),
+              &(local_args_info.svm_type_given), optarg, 0, "0", ARG_INT,
               check_ambiguity, override, 0, 0,
-              "k_value", 'k',
+              "svm_type", 'v',
               additional_error))
             goto failure;
         
           break;
-        case 't':	/* SVM tradeoff constant C.  */
+        case 'b':	/* weight classes such that C_P * n_P = C_N * n_N.  */
+        
+        
+          if (update_arg((void *)&(args_info->balance_flag), 0, &(args_info->balance_given),
+              &(local_args_info.balance_given), optarg, 0, 0, ARG_FLAG,
+              check_ambiguity, override, 1, 0, "balance", 'b',
+              additional_error))
+            goto failure;
+        
+          break;
+        case 't':	/* SVM tradeoff constant C of C-SVC.  */
         
         
           if (update_arg( (void *)&(args_info->tradeoff_arg), 
             goto failure;
         
           break;
-        case 'p':	/* Parameter file.  */
+        case 'u':	/* nu parameter of nu-SVC, one-class SVM.  */
         
         
-          if (update_arg( (void *)&(args_info->params_arg), 
-               &(args_info->params_orig), &(args_info->params_given),
-              &(local_args_info.params_given), optarg, 0, 0, ARG_STRING,
+          if (update_arg( (void *)&(args_info->nu_arg), 
+               &(args_info->nu_orig), &(args_info->nu_given),
+              &(local_args_info.nu_given), optarg, 0, "0.5", ARG_FLOAT,
               check_ambiguity, override, 0, 0,
-              "params", 'p',
+              "nu", 'u',
               additional_error))
             goto failure;
         

File tools/LibSVMer/cmdline.h

   const char *model_help; /**< @brief Model file help description.  */
   int all_flag;	/**< @brief Always classify all genes in PCLs (default=off).  */
   const char *all_help; /**< @brief Always classify all genes in PCLs help description.  */
-  int slack_flag;	/**< @brief Use slack rescaling (not implemented for ROC loss) (default=off).  */
-  const char *slack_help; /**< @brief Use slack rescaling (not implemented for ROC loss) help description.  */
-  int verbosity_arg;	/**< @brief Sets the svm_struct verbosity (default='0').  */
-  char * verbosity_orig;	/**< @brief Sets the svm_struct verbosity original value given at command line.  */
-  const char *verbosity_help; /**< @brief Sets the svm_struct verbosity help description.  */
   int skip_arg;	/**< @brief Number of columns to skip in input pcls (default='2').  */
   char * skip_orig;	/**< @brief Number of columns to skip in input pcls original value given at command line.  */
   const char *skip_help; /**< @brief Number of columns to skip in input pcls help description.  */
   int cross_validation_arg;	/**< @brief Number of cross-validation sets ( arg of 1 will turn off cross-validation ) (default='5').  */
   char * cross_validation_orig;	/**< @brief Number of cross-validation sets ( arg of 1 will turn off cross-validation ) original value given at command line.  */
   const char *cross_validation_help; /**< @brief Number of cross-validation sets ( arg of 1 will turn off cross-validation ) help description.  */
-  int error_function_arg;	/**< @brief Sets the loss function for SVM learning: Choice of:
-  0\tZero/one loss: 1 if vector of predictions contains error, 0 otherwise.
-  1\tF1: 100 minus the F1-score in percent.
-  2\tErrorrate: Percentage of errors in prediction vector.
-  3\tPrec/Rec Breakeven: 100 minus PRBEP in percent.
-  4\tPrec@k: 100 minus precision at k in percent.
-  5\tRec@k: 100 minus recall at k in percent.
-  10\tROCArea: Percentage of swapped pos/neg pairs (i.e. 100 - ROCArea).\n (default='10').  */
-  char * error_function_orig;	/**< @brief Sets the loss function for SVM learning: Choice of:
-  0\tZero/one loss: 1 if vector of predictions contains error, 0 otherwise.
-  1\tF1: 100 minus the F1-score in percent.
-  2\tErrorrate: Percentage of errors in prediction vector.
-  3\tPrec/Rec Breakeven: 100 minus PRBEP in percent.
-  4\tPrec@k: 100 minus precision at k in percent.
-  5\tRec@k: 100 minus recall at k in percent.
-  10\tROCArea: Percentage of swapped pos/neg pairs (i.e. 100 - ROCArea).\n original value given at command line.  */
-  const char *error_function_help; /**< @brief Sets the loss function for SVM learning: Choice of:
-  0\tZero/one loss: 1 if vector of predictions contains error, 0 otherwise.
-  1\tF1: 100 minus the F1-score in percent.
-  2\tErrorrate: Percentage of errors in prediction vector.
-  3\tPrec/Rec Breakeven: 100 minus PRBEP in percent.
-  4\tPrec@k: 100 minus precision at k in percent.
-  5\tRec@k: 100 minus recall at k in percent.
-  10\tROCArea: Percentage of swapped pos/neg pairs (i.e. 100 - ROCArea).\n help description.  */
-  float k_value_arg;	/**< @brief Value of k parameter used for Prec@k and Rec@k in (0,1) (default='0.5').  */
-  char * k_value_orig;	/**< @brief Value of k parameter used for Prec@k and Rec@k in (0,1) original value given at command line.  */
-  const char *k_value_help; /**< @brief Value of k parameter used for Prec@k and Rec@k in (0,1) help description.  */
-  float tradeoff_arg;	/**< @brief SVM tradeoff constant C (default='1').  */
-  char * tradeoff_orig;	/**< @brief SVM tradeoff constant C original value given at command line.  */
-  const char *tradeoff_help; /**< @brief SVM tradeoff constant C help description.  */
-  char * params_arg;	/**< @brief Parameter file.  */
-  char * params_orig;	/**< @brief Parameter file original value given at command line.  */
-  const char *params_help; /**< @brief Parameter file help description.  */
+  int num_cv_runs_arg;	/**< @brief Number of cross-validation runs (default='1').  */
+  char * num_cv_runs_orig;	/**< @brief Number of cross-validation runs original value given at command line.  */
+  const char *num_cv_runs_help; /**< @brief Number of cross-validation runs help description.  */
+  int svm_type_arg;	/**< @brief Sets type of SVM (default 0)
+  0\tC-SVC
+  1\tnu-SVC
+  2\tone-class SVM\n (default='0').  */
+  char * svm_type_orig;	/**< @brief Sets type of SVM (default 0)
+  0\tC-SVC
+  1\tnu-SVC
+  2\tone-class SVM\n original value given at command line.  */
+  const char *svm_type_help; /**< @brief Sets type of SVM (default 0)
+  0\tC-SVC
+  1\tnu-SVC
+  2\tone-class SVM\n help description.  */
+  int balance_flag;	/**< @brief weight classes such that C_P * n_P = C_N * n_N (default=off).  */
+  const char *balance_help; /**< @brief weight classes such that C_P * n_P = C_N * n_N help description.  */
+  float tradeoff_arg;	/**< @brief SVM tradeoff constant C of C-SVC (default='1').  */
+  char * tradeoff_orig;	/**< @brief SVM tradeoff constant C of C-SVC original value given at command line.  */
+  const char *tradeoff_help; /**< @brief SVM tradeoff constant C of C-SVC help description.  */
+  float nu_arg;	/**< @brief nu parameter of nu-SVC, one-class SVM (default='0.5').  */
+  char * nu_orig;	/**< @brief nu parameter of nu-SVC, one-class SVM original value given at command line.  */
+  const char *nu_help; /**< @brief nu parameter of nu-SVC, one-class SVM help description.  */
   int mmap_flag;	/**< @brief Memory map binary input (default=off).  */
   const char *mmap_help; /**< @brief Memory map binary input help description.  */
   
   unsigned int input_given ;	/**< @brief Whether input was given.  */
   unsigned int model_given ;	/**< @brief Whether model was given.  */
   unsigned int all_given ;	/**< @brief Whether all was given.  */
-  unsigned int slack_given ;	/**< @brief Whether slack was given.  */
-  unsigned int verbosity_given ;	/**< @brief Whether verbosity was given.  */
   unsigned int skip_given ;	/**< @brief Whether skip was given.  */
   unsigned int normalize_given ;	/**< @brief Whether normalize was given.  */
   unsigned int cross_validation_given ;	/**< @brief Whether cross_validation was given.  */
-  unsigned int error_function_given ;	/**< @brief Whether error_function was given.  */
-  unsigned int k_value_given ;	/**< @brief Whether k_value was given.  */
+  unsigned int num_cv_runs_given ;	/**< @brief Whether num_cv_runs was given.  */
+  unsigned int svm_type_given ;	/**< @brief Whether svm_type was given.  */
+  unsigned int balance_given ;	/**< @brief Whether balance was given.  */
   unsigned int tradeoff_given ;	/**< @brief Whether tradeoff was given.  */
-  unsigned int params_given ;	/**< @brief Whether params was given.  */
+  unsigned int nu_given ;	/**< @brief Whether nu was given.  */
   unsigned int mmap_given ;	/**< @brief Whether mmap was given.  */
 
 } ;

File tools/SVMperfer/SVMperfer.ggo

 option "params"   				p   "Parameter file"
 										string  typestr="filename"   no
 option	"mmap"					M	"Memory map binary input"
-										flag	off
+										flag	off