Permalink
Browse files

Checking LIBSVM Plus 2.9 changes - Part II

  • Loading branch information...
1 parent bb1f5a1 commit 5d8e984eee58819c3fa418c8ae07b3a7e4bda6b4 @vincenzo committed Dec 17, 2010
Showing with 658 additions and 231 deletions.
  1. +0 −1 COPYRIGHT
  2. +29 −39 Makefile.win
  3. +2 −2 svm-predict.c
  4. +35 −26 svm-train.c
  5. +463 −129 svm.cpp
  6. +129 −34 svm.h
View
@@ -1,4 +1,3 @@
-
Copyright (c) 2000-2009 Chih-Chung Chang and Chih-Jen Lin
All rights reserved.
View
@@ -1,39 +1,29 @@
-#You must ensure nmake.exe, cl.exe, link.exe are in system path.
-#VCVARS32.bat
-#Under dosbox prompt
-#nmake -f Makefile.win
-
-PYTHON_INC = c:\python26\include
-PYTHON_LIB = c:\python26\libs\python26.lib
-##########################################
-CXX = cl.exe
-CFLAGS = -nologo -O2 -EHsc -I. -D __WIN32__ -D _CRT_SECURE_NO_DEPRECATE
-TARGET = windows
-
-all: $(TARGET)\svm-train.exe $(TARGET)\svm-predict.exe $(TARGET)\svm-scale.exe $(TARGET)\svm-toy.exe
-
-python: $(TARGET)\python\svmc.pyd
-
-$(TARGET)\svm-predict.exe: svm.h svm-predict.c svm.obj
- $(CXX) $(CFLAGS) svm-predict.c svm.obj -Fe$(TARGET)\svm-predict.exe
-
-$(TARGET)\svm-train.exe: svm.h svm-train.c svm.obj
- $(CXX) $(CFLAGS) svm-train.c svm.obj -Fe$(TARGET)\svm-train.exe
-
-$(TARGET)\svm-scale.exe: svm.h svm-scale.c
- $(CXX) $(CFLAGS) svm-scale.c -Fe$(TARGET)\svm-scale.exe
-
-$(TARGET)\svm-toy.exe: svm.h svm.obj svm-toy\windows\svm-toy.cpp
- $(CXX) $(CFLAGS) svm-toy\windows\svm-toy.cpp svm.obj user32.lib gdi32.lib comdlg32.lib -Fe$(TARGET)\svm-toy.exe
-
-svm.obj: svm.cpp svm.h
- $(CXX) $(CFLAGS) -c svm.cpp
-
-$(TARGET)\python\svmc.pyd: python\svmc_wrap.c svm.obj $(PYTHON_LIB)
- $(CXX) $(CFLAGS) -I$(PYTHON_INC) -LD $** -Fe$(TARGET)\python\svmc.pyd
-# $** means all dependencies
-
-clean:
- -erase /Q *.obj $(TARGET)\. $(TARGET)\python\.
-
-
+# (by Vladislavs Dovgalecs, Universite Bordeaux I, FRANCE)
+#
+# You must ensure nmake.exe, cl.exe, link.exe are in system path.
+# VCVARS32.bat
+# Under dosbox prompt
+# nmake -f Makefile.win
+
+##########################################
+CXX = cl.exe
+CFLAGS = -nologo -O2 -EHsc -I. -D __WIN32__ -D _CRT_SECURE_NO_DEPRECATE
+TARGET = windows
+
+all: $(TARGET)\svm-train.exe $(TARGET)\svm-predict.exe $(TARGET)\svm-scale.exe
+
+$(TARGET)\svm-predict.exe: svm.h svm-predict.c svm.obj
+ $(CXX) $(CFLAGS) svm-predict.c svm.obj -Fe$(TARGET)\svm-predict.exe
+
+$(TARGET)\svm-train.exe: svm.h svm-train.c svm.obj
+ $(CXX) $(CFLAGS) svm-train.c svm.obj -Fe$(TARGET)\svm-train.exe
+
+$(TARGET)\svm-scale.exe: svm.h svm-scale.c
+ $(CXX) $(CFLAGS) svm-scale.c -Fe$(TARGET)\svm-scale.exe
+
+svm.obj: svm.cpp svm.h
+ $(CXX) $(CFLAGS) -c svm.cpp
+
+clean:
+ -erase /Q *.obj $(TARGET)\.
+
View
@@ -107,7 +107,7 @@ void predict(FILE *input, FILE *output)
exit_input_error(total+1);
++i;
- }
+ }
x[i].index = -1;
if (predict_probability && (svm_type==C_SVC || svm_type==NU_SVC))
@@ -201,7 +201,7 @@ int main(int argc, char **argv)
fprintf(stderr,"can't open model file %s\n",argv[i+1]);
exit(1);
}
-
+
x = (struct svm_node *) malloc(max_nr_attr*sizeof(struct svm_node));
if(predict_probability)
{
View
@@ -14,31 +14,40 @@ void exit_with_help()
"Usage: svm-train [options] training_set_file [model_file]\n"
"options:\n"
"-s svm_type : set type of SVM (default 0)\n"
- " 0 -- C-SVC\n"
- " 1 -- nu-SVC\n"
- " 2 -- one-class SVM\n"
- " 3 -- epsilon-SVR\n"
- " 4 -- nu-SVR\n"
+ "\t%d -- C-SVC (L1SVM)\n"
+ "\t%d -- C-SVC (L2SVM)\n"
+ "\t%d -- nu-SVC\n"
+ "\t%d -- one-class SVM\n"
+ "\t%d -- epsilon-SVR\n"
+ "\t%d -- nu-SVR\n"
+ "\t%d -- SVDD (L1SVM)\n"
+ "\t%d -- SVDD (L2SVM)\n"
"-t kernel_type : set type of kernel function (default 2)\n"
- " 0 -- linear: u'*v\n"
- " 1 -- polynomial: (gamma*u'*v + coef0)^degree\n"
- " 2 -- radial basis function: exp(-gamma*|u-v|^2)\n"
- " 3 -- sigmoid: tanh(gamma*u'*v + coef0)\n"
- " 4 -- precomputed kernel (kernel values in training_set_file)\n"
- "-d degree : set degree in kernel function (default 3)\n"
- "-g gamma : set gamma in kernel function (default 1/num_features)\n"
- "-r coef0 : set coef0 in kernel function (default 0)\n"
- "-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)\n"
- "-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n"
- "-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)\n"
- "-m cachesize : set cache memory size in MB (default 100)\n"
- "-e epsilon : set tolerance of termination criterion (default 0.001)\n"
- "-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)\n"
- "-b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n"
- "-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n"
+ "\t%d -- linear: u'*v\n"
+ "\t%d -- polynomial: (gamma*u'*v + coef0)^degree\n"
+ "\t%d -- gaussian: exp(-gamma*||u-v||^2)\n"
+ "\t%d -- sigmoid: tanh(gamma*u'*v + coef0)\n"
+ "\t%d -- stump: -|u-v| + coef0\n"
+ "\t%d -- perceptron: -||u-v|| + coef0\n"
+ "\t%d -- laplacian: exp(-gamma*|u-v|)\n"
+ "\t%d -- exponential: exp(-gamma*||u-v||)\n"
+ "\t%d -- precomputed kernel (kernel values in training_set_file)\n"
+ "-d degree: set degree in kernel function (default 3)\n"
+ "-g gamma: set gamma in kernel function (default 1/num_features)\n"
+ "-r coef0: set coef0 in kernel function (default 0)\n"
+ "-c cost: set the parameter C of C-SVC (L1/L2-SVM), SVDD (L1/L2-SVM), epsilon-SVR, and nu-SVR (default 1)\n"
+ "-n nu: set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)\n"
+ "-p epsilon: set the epsilon in loss function of epsilon-SVR (default 0.1)\n"
+ "-m cachesize: set cache memory size in MB (default 100)\n"
+ "-e epsilon: set tolerance of termination criterion (default 0.001)\n"
+ "-h shrinking: whether to use the shrinking heuristics, 0 or 1 (default 1)\n"
+ "-b probability_estimates: whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n"
+ "-wi weight: set the parameter C of class i to weight*C, for C-SVC (default 1)\n"
"-v n: n-fold cross validation mode\n"
- "-q : quiet mode (no outputs)\n"
- );
+ "-q: quiet mode (no outputs)\n", C_SVC, C_SVC_L2, NU_SVC, ONE_CLASS,
+ EPSILON_SVR, NU_SVR, SVDD, SVDD_L2,
+ LINEAR, POLY, GAUSSIAN, SIGMOID, STUMP,
+ PERC, LAPLACE, EXPO, PRECOMPUTED);
exit(1);
}
@@ -160,7 +169,7 @@ void parse_command_line(int argc, char **argv, char *input_file_name, char *mode
// default values
param.svm_type = C_SVC;
- param.kernel_type = RBF;
+ param.kernel_type = GAUSSIAN;
param.degree = 3;
param.gamma = 0; // 1/num_features
param.coef0 = 0;
@@ -274,7 +283,7 @@ void read_problem(const char *filename)
FILE *fp = fopen(filename,"r");
char *endptr;
char *idx, *val, *label;
-
+
if(fp == NULL)
{
fprintf(stderr,"can't open input file %s\n",filename);
@@ -340,7 +349,7 @@ void read_problem(const char *filename)
exit_input_error(i+1);
++j;
- }
+ }
if(inst_max_index > max_index)
max_index = inst_max_index;
Oops, something went wrong.

0 comments on commit 5d8e984

Please sign in to comment.