Commits

Jian Zhou committed 2b0e826 Merge

resolve

Comments (0)

Files changed (7)

   cat << EOF
 
 ** BUILDING WITHOUT SVM MULTICLASS
-SVM Multiclass is strongly recommended.
-It is available from http://svmlight.joachims.org/.
+SVM Multiclass is available from http://svmlight.joachims.org/.
 EOF
 
 fi
   cat << EOF
 
 ** BUILDING WITHOUT SVM HIERARCHY
-SVM Hierarchy is strongly recommended.
-It is available from http://svmlight.joachims.org/.
+
 EOF
 
 fi

src/svmstructtree.cpp

 	
 	void CSVMSTRUCTTREE::SetVerbosity(size_t V) {
 		struct_verbosity = (long) V;
+		//if( struct_verbosity>1)
+		//	struct_verbosity=1;
 	}
 
 	bool CSVMSTRUCTTREE::initialize() {
 
 	void CSVMSTRUCTTREE::InitializeLikAfterReadLabels() {
 		struct_parm.condLikelihood = (double*)my_malloc(sizeof(double)*struct_parm.num_classes);
-		struct_parm.condLikelihood[0] = 0;
+		struct_parm.condLikelihood[0] = 0; // now the first term in ontofile has to be the 'head node', change this to make code more robust
 		for(int i=1; i<struct_parm.num_classes;i++){
 			struct_parm.condLikelihood[i] = log(struct_parm.treeStruct.nodes[i]->parent->inputlabelCount) 
 				- log(struct_parm.treeStruct.nodes[i]->inputlabelCount);

src/svmstructtree.h

 			struct_parm.loss_type = MARGIN_RESCALING;
 		}
 
-
+		void SetNThreads(int n) {
+			struct_parm.n_threads=n;
+		}
 
 		void ReadModel(char* model_file) {
 			FreeModel();

tools/SVMhierarchy/SVMhierarchy.cpp

 	SVM.SetLearningAlgorithm(sArgs.learning_algorithm_arg);
 	SVM.SetVerbosity(sArgs.verbosity_arg);
 	SVM.SetLossFunction(sArgs.loss_function_arg);
-
+	SVM.SetNThreads(sArgs.threads_arg);
 	cerr << "SetLossFunction: " <<sArgs.loss_function_arg<< endl;
 
 	if (sArgs.cross_validation_arg < 1){
 			cerr << "Cross Validation Trial " << i << endl;
 			SVM.Learn(*pTrainSample);
 			cerr << "Learned" << endl;
+			if (i > -1) {
+				SVMArc::CSVMSTRUCTTREE::FreeSample(*pTrainSample);
+			}
 			tmpAllResults = SVM.Classify(PCL,	pTestVector[i]);
 			cerr << "Classified " << tmpAllResults.size() << " examples"<< endl;
+
+
+
 			AllResults.insert(AllResults.end(), tmpAllResults.begin(), tmpAllResults.end());
 			tmpAllResults.resize(0);
 
 						cerr << "Train with All Labeled Data " <<  endl;
 						SVM.Learn(*pTrainSample);
 						cerr << "Learned" << endl;
+                                                SVMArc::CSVMSTRUCTTREE::FreeSample(*pTrainSample);
+
 					}
 					if (sArgs.model_given ){  //learn once and write to file
 						SVM.WriteModel(sArgs.model_arg);
 
 
 
-			if (i > 0) {
-				SVMArc::CSVMSTRUCTTREE::FreeSample(*pTrainSample);
-			}
-
 
 
 

tools/SVMhierarchy/SVMhierarchy.ggo

 3\t1-slack algorithm (dual)
 4\t1-slack algorithm (dual) with constraint cache\n" 
 										int default="3" no
+option	"threads"		p	"number of threads (only apply to algorithm 3 currently)"
+										int default="4" no
 option	"mmap"					M	"Memory map binary input"
 										flag	off

tools/SVMhierarchy/cmdline.c

   "  -e, --loss_function=INT       Sets the loss function for SVM learning: Choice \n                                  of:\n\n                                  0\tHamming distance loss: total number of \n                                  differences in label vector.\n\n                                  1\tHamming distance loss (modified): total \n                                  number of differences in label vector; \n                                  over-annotation not counted as difference. \n\n                                  2\tLikelihood distance loss. \n\n                                  3\tLikelihood distance loss (modified). \n\n                                  \n                                    (default=`0')",
   "  -t, --tradeoff=FLOAT          SVM tradeoff constant C  (default=`1')",
   "  -w, --learning_algorithm=INT  Choice of structural learning algorithm \n                                  (default 4):\n\n                                  0\tn-slack algorithm \n\n                                  1\tn-slack algorithm with shrinking heuristic\n\n                                  2\t1-slack algorithm (primal) \n\n                                  3\t1-slack algorithm (dual)\n\n                                  4\t1-slack algorithm (dual) with constraint \n                                  cache\n                                    (default=`3')",
+  "  -p, --threads=INT             number of threads (only apply to algorithm 3 \n                                  currently)  (default=`4')",
   "  -M, --mmap                    Memory map binary input  (default=off)",
     0
 };
   args_info->loss_function_given = 0 ;
   args_info->tradeoff_given = 0 ;
   args_info->learning_algorithm_given = 0 ;
+  args_info->threads_given = 0 ;
   args_info->mmap_given = 0 ;
 }
 
   args_info->tradeoff_orig = NULL;
   args_info->learning_algorithm_arg = 3;
   args_info->learning_algorithm_orig = NULL;
+  args_info->threads_arg = 4;
+  args_info->threads_orig = NULL;
   args_info->mmap_flag = 0;
   
 }
   args_info->loss_function_help = gengetopt_args_info_help[15] ;
   args_info->tradeoff_help = gengetopt_args_info_help[16] ;
   args_info->learning_algorithm_help = gengetopt_args_info_help[17] ;
-  args_info->mmap_help = gengetopt_args_info_help[18] ;
+  args_info->threads_help = gengetopt_args_info_help[18] ;
+  args_info->mmap_help = gengetopt_args_info_help[19] ;
   
 }
 
   free_string_field (&(args_info->loss_function_orig));
   free_string_field (&(args_info->tradeoff_orig));
   free_string_field (&(args_info->learning_algorithm_orig));
+  free_string_field (&(args_info->threads_orig));
   
   
   for (i = 0; i < args_info->inputs_num; ++i)
     write_into_file(outfile, "tradeoff", args_info->tradeoff_orig, 0);
   if (args_info->learning_algorithm_given)
     write_into_file(outfile, "learning_algorithm", args_info->learning_algorithm_orig, 0);
+  if (args_info->threads_given)
+    write_into_file(outfile, "threads", args_info->threads_orig, 0);
   if (args_info->mmap_given)
     write_into_file(outfile, "mmap", 0, 0 );
   
         { "loss_function",	1, NULL, 'e' },
         { "tradeoff",	1, NULL, 't' },
         { "learning_algorithm",	1, NULL, 'w' },
+        { "threads",	1, NULL, 'p' },
         { "mmap",	0, NULL, 'M' },
         { NULL,	0, NULL, 0 }
       };
 
-      c = getopt_long (argc, argv, "Vl:o:i:m:h:aSv:s:nc:e:t:w:M", long_options, &option_index);
+      c = getopt_long (argc, argv, "Vl:o:i:m:h:aSv:s:nc:e:t:w:p:M", long_options, &option_index);
 
       if (c == -1) break;	/* Exit from `while (1)' loop.  */
 
             goto failure;
         
           break;
+        case 'p':	/* number of threads (only apply to algorithm 3 currently).  */
+        
+        
+          if (update_arg( (void *)&(args_info->threads_arg), 
+               &(args_info->threads_orig), &(args_info->threads_given),
+              &(local_args_info.threads_given), optarg, 0, "4", ARG_INT,
+              check_ambiguity, override, 0, 0,
+              "threads", 'p',
+              additional_error))
+            goto failure;
+        
+          break;
         case 'M':	/* Memory map binary input.  */
         
         

tools/SVMhierarchy/cmdline.h

   2\t1-slack algorithm (primal) 
   3\t1-slack algorithm (dual)
   4\t1-slack algorithm (dual) with constraint cache\n help description.  */
+  int threads_arg;	/**< @brief number of threads (only apply to algorithm 3 currently) (default='4').  */
+  char * threads_orig;	/**< @brief number of threads (only apply to algorithm 3 currently) original value given at command line.  */
+  const char *threads_help; /**< @brief number of threads (only apply to algorithm 3 currently) 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 loss_function_given ;	/**< @brief Whether loss_function was given.  */
   unsigned int tradeoff_given ;	/**< @brief Whether tradeoff was given.  */
   unsigned int learning_algorithm_given ;	/**< @brief Whether learning_algorithm was given.  */
+  unsigned int threads_given ;	/**< @brief Whether threads was given.  */
   unsigned int mmap_given ;	/**< @brief Whether mmap was given.  */
 
   char **inputs ; /**< @brief unamed options (options without names) */