diff -Nru libsvm-3.1/COPYRIGHT libsvm-3.12/COPYRIGHT --- libsvm-3.1/COPYRIGHT 2011-03-26 03:25:55.000000000 +0000 +++ libsvm-3.12/COPYRIGHT 2012-01-31 05:51:12.000000000 +0000 @@ -1,5 +1,5 @@ -Copyright (c) 2000-2011 Chih-Chung Chang and Chih-Jen Lin +Copyright (c) 2000-2012 Chih-Chung Chang and Chih-Jen Lin All rights reserved. Redistribution and use in source and binary forms, with or without diff -Nru libsvm-3.1/debian/changelog libsvm-3.12/debian/changelog --- libsvm-3.1/debian/changelog 2012-06-18 03:26:53.000000000 +0000 +++ libsvm-3.12/debian/changelog 2012-06-15 16:55:39.000000000 +0000 @@ -1,8 +1,19 @@ -libsvm (3.1-1build1) precise; urgency=low +libsvm (3.12-1) unstable; urgency=low - * Rebuild to drop python2.6 dependencies and provides. + * New upstream release + * Remove patchsys-quilt.mk and upgrade to packaging format "3.0 quilt". + (Closes: #667791) + * Update to Standards-Version to 3.9.3 and debhelper to 9. + * Change obsolete depends default-jdk-builddep to default-jdk. + (Closes: #669223) + * Fix description-synopsis-starts-with-article (Lintian). + * Fix extended-description-is-probably-too-short (Lintian). + * Fix needless-dependency-on-jre (Lintian). + * Fix capitalization-error-in-description Python (Lintian). + * Fix duplicate-short-description (Lintian). + * Add build-arch and build-indep rules. (Closes: #673215) - -- Matthias Klose Sat, 14 Apr 2012 13:42:56 +0000 + -- Chen-Tse Tsai Mon, 11 Jun 2012 16:14:24 +0800 libsvm (3.1-1) unstable; urgency=low diff -Nru libsvm-3.1/debian/compat libsvm-3.12/debian/compat --- libsvm-3.1/debian/compat 2012-06-18 03:26:53.000000000 +0000 +++ libsvm-3.12/debian/compat 2012-06-15 08:49:57.000000000 +0000 @@ -1 +1 @@ -5 +9 diff -Nru libsvm-3.1/debian/control libsvm-3.12/debian/control --- libsvm-3.1/debian/control 2012-06-18 03:26:53.000000000 +0000 +++ libsvm-3.12/debian/control 2012-06-15 17:31:59.000000000 +0000 @@ -4,8 +4,8 @@ Maintainer: Chen-Tse Tsai XS-Python-Version: all DM-Upload-Allowed: yes -Build-Depends: debhelper (>= 5.0.0), autotools-dev, libtool, cdbs, python-all-dev (>= 2.3.5-7), python-support (>= 0.90), default-jdk-builddep -Standards-Version: 3.9.2.0 +Build-Depends: debhelper (>= 9), autotools-dev, libtool, cdbs, python-all-dev (>= 2.3.5-7), python-support (>= 0.90), default-jdk +Standards-Version: 3.9.3 Homepage: http://www.csie.ntu.edu.tw/~cjlin/libsvm/ Package: libsvm3 @@ -22,7 +22,7 @@ Package: libsvm-tools Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, gnuplot -Description: The LIBSVM binary tools +Description: LIBSVM binary tools LIBSVM is an easy-to-use package for support vector classification, regression and one-class SVM. It supports multi-class classification, probability outputs, and parameter selection. @@ -32,8 +32,13 @@ Architecture: any Section: libdevel Depends: ${shlibs:Depends}, ${misc:Depends}, libsvm3 (=${binary:Version}) -Description: The LIBSVM header files - These are the header files for LIBSVM, a machine-learning library. +Description: LIBSVM header files + LIBSVM, a machine-learning library, is an easy-to-use package for + support vector classification, regression and one-class SVM. It + supports multi-class classification, probability outputs, and + parameter selection. + . + This package contains the development header files. Package: python-libsvm Architecture: any @@ -41,17 +46,17 @@ Depends: libsvm3(=${binary:Version}), ${python:Depends}, ${misc:Depends}, ${shlibs:Depends} Provides: ${python:Provides} Description: Python interface for support vector machine library - Python interface for the LIBSVM library using ctypes. This new python interface - is provided since 2.91, and it is incompatible with the old one. - + Python interface for the LIBSVM library using ctypes. This new Python + interface is provided since 2.91, and it is incompatible with the old + one. Package: libsvm3-java Architecture: all Section: java -Depends: gij | java-gcj-compat | java1-runtime | java2-runtime, ${misc:Depends} -Conflicts: libsvm2-java (<= 2.91-2) +Depends: ${misc:Depends} +Conflicts: libsvm2-java Suggests: java-virtual-machine -Description: Java API to support vector machine library +Description: Java API to support vector machine library (libsvm3.jar) The functionality of the libsvm are offered in a single jar file. It includes one-class, two-class, multiclass, regression-mode, and probablistic output functionality. @@ -60,10 +65,10 @@ Architecture: all Section: java Depends: libsvm3-java, ${misc:Depends} -Description: Java API to support vector machine library +Description: Java API to support vector machine library (libsvm.jar) The functionality of the libsvm are offered in a single jar file. It includes one-class, two-class, multiclass, regression-mode, and probablistic output functionality. . - This package solely provides a symbolic link from svm.jar svm3.jar. + This package solely provides a symbolic link from libsvm.jar libsvm3.jar. diff -Nru libsvm-3.1/debian/doc/svm-grid.1 libsvm-3.12/debian/doc/svm-grid.1 --- libsvm-3.1/debian/doc/svm-grid.1 2012-06-18 03:26:53.000000000 +0000 +++ libsvm-3.12/debian/doc/svm-grid.1 2012-06-15 17:24:00.000000000 +0000 @@ -37,7 +37,7 @@ for the format of .I dataset .SH EXAMPLES -svm-grid -log2c -5,5,1 -log2g -4,0,1 -v 5 -m 300 heart_scale +svm-grid \-log2c \-5,5,1 \-log2g \-4,0,1 \-v 5 \-m 300 heart_scale .SH BUGS Please report bugs to the Debian BTS. diff -Nru libsvm-3.1/debian/doc/svm-scale.1 libsvm-3.12/debian/doc/svm-scale.1 --- libsvm-3.1/debian/doc/svm-scale.1 2012-06-18 03:26:53.000000000 +0000 +++ libsvm-3.12/debian/doc/svm-scale.1 2012-06-15 17:26:13.000000000 +0000 @@ -29,7 +29,7 @@ .SH OPTIONS .IP "-l lower" .I lower -is the lowest (minimal) value allowed in each dimension. It defaults to -1. +is the lowest (minimal) value allowed in each dimension. It defaults to \-1. .IP "-u upper" .I upper is the highest (maximal) value allowed in each dimension. It defaults to 1. diff -Nru libsvm-3.1/debian/doc/svm-train.1 libsvm-3.12/debian/doc/svm-train.1 --- libsvm-3.1/debian/doc/svm-train.1 2012-06-18 03:26:53.000000000 +0000 +++ libsvm-3.12/debian/doc/svm-train.1 2012-06-15 17:26:32.000000000 +0000 @@ -141,7 +141,7 @@ .I n for .I n --fold cross validation mode +\-fold cross validation mode .IP "-q" quiet mode; suppress messages to stdout. .SH FILES diff -Nru libsvm-3.1/debian/libsvm3.install libsvm-3.12/debian/libsvm3.install --- libsvm-3.1/debian/libsvm3.install 2012-06-18 03:26:53.000000000 +0000 +++ libsvm-3.12/debian/libsvm3.install 2012-06-15 08:49:00.000000000 +0000 @@ -1,2 +1,2 @@ -libsvm.so.3.1 usr/lib +libsvm.so.3.12 usr/lib libsvm.so.3 usr/lib diff -Nru libsvm-3.1/debian/rules libsvm-3.12/debian/rules --- libsvm-3.1/debian/rules 2012-06-18 03:26:53.000000000 +0000 +++ libsvm-3.12/debian/rules 2012-06-15 08:49:26.000000000 +0000 @@ -1,7 +1,6 @@ #!/usr/bin/make -f include /usr/share/cdbs/1/rules/debhelper.mk -#include /usr/share/cdbs/1/rules/patchsys-quilt.mk #include /usr/share/cdbs/1/class/makefile.mk #include /usr/share/python/python.mk @@ -21,14 +20,16 @@ # use pysupport to install files of python-libsvm #PYVERS=$(shell pyversions -vs) LVER=3 -LSUBVER=1 +LSUBVER=12 SOVER=$(LVER).$(LSUBVER) LIBFILE=libsvm.so.$(SOVER) CXX ?= g++ CFLAGS = -Wall -Wconversion -O3 LIBFLAGS = -fPIC -build: svm-train svm-predict svm-scale $(LIBFILE) .javastuff chname +build: build-arch build-indep +build-arch: svm-train svm-predict svm-scale $(LIBFILE) chname +build-indep: .javastuff .javastuff: $(MAKE) -C java diff -Nru libsvm-3.1/debian/source/format libsvm-3.12/debian/source/format --- libsvm-3.1/debian/source/format 1970-01-01 00:00:00.000000000 +0000 +++ libsvm-3.12/debian/source/format 2012-06-18 03:26:54.000000000 +0000 @@ -0,0 +1 @@ +3.0 (quilt) diff -Nru libsvm-3.1/FAQ.html libsvm-3.12/FAQ.html --- libsvm-3.1/FAQ.html 2011-03-26 03:25:55.000000000 +0000 +++ libsvm-3.12/FAQ.html 2012-03-31 22:17:50.000000000 +0000 @@ -1,1781 +1,1899 @@ - - -LIBSVM FAQ - - -

LIBSVM FAQ

-last modified : -Sun, 13 Mar 2011 13:30:52 GMT - -
  • All Questions(74)
  • - - - - - -
    -

    - - -Q: Some courses which have used libsvm as a tool -
    -

    -

    -[Go Top] -


    - -Q: Some applications/tools which have used libsvm -
    -(and maybe liblinear). - -

    -[Go Top] -


    - -Q: Where can I find documents of libsvm ? -
    -

    - -

    -

    -[Go Top] -


    - -Q: Where are change log and earlier versions? -
    -

    See the change log. - -

    You can download earlier versions -here. -

    -[Go Top] -


    - -Q: How to cite LIBSVM? -
    -

    -Please cite the following document: -

    -Chih-Chung Chang and Chih-Jen Lin, LIBSVM -: a library for support vector machines, 2001. -Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm -

    -The bibtex format is -

    -@Manual{CC01a,
    -  author =	 {Chih-Chung Chang and Chih-Jen Lin},
    -  title =	 {{LIBSVM}: a library for support vector machines},
    -  year =	 {2001},
    -  note =	 {Software available at \url{http://www.csie.ntu.edu.tw/~cjlin/libsvm}}
    -}
    -
    -

    -[Go Top] -


    - -Q: I would like to use libsvm in my software. Is there any license problem? -
    -

    -The libsvm license ("the modified BSD license") -is compatible with many -free software licenses such as GPL. Hence, it is very easy to -use libsvm in your software. -Please check the COPYRIGHT file in detail. Basically -you need to -

      -
    1. -Clearly indicate that LIBSVM is used. -
    2. -
    3. -Retain the LIBSVM COPYRIGHT file in your software. -
    4. -
    -It can also be used in commercial products. -

    -[Go Top] -


    - -Q: Is there a repository of additional tools based on libsvm? -
    -

    -Yes, see libsvm -tools -

    -[Go Top] -


    - -Q: On unix machines, I got "error in loading shared libraries" or "cannot open shared object file." What happened ? -
    - -

    -This usually happens if you compile the code -on one machine and run it on another which has incompatible -libraries. -Try to recompile the program on that machine or use static linking. -

    -[Go Top] -


    - -Q: I have modified the source and would like to build the graphic interface "svm-toy" on MS windows. How should I do it ? -
    - -

    -Build it as a project by choosing "Win32 Project." -On the other hand, for "svm-train" and "svm-predict" -you want to choose "Win32 Console Project." -After libsvm 2.5, you can also use the file Makefile.win. -See details in README. - - -

    -If you are not using Makefile.win and see the following -link error -

    -LIBCMTD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol
    -_wWinMain@16
    -
    -you may have selected a wrong project type. -

    -[Go Top] -


    - -Q: I am an MS windows user but why only one (svm-toy) of those precompiled .exe actually runs ? -
    - -

    -You need to open a command window -and type svmtrain.exe to see all options. -Some examples are in README file. -

    -[Go Top] -


    - -Q: What is the difference between "." and "*" outputed during training? -
    - -

    -"." means every 1,000 iterations (or every #data -iterations is your #data is less than 1,000). -"*" means that after iterations of using -a smaller shrunk problem, -we reset to use the whole set. See the -implementation document for details. -

    -[Go Top] -


    - -Q: Why occasionally the program (including MATLAB or other interfaces) crashes and gives a segmentation fault? -
    - -

    -Very likely the program consumes too much memory than what the -operating system can provide. Try a smaller data and see if the -program still crashes. -

    -[Go Top] -


    - -Q: How to build a dynamic library (.dll file) on MS windows? -
    -

    - -The easiest way is to use Makefile.win. -See details in README. - -Alternatively, you can use Visual C++. Here is -the example using Visual Studio .Net 2008: -

      -
    1. Create a Win32 empty DLL project and set (in Project->$Project_Name -Properties...->Configuration) to "Release." - About how to create a new dynamic link library, please refer to -http://msdn2.microsoft.com/en-us/library/ms235636(VS.80).aspx - -
    2. Add svm.cpp, svm.h to your project. -
    3. Add __WIN32__ and _CRT_SECURE_NO_DEPRECATE to Preprocessor definitions (in -Project->$Project_Name Properties...->C/C++->Preprocessor) -
    4. Set Create/Use Precompiled Header to Not Using Precompiled Headers -(in Project->$Project_Name Properties...->C/C++->Precompiled Headers) -
    5. Set the path for the Modulation Definition File svm.def (in -Project->$Project_Name Properties...->Linker->input -
    6. Build the DLL. -
    7. Rename the dll file to libsvm.dll and move it to the correct path. -
    - - -

    -[Go Top] -


    - -Q: On some systems (e.g., Ubuntu), compiling LIBSVM gives many warning messages. Is this a problem and how to disable the warning message? -
    - -

    -The warning message is like -

    -svm.cpp:2730: warning: ignoring return value of int fscanf(FILE*, const char*, ...), declared with attribute warn_unused_result
    -
    -but this is not a problem. In the future we may modify the code -so that these messages do not appear. -At this moment, to disable the warning message you can replace -
    -CFLAGS = -Wall -Wconversion -O3 -fPIC
    -
    -with -
    -CFLAGS = -Wall -Wconversion -O3 -fPIC -U_FORTIFY_SOURCE
    -
    -in Makefile. -

    -[Go Top] -


    - -Q: Why sometimes not all attributes of a data appear in the training/model files ? -
    -

    -libsvm uses the so called "sparse" format where zero -values do not need to be stored. Hence a data with attributes -

    -1 0 2 0
    -
    -is represented as -
    -1:1 3:2
    -
    -

    -[Go Top] -


    - -Q: What if my data are non-numerical ? -
    -

    -Currently libsvm supports only numerical data. -You may have to change non-numerical data to -numerical. For example, you can use several -binary attributes to represent a categorical -attribute. -

    -[Go Top] -


    - -Q: Why do you consider sparse format ? Will the training of dense data be much slower ? -
    -

    -This is a controversial issue. The kernel -evaluation (i.e. inner product) of sparse vectors is slower -so the total training time can be at least twice or three times -of that using the dense format. -However, we cannot support only dense format as then we CANNOT -handle extremely sparse cases. Simplicity of the code is another -concern. Right now we decide to support -the sparse format only. -

    -[Go Top] -


    - -Q: Why sometimes the last line of my data is not read by svm-train? -
    - -

    -We assume that you have '\n' in the end of -each line. So please press enter in the end -of your last line. -

    -[Go Top] -


    - -Q: Is there a program to check if my data are in the correct format? -
    - -

    -The svm-train program in libsvm conducts only a simple check of the input data. To do a -detailed check, after libsvm 2.85, you can use the python script tools/checkdata.py. See tools/README for details. -

    -[Go Top] -


    - -Q: May I put comments in data files? -
    - -

    -We don't officially support this. But, cureently LIBSVM -is able to process data in the following -format: -

    -1 1:2 2:1 # your comments
    -
    -Note that the character ":" should not appear in your -comments. - -

    -[Go Top] -


    - -Q: How to convert other data formats to LIBSVM format? -
    - -

    -It depends on your data format. -We have a simple C code to transfer space/colon -separated format to libsvm format. Please contact -us if needed. - -

    -Alternatively, a simple way is to use -libsvmwrite in the libsvm matlab/octave interface. - -Take a CSV (colon separated format) file -in UCI machine learning repository as an example. -We download SPECTF.train. -Labels are in the first column. The following steps produce -a file in the libsvm format. -

    -matlab> SPECTF = csvread('SPECTF.train'); % read a csv file
    -matlab> labels = SPECTF(:, 1); % labels from the 1st column
    -matlab> features = SPECTF(:, 2:end); 
    -matlab> features_sparse = sparse(features); % features must be in a sparse matrix
    -matlab> libsvmwrite('SPECTFlibsvm.train', labels, features_sparse);
    -
    -The tranformed data are stored in SPECTFlibsvm.train. -

    -[Go Top] -


    - -Q: The output of training C-SVM is like the following. What do they mean? -
    -
    optimization finished, #iter = 219 -
    nu = 0.431030 -
    obj = -100.877286, rho = 0.424632 -
    nSV = 132, nBSV = 107 -
    Total nSV = 132 -

    -obj is the optimal objective value of the dual SVM problem. -rho is the bias term in the decision function -sgn(w^Tx - rho). -nSV and nBSV are number of support vectors and bounded support -vectors (i.e., alpha_i = C). nu-svm is a somewhat equivalent -form of C-SVM where C is replaced by nu. nu simply shows the -corresponding parameter. More details are in - -libsvm document. -

    -[Go Top] -


    - -Q: Can you explain more about the model file? -
    - -

    -After the parameters, each line represents a support vector. -Support vectors are listed in the order of "labels" listed earlier. -(i.e., those from the first class in the "labels" list are -grouped first, and so on.) -If k is the total number of classes, -in front of a support vector in class j, there are -k-1 coefficients -y*alpha where alpha are dual solution of the -following two class problems: -
    -1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k -
    -and y=1 in first j-1 coefficients, y=-1 in the remaining -k-j coefficients. - -For example, if there are 4 classes, the file looks like: - -

    -+-+-+-+--------------------+
    -|1|1|1|                    |
    -|v|v|v|  SVs from class 1  |
    -|2|3|4|                    |
    -+-+-+-+--------------------+
    -|1|2|2|                    |
    -|v|v|v|  SVs from class 2  |
    -|2|3|4|                    |
    -+-+-+-+--------------------+
    -|1|2|3|                    |
    -|v|v|v|  SVs from class 3  |
    -|3|3|4|                    |
    -+-+-+-+--------------------+
    -|1|2|3|                    |
    -|v|v|v|  SVs from class 4  |
    -|4|4|4|                    |
    -+-+-+-+--------------------+
    -
    -See also - an illustration using -MATLAB/OCTAVE. -

    -[Go Top] -


    - -Q: Should I use float or double to store numbers in the cache ? -
    - -

    -We have float as the default as you can store more numbers -in the cache. -In general this is good enough but for few difficult -cases (e.g. C very very large) where solutions are huge -numbers, it might be possible that the numerical precision is not -enough using only float. -

    -[Go Top] -


    - -Q: How do I choose the kernel? -
    - -

    -In general we suggest you to try the RBF kernel first. -A recent result by Keerthi and Lin -( -download paper here) -shows that if RBF is used with model selection, -then there is no need to consider the linear kernel. -The kernel matrix using sigmoid may not be positive definite -and in general it's accuracy is not better than RBF. -(see the paper by Lin and Lin -( -download paper here). -Polynomial kernels are ok but if a high degree is used, -numerical difficulties tend to happen -(thinking about dth power of (<1) goes to 0 -and (>1) goes to infinity). -

    -[Go Top] -


    - -Q: Does libsvm have special treatments for linear SVM? -
    - -

    - -No, libsvm solves linear/nonlinear SVMs by the -same way. -Some tricks may save training/testing time if the -linear kernel is used, -so libsvm is NOT particularly efficient for linear SVM, -especially when -C is large and -the number of data is much larger -than the number of attributes. -You can either -

    - -

    Please also see our SVM guide -on the discussion of using RBF and linear -kernels. -

    -[Go Top] -


    - -Q: The number of free support vectors is large. What should I do? -
    -

    -This usually happens when the data are overfitted. -If attributes of your data are in large ranges, -try to scale them. Then the region -of appropriate parameters may be larger. -Note that there is a scale program -in libsvm. -

    -[Go Top] -


    - -Q: Should I scale training and testing data in a similar way? -
    -

    -Yes, you can do the following: -

    -> svm-scale -s scaling_parameters train_data > scaled_train_data
    -> svm-scale -r scaling_parameters test_data > scaled_test_data
    -
    -

    -[Go Top] -


    - -Q: Does it make a big difference if I scale each attribute to [0,1] instead of [-1,1]? -
    - -

    -For the linear scaling method, if the RBF kernel is -used and parameter selection is conducted, there -is no difference. Assume Mi and mi are -respectively the maximal and minimal values of the -ith attribute. Scaling to [0,1] means -

    -                x'=(x-mi)/(Mi-mi)
    -
    -For [-1,1], -
    -                x''=2(x-mi)/(Mi-mi)-1.
    -
    -In the RBF kernel, -
    -                x'-y'=(x-y)/(Mi-mi), x''-y''=2(x-y)/(Mi-mi).
    -
    -Hence, using (C,g) on the [0,1]-scaled data is the -same as (C,g/2) on the [-1,1]-scaled data. - -

    Though the performance is the same, the computational -time may be different. For data with many zero entries, -[0,1]-scaling keeps the sparsity of input data and hence -may save the time. -

    -[Go Top] -


    - -Q: The prediction rate is low. How could I improve it? -
    -

    -Try to use the model selection tool grid.py in the python -directory find -out good parameters. To see the importance of model selection, -please -see my talk: - -A practical guide to support vector -classification - -

    -[Go Top] -


    - -Q: My data are unbalanced. Could libsvm handle such problems? -
    -

    -Yes, there is a -wi options. For example, if you use -

    -> svm-train -s 0 -c 10 -w1 1 -w-1 5 data_file
    -
    -

    -the penalty for class "-1" is larger. -Note that this -w option is for C-SVC only. -

    -[Go Top] -


    - -Q: What is the difference between nu-SVC and C-SVC? -
    -

    -Basically they are the same thing but with different -parameters. The range of C is from zero to infinity -but nu is always between [0,1]. A nice property -of nu is that it is related to the ratio of -support vectors and the ratio of the training -error. -

    -[Go Top] -


    - -Q: The program keeps running (without showing any output). What should I do? -
    -

    -You may want to check your data. Each training/testing -data must be in one line. It cannot be separated. -In addition, you have to remove empty lines. -

    -[Go Top] -


    - -Q: The program keeps running (with output, i.e. many dots). What should I do? -
    -

    -In theory libsvm guarantees to converge. -Therefore, this means you are -handling ill-conditioned situations -(e.g. too large/small parameters) so numerical -difficulties occur. -

    -[Go Top] -


    - -Q: The training time is too long. What should I do? -
    -

    -For large problems, please specify enough cache size (i.e., --m). -Slow convergence may happen for some difficult cases (e.g. -c is large). -You can try to use a looser stopping tolerance with -e. -If that still doesn't work, you may train only a subset of the data. -You can use the program subset.py in the directory "tools" -to obtain a random subset. - -

    -If you have extremely large data and face this difficulty, please -contact us. We will be happy to discuss possible solutions. - -

    When using large -e, you may want to check if -h 0 (no shrinking) or -h 1 (shrinking) is faster. -See a related question below. - -

    -[Go Top] -


    - -Q: Does shrinking always help? -
    -

    -If the number of iterations is high, then shrinking -often helps. -However, if the number of iterations is small -(e.g., you specify a large -e), then -probably using -h 0 (no shrinking) is better. -See the -implementation document for details. -

    -[Go Top] -


    - -Q: How do I get the decision value(s)? -
    -

    -We print out decision values for regression. For classification, -we solve several binary SVMs for multi-class cases. You -can obtain values by easily calling the subroutine -svm_predict_values. Their corresponding labels -can be obtained from svm_get_labels. -Details are in -README of libsvm package. - -

    -We do not recommend the following. But if you would -like to get values for -TWO-class classification with labels +1 and -1 -(note: +1 and -1 but not things like 5 and 10) -in the easiest way, simply add -

    -		printf("%f\n", dec_values[0]*model->label[0]);
    -
    -after the line -
    -		svm_predict_values(model, x, dec_values);
    -
    -of the file svm.cpp. -Positive (negative) -decision values correspond to data predicted as +1 (-1). - - -

    -[Go Top] -


    - -Q: How do I get the distance between a point and the hyperplane? -
    -

    -The distance is |decision_value| / |w|. -We have |w|^2 = w^Tw = alpha^T Q alpha = 2*(dual_obj + sum alpha_i). -Thus in svm.cpp please find the place -where we calculate the dual objective value -(i.e., the subroutine Solve()) -and add a statement to print w^Tw. - -

    -[Go Top] -


    - -Q: On 32-bit machines, if I use a large cache (i.e. large -m) on a linux machine, why sometimes I get "segmentation fault ?" -
    -

    - -On 32-bit machines, the maximum addressable -memory is 4GB. The Linux kernel uses 3:1 -split which means user space is 3G and -kernel space is 1G. Although there are -3G user space, the maximum dynamic allocation -memory is 2G. So, if you specify -m near 2G, -the memory will be exhausted. And svm-train -will fail when it asks more memory. -For more details, please read - -this article. -

    -The easiest solution is to switch to a - 64-bit machine. -Otherwise, there are two ways to solve this. If your -machine supports Intel's PAE (Physical Address -Extension), you can turn on the option HIGHMEM64G -in Linux kernel which uses 4G:4G split for -kernel and user space. If you don't, you can -try a software `tub' which can eliminate the 2G -boundary for dynamic allocated memory. The `tub' -is available at -http://www.bitwagon.com/tub.html. - - - -

    -[Go Top] -


    - -Q: How do I disable screen output of svm-train? -
    -

    -For commend-line users, use the -q option: -

    -> ./svm-train -q heart_scale
    -
    -

    -For library users, set the global variable -

    -extern void (*svm_print_string) (const char *);
    -
    -to specify the output format. You can disable the output by the following steps: -
      -
    1. -Declare a function to output nothing: -
      -void print_null(const char *s) {}
      -
      -
    2. -
    3. -Assign the output function of libsvm by -
      -svm_print_string = &print_null;
      -
      -
    4. -
    -Finally, a way used in earlier libsvm -is by updating svm.cpp from -
    -#if 1
    -void info(const char *fmt,...)
    -
    -to -
    -#if 0
    -void info(const char *fmt,...)
    -
    -

    -[Go Top] -


    - -Q: I would like to use my own kernel. Any example? In svm.cpp, there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ? -
    -

    -An example is "LIBSVM for string data" in LIBSVM Tools. -

    -The reason why we have two functions is as follows. -For the RBF kernel exp(-g |xi - xj|^2), if we calculate -xi - xj first and then the norm square, there are 3n operations. -Thus we consider exp(-g (|xi|^2 - 2dot(xi,xj) +|xj|^2)) -and by calculating all |xi|^2 in the beginning, -the number of operations is reduced to 2n. -This is for the training. For prediction we cannot -do this so a regular subroutine using that 3n operations is -needed. - -The easiest way to have your own kernel is -to put the same code in these two -subroutines by replacing any kernel. -

    -[Go Top] -


    - -Q: What method does libsvm use for multi-class SVM ? Why don't you use the "1-against-the rest" method ? -
    -

    -It is one-against-one. We chose it after doing the following -comparison: -C.-W. Hsu and C.-J. Lin. - -A comparison of methods -for multi-class support vector machines -, -IEEE Transactions on Neural Networks, 13(2002), 415-425. - -

    -"1-against-the rest" is a good method whose performance -is comparable to "1-against-1." We do the latter -simply because its training time is shorter. -

    -[Go Top] -


    - -Q: After doing cross validation, why there is no model file outputted ? -
    -

    -Cross validation is used for selecting good parameters. -After finding them, you want to re-train the whole -data without the -v option. -

    -[Go Top] -


    - -Q: Why my cross-validation results are different from those in the Practical Guide? -
    -

    - -Due to random partitions of -the data, on different systems CV accuracy values -may be different. -

    -[Go Top] -


    - -Q: On some systems CV accuracy is the same in several runs. How could I use different data partitions? In other words, how do I set random seed in LIBSVM? -
    -

    -If you use GNU C library, -the default seed 1 is considered. Thus you always -get the same result of running svm-train -v. -To have different seeds, you can add the following code -in svm-train.c: -

    -#include <time.h>
    -
    -and in the beginning of the subroutine do_cross_validation(), -
    -srand(time(0));
    -
    -Alternatively, if you are not using GNU C library -and would like to use a fixed seed, you can have -
    -srand(1);
    -
    - -

    -For Java, the random number generator -is initialized using the time information. -So results of two CV runs are different. -To fix the seed, after version 3.1 (released -in mid 2011), you can add -

    -svm.rand.setSeed(0);
    -
    -in the main() function of svm_train.java. -

    -[Go Top] -


    - -Q: I would like to solve L2-loss SVM (i.e., error term is quadratic). How should I modify the code ? -
    -

    -It is extremely easy. Taking c-svc for example, to solve -

    -min_w w^Tw/2 + C \sum max(0, 1- (y_i w^Tx_i+b))^2, -

    -only two -places of svm.cpp have to be changed. -First, modify the following line of -solve_c_svc from -

    -	s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
    -		alpha, Cp, Cn, param->eps, si, param->shrinking);
    -
    -to -
    -	s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
    -		alpha, INF, INF, param->eps, si, param->shrinking);
    -
    -Second, in the class of SVC_Q, declare C as -a private variable: -
    -	double C;
    -
    -In the constructor replace -
    -	for(int i=0;i<prob.l;i++)
    -		QD[i]= (Qfloat)(this->*kernel_function)(i,i);
    -
    -with -
    -        this->C = param.C;
    -	for(int i=0;i<prob.l;i++)
    -		QD[i]= (Qfloat)(this->*kernel_function)(i,i)+0.5/C;
    -
    -Then in the subroutine get_Q, after the for loop, add -
    -        if(i >= start && i < len) 
    -		data[i] += 0.5/C;
    -
    - -

    -For one-class svm, the modification is exactly the same. For SVR, you don't need an if statement like the above. Instead, you only need a simple assignment: -

    -	data[real_i] += 0.5/C;
    -
    - - -

    -For large linear L2-loss SVM, please use -LIBLINEAR. -

    -[Go Top] -


    - -Q: How do I choose parameters for one-class svm as training data are in only one class? -
    -

    -You have pre-specified true positive rate in mind and then search for -parameters which achieve similar cross-validation accuracy. -

    -[Go Top] -


    - -Q: Why the code gives NaN (not a number) results? -
    -

    -This rarely happens, but few users reported the problem. -It seems that their -computers for training libsvm have the VPN client -running. The VPN software has some bugs and causes this -problem. Please try to close or disconnect the VPN client. -

    -[Go Top] -


    - -Q: Why on windows sometimes grid.py fails? -
    -

    - -This problem shouldn't happen after version -2.85. If you are using earlier versions, -please download the latest one. - - -

    -[Go Top] -


    - -Q: Why grid.py/easy.py sometimes generates the following warning message? -
    -
    -Warning: empty z range [62.5:62.5], adjusting to [61.875:63.125]
    -Notice: cannot contour non grid data!
    -
    -

    Nothing is wrong and please disregard the -message. It is from gnuplot when drawing -the contour. -

    -[Go Top] -


    - -Q: Why the sign of predicted labels and decision values are sometimes reversed? -
    -

    Nothing is wrong. Very likely you have two labels +1/-1 and the first instance in your data -has -1. -Think about the case of labels +5/+10. Since -SVM needs to use +1/-1, internally -we map +5/+10 to +1/-1 according to which -label appears first. -Hence a positive decision value implies -that we should predict the "internal" +1, -which may not be the +1 in the input file. - -

    -[Go Top] -


    - -Q: I don't know class labels of test data. What should I put in the first column of the test file? -
    -

    Any value is ok. In this situation, what you will use is the output file of svm-predict, which gives predicted class labels. - - -

    -[Go Top] -


    - -Q: How can I use OpenMP to parallelize LIBSVM on a multicore/shared-memory computer? -
    - -

    It is very easy if you are using GCC 4.2 -or after. - -

    In Makefile, add -fopenmp to CFLAGS. - -

    In class SVC_Q of svm.cpp, modify the for loop -of get_Q to: -

    -#pragma omp parallel for private(j) 
    -			for(j=start;j<len;j++)
    -
    -

    In the subroutine svm_predict_values of svm.cpp, add one line to the for loop: -

    -#pragma omp parallel for private(i) 
    -		for(i=0;i<l;i++)
    -			kvalue[i] = Kernel::k_function(x,model->SV[i],model->param);
    -
    -For regression, you need a reduction clause for the variable sum: -
    -#pragma omp parallel for private(i) reduction(+:sum) 
    -		for(i=0;i<model->l;i++)
    -			sum += sv_coef[i] * Kernel::k_function(x,model>SV[i],model>param);
    -
    - -

    Then rebuild the package. Kernel evaluations in training/testing will be parallelized. An example of running this modification on -an 8-core machine using the data set -ijcnn1: - -

    8 cores: -

    -%setenv OMP_NUM_THREADS 8
    -%time svm-train -c 16 -g 4 -m 400 ijcnn1
    -27.1sec
    -
    -1 core: -
    -%setenv OMP_NUM_THREADS 1
    -%time svm-train -c 16 -g 4 -m 400 ijcnn1
    -79.8sec
    -
    -For this data, kernel evaluations take 80% of training time. In the above example, we assume you use csh. For bash, use -
    -export OMP_NUM_THREADS=8
    -
    -instead. - -

    For Python interface, you need to add the -lgomp link option: -

    -$(CXX) -lgomp -shared -dynamiclib svm.o -o libsvm.so.$(SHVER)
    -
    -

    -[Go Top] -


    - -Q: How could I know which training instances are support vectors? -
    - -

    -It's very simple. Please replace -

    -			if(nonzero[i]) model->SV[p++] = x[i];
    -
    -in svm_train() of svm.cpp with -
    -			if(nonzero[i]) 
    -			{
    -				model->SV[p++] = x[i];
    -				info("%d\n", perm[i]);
    -			}
    -
    -If there are many requests, we may -provide a function to return indices -of support vectors. In the mean time, -if you need such information in your code, -you can add the array nonzero to the model -structure. This array has the same size as -the number of data, so alternatively you can -store only indices of support vectors. - -

    If you use matlab interface, you can easily -compare support vectors and training data to know -the indices: -

    -[tmp index]=ismember(model.SVs, training_data,'rows');
    -
    -

    -[Go Top] -


    - -Q: Why training a probability model (i.e., -b 1) takes a longer time? -
    -

    -To construct this probability model, we internally conduct a -cross validation, which is more time consuming than -a regular training. -Hence, in general you do parameter selection first without --b 1. You only use -b 1 when good parameters have been -selected. In other words, you avoid using -b 1 and -v -together. -

    -[Go Top] -


    - -Q: Why using the -b option does not give me better accuracy? -
    -

    -There is absolutely no reason the probability outputs guarantee -you better accuracy. The main purpose of this option is -to provide you the probability estimates, but not to boost -prediction accuracy. From our experience, -after proper parameter selections, in general with -and without -b have similar accuracy. Occasionally there -are some differences. -It is not recommended to compare the two under -just a fixed parameter -set as more differences will be observed. -

    -[Go Top] -


    - -Q: Why using svm-predict -b 0 and -b 1 gives different accuracy values? -
    -

    -Let's just consider two-class classification here. After probability information is obtained in training, -we do not have -

    -prob > = 0.5 if and only if decision value >= 0. -

    -So predictions may be different with -b 0 and 1. -

    -[Go Top] -


    - -Q: How can I save images drawn by svm-toy? -
    -

    -For Microsoft windows, first press the "print screen" key on the keyboard. -Open "Microsoft Paint" -(included in Windows) -and press "ctrl-v." Then you can clip -the part of picture which you want. -For X windows, you can -use the program "xv" or "import" to grab the picture of the svm-toy window. -

    -[Go Top] -


    - -Q: I press the "load" button to load data points but why svm-toy does not draw them ? -
    -

    -The program svm-toy assumes both attributes (i.e. x-axis and y-axis -values) are in (0,1). Hence you want to scale your -data to between a small positive number and -a number less than but very close to 1. -Moreover, class labels must be 1, 2, or 3 -(not 1.0, 2.0 or anything else). -

    -[Go Top] -


    - -Q: I would like svm-toy to handle more than three classes of data, what should I do ? -
    -

    -Taking windows/svm-toy.cpp as an example, you need to -modify it and the difference -from the original file is as the following: (for five classes of -data) -

    -30,32c30
    -< 	RGB(200,0,200),
    -< 	RGB(0,160,0),
    -< 	RGB(160,0,0)
    ----
    -> 	RGB(200,0,200)
    -39c37
    -< HBRUSH brush1, brush2, brush3, brush4, brush5;
    ----
    -> HBRUSH brush1, brush2, brush3;
    -113,114d110
    -< 	brush4 = CreateSolidBrush(colors[7]);
    -< 	brush5 = CreateSolidBrush(colors[8]);
    -155,157c151
    -< 	else if(v==3) return brush3;
    -< 	else if(v==4) return brush4;
    -< 	else return brush5;
    ----
    -> 	else return brush3;
    -325d318
    -< 	  int colornum = 5;
    -327c320
    -< 		svm_node *x_space = new svm_node[colornum * prob.l];
    ----
    -> 		svm_node *x_space = new svm_node[3 * prob.l];
    -333,338c326,331
    -< 			x_space[colornum * i].index = 1;
    -< 			x_space[colornum * i].value = q->x;
    -< 			x_space[colornum * i + 1].index = 2;
    -< 			x_space[colornum * i + 1].value = q->y;
    -< 			x_space[colornum * i + 2].index = -1;
    -< 			prob.x[i] = &x_space[colornum * i];
    ----
    -> 			x_space[3 * i].index = 1;
    -> 			x_space[3 * i].value = q->x;
    -> 			x_space[3 * i + 1].index = 2;
    -> 			x_space[3 * i + 1].value = q->y;
    -> 			x_space[3 * i + 2].index = -1;
    -> 			prob.x[i] = &x_space[3 * i];
    -397c390
    -< 				if(current_value > 5) current_value = 1;
    ----
    -> 				if(current_value > 3) current_value = 1;
    -
    -

    -[Go Top] -


    - -Q: What is the difference between Java version and C++ version of libsvm? -
    -

    -They are the same thing. We just rewrote the C++ code -in Java. -

    -[Go Top] -


    - -Q: Is the Java version significantly slower than the C++ version? -
    -

    -This depends on the VM you used. We have seen good -VM which leads the Java version to be quite competitive with -the C++ code. (though still slower) -

    -[Go Top] -


    - -Q: While training I get the following error message: java.lang.OutOfMemoryError. What is wrong? -
    -

    -You should try to increase the maximum Java heap size. -For example, -

    -java -Xmx2048m -classpath libsvm.jar svm_train ...
    -
    -sets the maximum heap size to 2048M. -

    -[Go Top] -


    - -Q: Why you have the main source file svm.m4 and then transform it to svm.java? -
    -

    -Unlike C, Java does not have a preprocessor built-in. -However, we need some macros (see first 3 lines of svm.m4). - - -

    -[Go Top] -


    - -Q: Except the python-C++ interface provided, could I use Jython to call libsvm ? -
    -

    Yes, here are some examples: - -

    -$ export CLASSPATH=$CLASSPATH:~/libsvm-2.91/java/libsvm.jar
    -$ ./jython
    -Jython 2.1a3 on java1.3.0 (JIT: jitc)
    -Type "copyright", "credits" or "license" for more information.
    ->>> from libsvm import *
    ->>> dir()
    -['__doc__', '__name__', 'svm', 'svm_model', 'svm_node', 'svm_parameter',
    -'svm_problem']
    ->>> x1 = [svm_node(index=1,value=1)]
    ->>> x2 = [svm_node(index=1,value=-1)]
    ->>> param = svm_parameter(svm_type=0,kernel_type=2,gamma=1,cache_size=40,eps=0.001,C=1,nr_weight=0,shrinking=1)
    ->>> prob = svm_problem(l=2,y=[1,-1],x=[x1,x2])
    ->>> model = svm.svm_train(prob,param)
    -*
    -optimization finished, #iter = 1
    -nu = 1.0
    -obj = -1.018315639346838, rho = 0.0
    -nSV = 2, nBSV = 2
    -Total nSV = 2
    ->>> svm.svm_predict(model,x1)
    -1.0
    ->>> svm.svm_predict(model,x2)
    --1.0
    ->>> svm.svm_save_model("test.model",model)
    -
    -
    - -

    -[Go Top] -


    - -Q: I compile the MATLAB interface without problem, but why errors occur while running it? -
    -

    -Your compiler version may not be supported/compatible for MATLAB. -Please check this MATLAB page first and then specify the version -number. For example, if g++ X.Y is supported, replace -

    -CXX = g++
    -
    -in the Makefile with -
    -CXX = g++-X.Y
    -
    -

    -[Go Top] -


    - -Q: On 64bit Windows I compile the MATLAB interface without problem, but why errors occur while running it? -
    -

    - - -Please make sure that you have modified make.m -to use -largeArrayDims option. For example, -

    -mex -largeArrayDims -O -c svm.cpp
    -
    - -Moreover, if you use Microsoft Visual Studio, -probabally it is not properly installed. -See the explanation -here. -

    -[Go Top] -


    - -Q: Does the MATLAB interface provide a function to do scaling? -
    -

    -It is extremely easy to do scaling under MATLAB. -The following one-line code scale each feature to the range -of [0.1]: -

    -(data - repmat(min(data,[],1),size(data,1),1))*spdiags(1./(max(data,[],1)-min(data,[],1))',0,size(data,2),size(data,2))
    -
    -

    -[Go Top] -


    - -Q: How could I use MATLAB interface for parameter selection? -
    -

    -One can do this by a simple loop. -See the following example: -

    -bestcv = 0;
    -for log2c = -1:3,
    -  for log2g = -4:1,
    -    cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
    -    cv = svmtrain(heart_scale_label, heart_scale_inst, cmd);
    -    if (cv >= bestcv),
    -      bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
    -    end
    -    fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
    -  end
    -end
    -
    -You may adjust the parameter range in the above loops. -

    -[Go Top] -


    - -Q: I use MATLAB parallel programming toolbox on a multi-core environment for parameter selection. Why the program is even slower? -
    -

    -Fabrizio Lacalandra of University of Pisa reported this issue. -It seems the problem is caused by the screen output. -If you disable the info function -using

    #if 0,
    then the problem -may be solved. -

    -[Go Top] -


    - -Q: How do I use LIBSVM with OpenMP under MATLAB? -
    -

    -In Makefile, -you need to add -fopenmp to CFLAGS and -lgomp to MEX_OPTION. For Octave, you need the same modification. - -

    However, a minor problem is that -the number of threads cannot -be specified in MATLAB. We tried Version 7.7 (R2008b) and gcc-4.3.3. - -

    -% export OMP_NUM_THREADS=4; matlab
    ->> setenv('OMP_NUM_THREADS', '1');
    -
    - -Then OMP_NUM_THREADS is still 4 while running the program. Please contact us if you -see how to solve this problem. -

    -[Go Top] -


    - -Q: How could I generate the primal variable w of linear SVM? -
    -

    -Let's start from the binary class and -assume you have two labels -1 and +1. -After obtaining the model from calling svmtrain, -do the following to have w and b: -

    -w = model.SVs' * model.sv_coef;
    -b = -model.rho;
    -
    -if model.Label(1) == -1
    -  w = -w;
    -  b = -b;
    -end
    -
    -If you do regression or one-class SVM, then the if statement is not needed. - -

    For multi-class SVM, we illustrate the setting -in the following example of running the iris -data, which have 3 classes -

      
    -> [y, x] = libsvmread('../../htdocs/libsvmtools/datasets/multiclass/iris.scale');
    -> m = svmtrain(y, x, '-t 0')
    -
    -m = 
    -
    -    Parameters: [5x1 double]
    -      nr_class: 3
    -       totalSV: 42
    -           rho: [3x1 double]
    -         Label: [3x1 double]
    -         ProbA: []
    -         ProbB: []
    -           nSV: [3x1 double]
    -       sv_coef: [42x2 double]
    -           SVs: [42x4 double]
    -
    -sv_coef is like: -
    -+-+-+--------------------+
    -|1|1|                    |
    -|v|v|  SVs from class 1  |
    -|2|3|                    |
    -+-+-+--------------------+
    -|1|2|                    |
    -|v|v|  SVs from class 2  |
    -|2|3|                    |
    -+-+-+--------------------+
    -|1|2|                    |
    -|v|v|  SVs from class 3  |
    -|3|3|                    |
    -+-+-+--------------------+
    -
    -so we need to see nSV of each classes. -
      
    -> m.nSV
    -
    -ans =
    -
    -     3
    -    21
    -    18
    -
    -Suppose the goal is to find the vector w of classes -1 vs 3. Then -y_i alpha_i of training 1 vs 3 are -
      
    -> coef = [m.sv_coef(1:3,2); m.sv_coef(25:42,1)];
    -
    -and SVs are: -
      
    -> SVs = [m.SVs(1:3,:); m.SVs(25:42,:)];
    -
    -Hence, w is -
    -> w = SVs'*coef;
    -
    -For rho, -
    -> m.rho
    -
    -ans =
    -
    -    1.1465
    -    0.3682
    -   -1.9969
    -> b = -m.rho(2);
    -
    -because rho is arranged by 1vs2 1vs3 2vs3. - - - -

    -[Go Top] -


    - -Q: Is there an OCTAVE interface for libsvm? -
    -

    -Yes, after libsvm 2.86, the matlab interface -works on OCTAVE as well. Please type -

    -make octave
    -
    -for installation. -

    -[Go Top] -


    - -Q: How to handle the name conflict between svmtrain in the libsvm matlab interface and that in MATLAB bioinformatics toolbox? -
    -

    -The easiest way is to rename the svmtrain binary -file (e.g., svmtrain.mexw32 on 32-bit windows) -to a different -name (e.g., svmtrain2.mexw32). -

    -[Go Top] -


    -

    -LIBSVM home page -

    - - + + +LIBSVM FAQ + + + +

    LIBSVM FAQ

    +last modified : +Thu, 1 Mar 2012 14:45:34 GMT + +
  • All Questions(77)
  • + + + + + + +
    +

    + + +Q: Some courses which have used libsvm as a tool +
    +

    +

    +[Go Top] +


    + +Q: Some applications/tools which have used libsvm +
    +(and maybe liblinear). + +

    +[Go Top] +


    + +Q: Where can I find documents/videos of libsvm ? +
    +

    + +

      +
    • +Official implementation document: +
      +C.-C. Chang and +C.-J. Lin. +LIBSVM +: a library for support vector machines. +ACM Transactions on Intelligent +Systems and Technology, 2:27:1--27:27, 2011. +pdf, ps.gz, +ACM digital lib. + + +
    • Instructions for using LIBSVM are in the README files in the main directory and some sub-directories. +
      +README in the main directory: details all options, data format, and library calls. +
      +tools/README: parameter selection and other tools +
    • +A guide for beginners: +
      +C.-W. Hsu, C.-C. Chang, and +C.-J. Lin. + +A practical guide to support vector classification + +
    • An introductory video +for windows users. + +
    +

    +[Go Top] +


    + +Q: Where are change log and earlier versions? +
    +

    See the change log. + +

    You can download earlier versions +here. +

    +[Go Top] +


    + +Q: How to cite LIBSVM? +
    +

    +Please cite the following paper: +

    +Chih-Chung Chang and Chih-Jen Lin, LIBSVM +: a library for support vector machines. +ACM Transactions on Intelligent Systems and Technology, 2:27:1--27:27, 2011. +Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm +

    +The bibtex format is +

    +@article{CC01a,
    + author = {Chang, Chih-Chung and Lin, Chih-Jen},
    + title = {{LIBSVM}: A library for support vector machines},
    + journal = {ACM Transactions on Intelligent Systems and Technology},
    + volume = {2},
    + issue = {3},
    + year = {2011},
    + pages = {27:1--27:27},
    + note =	 {Software available at \url{http://www.csie.ntu.edu.tw/~cjlin/libsvm}}
    +}
    +
    +

    +[Go Top] +


    + +Q: I would like to use libsvm in my software. Is there any license problem? +
    +

    +The libsvm license ("the modified BSD license") +is compatible with many +free software licenses such as GPL. Hence, it is very easy to +use libsvm in your software. +Please check the COPYRIGHT file in detail. Basically +you need to +

      +
    1. +Clearly indicate that LIBSVM is used. +
    2. +
    3. +Retain the LIBSVM COPYRIGHT file in your software. +
    4. +
    +It can also be used in commercial products. +

    +[Go Top] +


    + +Q: Is there a repository of additional tools based on libsvm? +
    +

    +Yes, see libsvm +tools +

    +[Go Top] +


    + +Q: On unix machines, I got "error in loading shared libraries" or "cannot open shared object file." What happened ? +
    + +

    +This usually happens if you compile the code +on one machine and run it on another which has incompatible +libraries. +Try to recompile the program on that machine or use static linking. +

    +[Go Top] +


    + +Q: I have modified the source and would like to build the graphic interface "svm-toy" on MS windows. How should I do it ? +
    + +

    +Build it as a project by choosing "Win32 Project." +On the other hand, for "svm-train" and "svm-predict" +you want to choose "Win32 Console Project." +After libsvm 2.5, you can also use the file Makefile.win. +See details in README. + + +

    +If you are not using Makefile.win and see the following +link error +

    +LIBCMTD.lib(wwincrt0.obj) : error LNK2001: unresolved external symbol
    +_wWinMain@16
    +
    +you may have selected a wrong project type. +

    +[Go Top] +


    + +Q: I am an MS windows user but why only one (svm-toy) of those precompiled .exe actually runs ? +
    + +

    +You need to open a command window +and type svmtrain.exe to see all options. +Some examples are in README file. +

    +[Go Top] +


    + +Q: What is the difference between "." and "*" outputed during training? +
    + +

    +"." means every 1,000 iterations (or every #data +iterations is your #data is less than 1,000). +"*" means that after iterations of using +a smaller shrunk problem, +we reset to use the whole set. See the +implementation document for details. +

    +[Go Top] +


    + +Q: Why occasionally the program (including MATLAB or other interfaces) crashes and gives a segmentation fault? +
    + +

    +Very likely the program consumes too much memory than what the +operating system can provide. Try a smaller data and see if the +program still crashes. +

    +[Go Top] +


    + +Q: How to build a dynamic library (.dll file) on MS windows? +
    +

    + +The easiest way is to use Makefile.win. +See details in README. + +Alternatively, you can use Visual C++. Here is +the example using Visual Studio .Net 2008: +

      +
    1. Create a Win32 empty DLL project and set (in Project->$Project_Name +Properties...->Configuration) to "Release." + About how to create a new dynamic link library, please refer to +http://msdn2.microsoft.com/en-us/library/ms235636(VS.80).aspx + +
    2. Add svm.cpp, svm.h to your project. +
    3. Add __WIN32__ and _CRT_SECURE_NO_DEPRECATE to Preprocessor definitions (in +Project->$Project_Name Properties...->C/C++->Preprocessor) +
    4. Set Create/Use Precompiled Header to Not Using Precompiled Headers +(in Project->$Project_Name Properties...->C/C++->Precompiled Headers) +
    5. Set the path for the Modulation Definition File svm.def (in +Project->$Project_Name Properties...->Linker->input +
    6. Build the DLL. +
    7. Rename the dll file to libsvm.dll and move it to the correct path. +
    + + +

    +[Go Top] +


    + +Q: On some systems (e.g., Ubuntu), compiling LIBSVM gives many warning messages. Is this a problem and how to disable the warning message? +
    + +

    +The warning message is like +

    +svm.cpp:2730: warning: ignoring return value of int fscanf(FILE*, const char*, ...), declared with attribute warn_unused_result
    +
    +This is not a problem; see for more +details of ubuntu systems. +In the future we may modify the code +so that these messages do not appear. +At this moment, to disable the warning message you can replace +
    +CFLAGS = -Wall -Wconversion -O3 -fPIC
    +
    +with +
    +CFLAGS = -Wall -Wconversion -O3 -fPIC -U_FORTIFY_SOURCE
    +
    +in Makefile. +

    +[Go Top] +


    + +Q: In LIBSVM, why you don't use certain C/C++ library functions to make the code shorter? +
    + +

    +For portability, we use only features defined in ISO C89. Note that features in ISO C99 may not be available everywhere. +Even the newest gcc lacks some features in C99 (see http://gcc.gnu.org/c99status.html for details). +If the situation changes in the future, +we might consider using these newer features. +

    +[Go Top] +


    + +Q: Why sometimes not all attributes of a data appear in the training/model files ? +
    +

    +libsvm uses the so called "sparse" format where zero +values do not need to be stored. Hence a data with attributes +

    +1 0 2 0
    +
    +is represented as +
    +1:1 3:2
    +
    +

    +[Go Top] +


    + +Q: What if my data are non-numerical ? +
    +

    +Currently libsvm supports only numerical data. +You may have to change non-numerical data to +numerical. For example, you can use several +binary attributes to represent a categorical +attribute. +

    +[Go Top] +


    + +Q: Why do you consider sparse format ? Will the training of dense data be much slower ? +
    +

    +This is a controversial issue. The kernel +evaluation (i.e. inner product) of sparse vectors is slower +so the total training time can be at least twice or three times +of that using the dense format. +However, we cannot support only dense format as then we CANNOT +handle extremely sparse cases. Simplicity of the code is another +concern. Right now we decide to support +the sparse format only. +

    +[Go Top] +


    + +Q: Why sometimes the last line of my data is not read by svm-train? +
    + +

    +We assume that you have '\n' in the end of +each line. So please press enter in the end +of your last line. +

    +[Go Top] +


    + +Q: Is there a program to check if my data are in the correct format? +
    + +

    +The svm-train program in libsvm conducts only a simple check of the input data. To do a +detailed check, after libsvm 2.85, you can use the python script tools/checkdata.py. See tools/README for details. +

    +[Go Top] +


    + +Q: May I put comments in data files? +
    + +

    +We don't officially support this. But, cureently LIBSVM +is able to process data in the following +format: +

    +1 1:2 2:1 # your comments
    +
    +Note that the character ":" should not appear in your +comments. + +

    +[Go Top] +


    + +Q: How to convert other data formats to LIBSVM format? +
    + +

    +It depends on your data format. A simple way is to use +libsvmwrite in the libsvm matlab/octave interface. + +Take a CSV (comma-separated values) file +in UCI machine learning repository as an example. +We download SPECTF.train. +Labels are in the first column. The following steps produce +a file in the libsvm format. +

    +matlab> SPECTF = csvread('SPECTF.train'); % read a csv file
    +matlab> labels = SPECTF(:, 1); % labels from the 1st column
    +matlab> features = SPECTF(:, 2:end); 
    +matlab> features_sparse = sparse(features); % features must be in a sparse matrix
    +matlab> libsvmwrite('SPECTFlibsvm.train', labels, features_sparse);
    +
    +The tranformed data are stored in SPECTFlibsvm.train. + +

    +Alternatively, you can use convert.c +to convert CSV format to libsvm format. +

    +[Go Top] +


    + +Q: The output of training C-SVM is like the following. What do they mean? +
    +
    optimization finished, #iter = 219 +
    nu = 0.431030 +
    obj = -100.877286, rho = 0.424632 +
    nSV = 132, nBSV = 107 +
    Total nSV = 132 +

    +obj is the optimal objective value of the dual SVM problem. +rho is the bias term in the decision function +sgn(w^Tx - rho). +nSV and nBSV are number of support vectors and bounded support +vectors (i.e., alpha_i = C). nu-svm is a somewhat equivalent +form of C-SVM where C is replaced by nu. nu simply shows the +corresponding parameter. More details are in + +libsvm document. +

    +[Go Top] +


    + +Q: Can you explain more about the model file? +
    + +

    +In the model file, after parameters and other informations such as labels , each line represents a support vector. +Support vectors are listed in the order of "labels" shown earlier. +(i.e., those from the first class in the "labels" list are +grouped first, and so on.) +If k is the total number of classes, +in front of a support vector in class j, there are +k-1 coefficients +y*alpha where alpha are dual solution of the +following two class problems: +
    +1 vs j, 2 vs j, ..., j-1 vs j, j vs j+1, j vs j+2, ..., j vs k +
    +and y=1 in first j-1 coefficients, y=-1 in the remaining +k-j coefficients. + +For example, if there are 4 classes, the file looks like: + +

    ++-+-+-+--------------------+
    +|1|1|1|                    |
    +|v|v|v|  SVs from class 1  |
    +|2|3|4|                    |
    ++-+-+-+--------------------+
    +|1|2|2|                    |
    +|v|v|v|  SVs from class 2  |
    +|2|3|4|                    |
    ++-+-+-+--------------------+
    +|1|2|3|                    |
    +|v|v|v|  SVs from class 3  |
    +|3|3|4|                    |
    ++-+-+-+--------------------+
    +|1|2|3|                    |
    +|v|v|v|  SVs from class 4  |
    +|4|4|4|                    |
    ++-+-+-+--------------------+
    +
    +See also + an illustration using +MATLAB/OCTAVE. +

    +[Go Top] +


    + +Q: Should I use float or double to store numbers in the cache ? +
    + +

    +We have float as the default as you can store more numbers +in the cache. +In general this is good enough but for few difficult +cases (e.g. C very very large) where solutions are huge +numbers, it might be possible that the numerical precision is not +enough using only float. +

    +[Go Top] +


    + +Q: How do I choose the kernel? +
    + +

    +In general we suggest you to try the RBF kernel first. +A recent result by Keerthi and Lin +( +download paper here) +shows that if RBF is used with model selection, +then there is no need to consider the linear kernel. +The kernel matrix using sigmoid may not be positive definite +and in general it's accuracy is not better than RBF. +(see the paper by Lin and Lin +( +download paper here). +Polynomial kernels are ok but if a high degree is used, +numerical difficulties tend to happen +(thinking about dth power of (<1) goes to 0 +and (>1) goes to infinity). +

    +[Go Top] +


    + +Q: Does libsvm have special treatments for linear SVM? +
    + +

    + +No, libsvm solves linear/nonlinear SVMs by the +same way. +Some tricks may save training/testing time if the +linear kernel is used, +so libsvm is NOT particularly efficient for linear SVM, +especially when +C is large and +the number of data is much larger +than the number of attributes. +You can either +

    + +

    Please also see our SVM guide +on the discussion of using RBF and linear +kernels. +

    +[Go Top] +


    + +Q: The number of free support vectors is large. What should I do? +
    +

    +This usually happens when the data are overfitted. +If attributes of your data are in large ranges, +try to scale them. Then the region +of appropriate parameters may be larger. +Note that there is a scale program +in libsvm. +

    +[Go Top] +


    + +Q: Should I scale training and testing data in a similar way? +
    +

    +Yes, you can do the following: +

    +> svm-scale -s scaling_parameters train_data > scaled_train_data
    +> svm-scale -r scaling_parameters test_data > scaled_test_data
    +
    +

    +[Go Top] +


    + +Q: Does it make a big difference if I scale each attribute to [0,1] instead of [-1,1]? +
    + +

    +For the linear scaling method, if the RBF kernel is +used and parameter selection is conducted, there +is no difference. Assume Mi and mi are +respectively the maximal and minimal values of the +ith attribute. Scaling to [0,1] means +

    +                x'=(x-mi)/(Mi-mi)
    +
    +For [-1,1], +
    +                x''=2(x-mi)/(Mi-mi)-1.
    +
    +In the RBF kernel, +
    +                x'-y'=(x-y)/(Mi-mi), x''-y''=2(x-y)/(Mi-mi).
    +
    +Hence, using (C,g) on the [0,1]-scaled data is the +same as (C,g/2) on the [-1,1]-scaled data. + +

    Though the performance is the same, the computational +time may be different. For data with many zero entries, +[0,1]-scaling keeps the sparsity of input data and hence +may save the time. +

    +[Go Top] +


    + +Q: The prediction rate is low. How could I improve it? +
    +

    +Try to use the model selection tool grid.py in the python +directory find +out good parameters. To see the importance of model selection, +please +see my talk: + +A practical guide to support vector +classification + +

    +[Go Top] +


    + +Q: My data are unbalanced. Could libsvm handle such problems? +
    +

    +Yes, there is a -wi options. For example, if you use +

    +> svm-train -s 0 -c 10 -w1 1 -w-1 5 data_file
    +
    +

    +the penalty for class "-1" is larger. +Note that this -w option is for C-SVC only. +

    +[Go Top] +


    + +Q: What is the difference between nu-SVC and C-SVC? +
    +

    +Basically they are the same thing but with different +parameters. The range of C is from zero to infinity +but nu is always between [0,1]. A nice property +of nu is that it is related to the ratio of +support vectors and the ratio of the training +error. +

    +[Go Top] +


    + +Q: The program keeps running (without showing any output). What should I do? +
    +

    +You may want to check your data. Each training/testing +data must be in one line. It cannot be separated. +In addition, you have to remove empty lines. +

    +[Go Top] +


    + +Q: The program keeps running (with output, i.e. many dots). What should I do? +
    +

    +In theory libsvm guarantees to converge. +Therefore, this means you are +handling ill-conditioned situations +(e.g. too large/small parameters) so numerical +difficulties occur. +

    +You may get better numerical stability by replacing +

    +typedef float Qfloat;
    +
    +in svm.cpp with +
    +typedef double Qfloat;
    +
    +That is, elements in the kernel cache are stored +in double instead of single. However, this means fewer elements +can be put in the kernel cache. +

    +[Go Top] +


    + +Q: The training time is too long. What should I do? +
    +

    +For large problems, please specify enough cache size (i.e., +-m). +Slow convergence may happen for some difficult cases (e.g. -c is large). +You can try to use a looser stopping tolerance with -e. +If that still doesn't work, you may train only a subset of the data. +You can use the program subset.py in the directory "tools" +to obtain a random subset. + +

    +If you have extremely large data and face this difficulty, please +contact us. We will be happy to discuss possible solutions. + +

    When using large -e, you may want to check if -h 0 (no shrinking) or -h 1 (shrinking) is faster. +See a related question below. + +

    +[Go Top] +


    + +Q: Does shrinking always help? +
    +

    +If the number of iterations is high, then shrinking +often helps. +However, if the number of iterations is small +(e.g., you specify a large -e), then +probably using -h 0 (no shrinking) is better. +See the +implementation document for details. +

    +[Go Top] +


    + +Q: How do I get the decision value(s)? +
    +

    +We print out decision values for regression. For classification, +we solve several binary SVMs for multi-class cases. You +can obtain values by easily calling the subroutine +svm_predict_values. Their corresponding labels +can be obtained from svm_get_labels. +Details are in +README of libsvm package. + +

    +If you are using MATLAB/OCTAVE interface, svmpredict can directly +give you decision values. Please see matlab/README for details. + +

    +We do not recommend the following. But if you would +like to get values for +TWO-class classification with labels +1 and -1 +(note: +1 and -1 but not things like 5 and 10) +in the easiest way, simply add +

    +		printf("%f\n", dec_values[0]*model->label[0]);
    +
    +after the line +
    +		svm_predict_values(model, x, dec_values);
    +
    +of the file svm.cpp. +Positive (negative) +decision values correspond to data predicted as +1 (-1). + + +

    +[Go Top] +


    + +Q: How do I get the distance between a point and the hyperplane? +
    +

    +The distance is |decision_value| / |w|. +We have |w|^2 = w^Tw = alpha^T Q alpha = 2*(dual_obj + sum alpha_i). +Thus in svm.cpp please find the place +where we calculate the dual objective value +(i.e., the subroutine Solve()) +and add a statement to print w^Tw. + +

    +[Go Top] +


    + +Q: On 32-bit machines, if I use a large cache (i.e. large -m) on a linux machine, why sometimes I get "segmentation fault ?" +
    +

    + +On 32-bit machines, the maximum addressable +memory is 4GB. The Linux kernel uses 3:1 +split which means user space is 3G and +kernel space is 1G. Although there are +3G user space, the maximum dynamic allocation +memory is 2G. So, if you specify -m near 2G, +the memory will be exhausted. And svm-train +will fail when it asks more memory. +For more details, please read + +this article. +

    +The easiest solution is to switch to a + 64-bit machine. +Otherwise, there are two ways to solve this. If your +machine supports Intel's PAE (Physical Address +Extension), you can turn on the option HIGHMEM64G +in Linux kernel which uses 4G:4G split for +kernel and user space. If you don't, you can +try a software `tub' which can eliminate the 2G +boundary for dynamic allocated memory. The `tub' +is available at +http://www.bitwagon.com/tub.html. + + + +

    +[Go Top] +


    + +Q: How do I disable screen output of svm-train? +
    +

    +For commend-line users, use the -q option: +

    +> ./svm-train -q heart_scale
    +
    +

    +For library users, set the global variable +

    +extern void (*svm_print_string) (const char *);
    +
    +to specify the output format. You can disable the output by the following steps: +
      +
    1. +Declare a function to output nothing: +
      +void print_null(const char *s) {}
      +
      +
    2. +
    3. +Assign the output function of libsvm by +
      +svm_print_string = &print_null;
      +
      +
    4. +
    +Finally, a way used in earlier libsvm +is by updating svm.cpp from +
    +#if 1
    +void info(const char *fmt,...)
    +
    +to +
    +#if 0
    +void info(const char *fmt,...)
    +
    +

    +[Go Top] +


    + +Q: I would like to use my own kernel. Any example? In svm.cpp, there are two subroutines for kernel evaluations: k_function() and kernel_function(). Which one should I modify ? +
    +

    +An example is "LIBSVM for string data" in LIBSVM Tools. +

    +The reason why we have two functions is as follows. +For the RBF kernel exp(-g |xi - xj|^2), if we calculate +xi - xj first and then the norm square, there are 3n operations. +Thus we consider exp(-g (|xi|^2 - 2dot(xi,xj) +|xj|^2)) +and by calculating all |xi|^2 in the beginning, +the number of operations is reduced to 2n. +This is for the training. For prediction we cannot +do this so a regular subroutine using that 3n operations is +needed. + +The easiest way to have your own kernel is +to put the same code in these two +subroutines by replacing any kernel. +

    +[Go Top] +


    + +Q: What method does libsvm use for multi-class SVM ? Why don't you use the "1-against-the rest" method ? +
    +

    +It is one-against-one. We chose it after doing the following +comparison: +C.-W. Hsu and C.-J. Lin. + +A comparison of methods +for multi-class support vector machines +, +IEEE Transactions on Neural Networks, 13(2002), 415-425. + +

    +"1-against-the rest" is a good method whose performance +is comparable to "1-against-1." We do the latter +simply because its training time is shorter. +

    +[Go Top] +


    + +Q: After doing cross validation, why there is no model file outputted ? +
    +

    +Cross validation is used for selecting good parameters. +After finding them, you want to re-train the whole +data without the -v option. +

    +[Go Top] +


    + +Q: Why my cross-validation results are different from those in the Practical Guide? +
    +

    + +Due to random partitions of +the data, on different systems CV accuracy values +may be different. +

    +[Go Top] +


    + +Q: On some systems CV accuracy is the same in several runs. How could I use different data partitions? In other words, how do I set random seed in LIBSVM? +
    +

    +If you use GNU C library, +the default seed 1 is considered. Thus you always +get the same result of running svm-train -v. +To have different seeds, you can add the following code +in svm-train.c: +

    +#include <time.h>
    +
    +and in the beginning of main(), +
    +srand(time(0));
    +
    +Alternatively, if you are not using GNU C library +and would like to use a fixed seed, you can have +
    +srand(1);
    +
    + +

    +For Java, the random number generator +is initialized using the time information. +So results of two CV runs are different. +To fix the seed, after version 3.1 (released +in mid 2011), you can add +

    +svm.rand.setSeed(0);
    +
    +in the main() function of svm_train.java. +

    +[Go Top] +


    + +Q: I would like to solve L2-loss SVM (i.e., error term is quadratic). How should I modify the code ? +
    +

    +It is extremely easy. Taking c-svc for example, to solve +

    +min_w w^Tw/2 + C \sum max(0, 1- (y_i w^Tx_i+b))^2, +

    +only two +places of svm.cpp have to be changed. +First, modify the following line of +solve_c_svc from +

    +	s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
    +		alpha, Cp, Cn, param->eps, si, param->shrinking);
    +
    +to +
    +	s.Solve(l, SVC_Q(*prob,*param,y), minus_ones, y,
    +		alpha, INF, INF, param->eps, si, param->shrinking);
    +
    +Second, in the class of SVC_Q, declare C as +a private variable: +
    +	double C;
    +
    +In the constructor replace +
    +	for(int i=0;i<prob.l;i++)
    +		QD[i]= (Qfloat)(this->*kernel_function)(i,i);
    +
    +with +
    +        this->C = param.C;
    +	for(int i=0;i<prob.l;i++)
    +		QD[i]= (Qfloat)(this->*kernel_function)(i,i)+0.5/C;
    +
    +Then in the subroutine get_Q, after the for loop, add +
    +        if(i >= start && i < len) 
    +		data[i] += 0.5/C;
    +
    + +

    +For one-class svm, the modification is exactly the same. For SVR, you don't need an if statement like the above. Instead, you only need a simple assignment: +

    +	data[real_i] += 0.5/C;
    +
    + + +

    +For large linear L2-loss SVM, please use +LIBLINEAR. +

    +[Go Top] +


    + +Q: How do I choose parameters for one-class svm as training data are in only one class? +
    +

    +You have pre-specified true positive rate in mind and then search for +parameters which achieve similar cross-validation accuracy. +

    +[Go Top] +


    + +Q: Why the code gives NaN (not a number) results? +
    +

    +This rarely happens, but few users reported the problem. +It seems that their +computers for training libsvm have the VPN client +running. The VPN software has some bugs and causes this +problem. Please try to close or disconnect the VPN client. +

    +[Go Top] +


    + +Q: Why on windows sometimes grid.py fails? +
    +

    + +This problem shouldn't happen after version +2.85. If you are using earlier versions, +please download the latest one. + + +

    +[Go Top] +


    + +Q: Why grid.py/easy.py sometimes generates the following warning message? +
    +
    +Warning: empty z range [62.5:62.5], adjusting to [61.875:63.125]
    +Notice: cannot contour non grid data!
    +
    +

    Nothing is wrong and please disregard the +message. It is from gnuplot when drawing +the contour. +

    +[Go Top] +


    + +Q: Why the sign of predicted labels and decision values are sometimes reversed? +
    +

    Nothing is wrong. Very likely you have two labels +1/-1 and the first instance in your data +has -1. +Think about the case of labels +5/+10. Since +SVM needs to use +1/-1, internally +we map +5/+10 to +1/-1 according to which +label appears first. +Hence a positive decision value implies +that we should predict the "internal" +1, +which may not be the +1 in the input file. + +

    +[Go Top] +


    + +Q: I don't know class labels of test data. What should I put in the first column of the test file? +
    +

    Any value is ok. In this situation, what you will use is the output file of svm-predict, which gives predicted class labels. + + +

    +[Go Top] +


    + +Q: How can I use OpenMP to parallelize LIBSVM on a multicore/shared-memory computer? +
    + +

    It is very easy if you are using GCC 4.2 +or after. + +

    In Makefile, add -fopenmp to CFLAGS. + +

    In class SVC_Q of svm.cpp, modify the for loop +of get_Q to: +

    +#pragma omp parallel for private(j) 
    +			for(j=start;j<len;j++)
    +
    +

    In the subroutine svm_predict_values of svm.cpp, add one line to the for loop: +

    +#pragma omp parallel for private(i) 
    +		for(i=0;i<l;i++)
    +			kvalue[i] = Kernel::k_function(x,model->SV[i],model->param);
    +
    +For regression, you need to modify +class SVR_Q instead. The loop in svm_predict_values +is also different because you need +a reduction clause for the variable sum: +
    +#pragma omp parallel for private(i) reduction(+:sum) 
    +		for(i=0;i<model->l;i++)
    +			sum += sv_coef[i] * Kernel::k_function(x,model->SV[i],model->param);
    +
    + +

    Then rebuild the package. Kernel evaluations in training/testing will be parallelized. An example of running this modification on +an 8-core machine using the data set +ijcnn1: + +

    8 cores: +

    +%setenv OMP_NUM_THREADS 8
    +%time svm-train -c 16 -g 4 -m 400 ijcnn1
    +27.1sec
    +
    +1 core: +
    +%setenv OMP_NUM_THREADS 1
    +%time svm-train -c 16 -g 4 -m 400 ijcnn1
    +79.8sec
    +
    +For this data, kernel evaluations take 80% of training time. In the above example, we assume you use csh. For bash, use +
    +export OMP_NUM_THREADS=8
    +
    +instead. + +

    For Python interface, you need to add the -lgomp link option: +

    +$(CXX) -lgomp -shared -dynamiclib svm.o -o libsvm.so.$(SHVER)
    +
    + +

    For MS Windows, you need to add /openmp in CFLAGS of Makefile.win + +

    +[Go Top] +


    + +Q: How could I know which training instances are support vectors? +
    + +

    +It's very simple. Please replace +

    +			if(nonzero[i]) model->SV[p++] = x[i];
    +
    +in svm_train() of svm.cpp with +
    +			if(nonzero[i]) 
    +			{
    +				model->SV[p++] = x[i];
    +				info("%d\n", perm[i]);
    +			}
    +
    +If there are many requests, we may +provide a function to return indices +of support vectors. In the mean time, +if you need such information in your code, +you can add the array nonzero to the model +structure. This array has the same size as +the number of data, so alternatively you can +store only indices of support vectors. + +

    If you use matlab interface, you can easily +compare support vectors and training data to know +the indices: +

    +[tmp index]=ismember(model.SVs, training_data,'rows');
    +
    +

    +[Go Top] +


    + +Q: Why training a probability model (i.e., -b 1) takes a longer time? +
    +

    +To construct this probability model, we internally conduct a +cross validation, which is more time consuming than +a regular training. +Hence, in general you do parameter selection first without +-b 1. You only use -b 1 when good parameters have been +selected. In other words, you avoid using -b 1 and -v +together. +

    +[Go Top] +


    + +Q: Why using the -b option does not give me better accuracy? +
    +

    +There is absolutely no reason the probability outputs guarantee +you better accuracy. The main purpose of this option is +to provide you the probability estimates, but not to boost +prediction accuracy. From our experience, +after proper parameter selections, in general with +and without -b have similar accuracy. Occasionally there +are some differences. +It is not recommended to compare the two under +just a fixed parameter +set as more differences will be observed. +

    +[Go Top] +


    + +Q: Why using svm-predict -b 0 and -b 1 gives different accuracy values? +
    +

    +Let's just consider two-class classification here. After probability information is obtained in training, +we do not have +

    +prob > = 0.5 if and only if decision value >= 0. +

    +So predictions may be different with -b 0 and 1. +

    +[Go Top] +


    + +Q: How can I save images drawn by svm-toy? +
    +

    +For Microsoft windows, first press the "print screen" key on the keyboard. +Open "Microsoft Paint" +(included in Windows) +and press "ctrl-v." Then you can clip +the part of picture which you want. +For X windows, you can +use the program "xv" or "import" to grab the picture of the svm-toy window. +

    +[Go Top] +


    + +Q: I press the "load" button to load data points but why svm-toy does not draw them ? +
    +

    +The program svm-toy assumes both attributes (i.e. x-axis and y-axis +values) are in (0,1). Hence you want to scale your +data to between a small positive number and +a number less than but very close to 1. +Moreover, class labels must be 1, 2, or 3 +(not 1.0, 2.0 or anything else). +

    +[Go Top] +


    + +Q: I would like svm-toy to handle more than three classes of data, what should I do ? +
    +

    +Taking windows/svm-toy.cpp as an example, you need to +modify it and the difference +from the original file is as the following: (for five classes of +data) +

    +30,32c30
    +< 	RGB(200,0,200),
    +< 	RGB(0,160,0),
    +< 	RGB(160,0,0)
    +---
    +> 	RGB(200,0,200)
    +39c37
    +< HBRUSH brush1, brush2, brush3, brush4, brush5;
    +---
    +> HBRUSH brush1, brush2, brush3;
    +113,114d110
    +< 	brush4 = CreateSolidBrush(colors[7]);
    +< 	brush5 = CreateSolidBrush(colors[8]);
    +155,157c151
    +< 	else if(v==3) return brush3;
    +< 	else if(v==4) return brush4;
    +< 	else return brush5;
    +---
    +> 	else return brush3;
    +325d318
    +< 	  int colornum = 5;
    +327c320
    +< 		svm_node *x_space = new svm_node[colornum * prob.l];
    +---
    +> 		svm_node *x_space = new svm_node[3 * prob.l];
    +333,338c326,331
    +< 			x_space[colornum * i].index = 1;
    +< 			x_space[colornum * i].value = q->x;
    +< 			x_space[colornum * i + 1].index = 2;
    +< 			x_space[colornum * i + 1].value = q->y;
    +< 			x_space[colornum * i + 2].index = -1;
    +< 			prob.x[i] = &x_space[colornum * i];
    +---
    +> 			x_space[3 * i].index = 1;
    +> 			x_space[3 * i].value = q->x;
    +> 			x_space[3 * i + 1].index = 2;
    +> 			x_space[3 * i + 1].value = q->y;
    +> 			x_space[3 * i + 2].index = -1;
    +> 			prob.x[i] = &x_space[3 * i];
    +397c390
    +< 				if(current_value > 5) current_value = 1;
    +---
    +> 				if(current_value > 3) current_value = 1;
    +
    +

    +[Go Top] +


    + +Q: What is the difference between Java version and C++ version of libsvm? +
    +

    +They are the same thing. We just rewrote the C++ code +in Java. +

    +[Go Top] +


    + +Q: Is the Java version significantly slower than the C++ version? +
    +

    +This depends on the VM you used. We have seen good +VM which leads the Java version to be quite competitive with +the C++ code. (though still slower) +

    +[Go Top] +


    + +Q: While training I get the following error message: java.lang.OutOfMemoryError. What is wrong? +
    +

    +You should try to increase the maximum Java heap size. +For example, +

    +java -Xmx2048m -classpath libsvm.jar svm_train ...
    +
    +sets the maximum heap size to 2048M. +

    +[Go Top] +


    + +Q: Why you have the main source file svm.m4 and then transform it to svm.java? +
    +

    +Unlike C, Java does not have a preprocessor built-in. +However, we need some macros (see first 3 lines of svm.m4). + + +

    +[Go Top] +


    + +Q: Except the python-C++ interface provided, could I use Jython to call libsvm ? +
    +

    Yes, here are some examples: + +

    +$ export CLASSPATH=$CLASSPATH:~/libsvm-2.91/java/libsvm.jar
    +$ ./jython
    +Jython 2.1a3 on java1.3.0 (JIT: jitc)
    +Type "copyright", "credits" or "license" for more information.
    +>>> from libsvm import *
    +>>> dir()
    +['__doc__', '__name__', 'svm', 'svm_model', 'svm_node', 'svm_parameter',
    +'svm_problem']
    +>>> x1 = [svm_node(index=1,value=1)]
    +>>> x2 = [svm_node(index=1,value=-1)]
    +>>> param = svm_parameter(svm_type=0,kernel_type=2,gamma=1,cache_size=40,eps=0.001,C=1,nr_weight=0,shrinking=1)
    +>>> prob = svm_problem(l=2,y=[1,-1],x=[x1,x2])
    +>>> model = svm.svm_train(prob,param)
    +*
    +optimization finished, #iter = 1
    +nu = 1.0
    +obj = -1.018315639346838, rho = 0.0
    +nSV = 2, nBSV = 2
    +Total nSV = 2
    +>>> svm.svm_predict(model,x1)
    +1.0
    +>>> svm.svm_predict(model,x2)
    +-1.0
    +>>> svm.svm_save_model("test.model",model)
    +
    +
    + +

    +[Go Top] +


    + +Q: I compile the MATLAB interface without problem, but why errors occur while running it? +
    +

    +Your compiler version may not be supported/compatible for MATLAB. +Please check this MATLAB page first and then specify the version +number. For example, if g++ X.Y is supported, replace +

    +CXX = g++
    +
    +in the Makefile with +
    +CXX = g++-X.Y
    +
    +

    +[Go Top] +


    + +Q: On 64bit Windows I compile the MATLAB interface without problem, but why errors occur while running it? +
    +

    + + +Please make sure that you use +the -largeArrayDims option in make.m. For example, +

    +mex -largeArrayDims -O -c svm.cpp
    +
    + +Moreover, if you use Microsoft Visual Studio, +probabally it is not properly installed. +See the explanation +here. +

    +[Go Top] +


    + +Q: Does the MATLAB interface provide a function to do scaling? +
    +

    +It is extremely easy to do scaling under MATLAB. +The following one-line code scale each feature to the range +of [0,1]: +

    +(data - repmat(min(data,[],1),size(data,1),1))*spdiags(1./(max(data,[],1)-min(data,[],1))',0,size(data,2),size(data,2))
    +
    +

    +[Go Top] +


    + +Q: How could I use MATLAB interface for parameter selection? +
    +

    +One can do this by a simple loop. +See the following example: +

    +bestcv = 0;
    +for log2c = -1:3,
    +  for log2g = -4:1,
    +    cmd = ['-v 5 -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
    +    cv = svmtrain(heart_scale_label, heart_scale_inst, cmd);
    +    if (cv >= bestcv),
    +      bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
    +    end
    +    fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
    +  end
    +end
    +
    +You may adjust the parameter range in the above loops. +

    +[Go Top] +


    + +Q: I use MATLAB parallel programming toolbox on a multi-core environment for parameter selection. Why the program is even slower? +
    +

    +Fabrizio Lacalandra of University of Pisa reported this issue. +It seems the problem is caused by the screen output. +If you disable the info function +using

    #if 0,
    then the problem +may be solved. +

    +[Go Top] +


    + +Q: How do I use LIBSVM with OpenMP under MATLAB? +
    +

    +In Makefile, +you need to add -fopenmp to CFLAGS and -lgomp to MEX_OPTION. For Octave, you need the same modification. + +

    However, a minor problem is that +the number of threads cannot +be specified in MATLAB. We tried Version 7.12 (R2011a) and gcc-4.6.1. + +

    +% export OMP_NUM_THREADS=4; matlab
    +>> setenv('OMP_NUM_THREADS', '1');
    +
    + +Then OMP_NUM_THREADS is still 4 while running the program. Please contact us if you +see how to solve this problem. You can, however, +specify the number in the source code (thanks +to comments from Ricardo Santiago-mozos): +
    +#pragma omp parallel  for private(i) num_threads(4)
    +
    +

    +[Go Top] +


    + +Q: How could I generate the primal variable w of linear SVM? +
    +

    +Let's start from the binary class and +assume you have two labels -1 and +1. +After obtaining the model from calling svmtrain, +do the following to have w and b: +

    +w = model.SVs' * model.sv_coef;
    +b = -model.rho;
    +
    +if model.Label(1) == -1
    +  w = -w;
    +  b = -b;
    +end
    +
    +If you do regression or one-class SVM, then the if statement is not needed. + +

    For multi-class SVM, we illustrate the setting +in the following example of running the iris +data, which have 3 classes +

      
    +> [y, x] = libsvmread('../../htdocs/libsvmtools/datasets/multiclass/iris.scale');
    +> m = svmtrain(y, x, '-t 0')
    +
    +m = 
    +
    +    Parameters: [5x1 double]
    +      nr_class: 3
    +       totalSV: 42
    +           rho: [3x1 double]
    +         Label: [3x1 double]
    +         ProbA: []
    +         ProbB: []
    +           nSV: [3x1 double]
    +       sv_coef: [42x2 double]
    +           SVs: [42x4 double]
    +
    +sv_coef is like: +
    ++-+-+--------------------+
    +|1|1|                    |
    +|v|v|  SVs from class 1  |
    +|2|3|                    |
    ++-+-+--------------------+
    +|1|2|                    |
    +|v|v|  SVs from class 2  |
    +|2|3|                    |
    ++-+-+--------------------+
    +|1|2|                    |
    +|v|v|  SVs from class 3  |
    +|3|3|                    |
    ++-+-+--------------------+
    +
    +so we need to see nSV of each classes. +
      
    +> m.nSV
    +
    +ans =
    +
    +     3
    +    21
    +    18
    +
    +Suppose the goal is to find the vector w of classes +1 vs 3. Then +y_i alpha_i of training 1 vs 3 are +
      
    +> coef = [m.sv_coef(1:3,2); m.sv_coef(25:42,1)];
    +
    +and SVs are: +
      
    +> SVs = [m.SVs(1:3,:); m.SVs(25:42,:)];
    +
    +Hence, w is +
    +> w = SVs'*coef;
    +
    +For rho, +
    +> m.rho
    +
    +ans =
    +
    +    1.1465
    +    0.3682
    +   -1.9969
    +> b = -m.rho(2);
    +
    +because rho is arranged by 1vs2 1vs3 2vs3. + + + +

    +[Go Top] +


    + +Q: Is there an OCTAVE interface for libsvm? +
    +

    +Yes, after libsvm 2.86, the matlab interface +works on OCTAVE as well. Please type +

    +make octave
    +
    +for installation. +

    +[Go Top] +


    + +Q: How to handle the name conflict between svmtrain in the libsvm matlab interface and that in MATLAB bioinformatics toolbox? +
    +

    +The easiest way is to rename the svmtrain binary +file (e.g., svmtrain.mexw32 on 32-bit windows) +to a different +name (e.g., svmtrain2.mexw32). +

    +[Go Top] +


    + +Q: On Windows I got an error message "Invalid MEX-file: Specific module not found" when running the pre-built MATLAB interface in the windows sub-directory. What should I do? +
    +

    + +The error usually happens +when there are missing runtime components +such as MSVCR100.dll on your Windows platform. +You can use tools such as +Dependency +Walker to find missing library files. + +

    +For example, if the pre-built MEX files are compiled by +Visual C++ 2010, +you must have installed +Microsoft Visual C++ Redistributable Package 2010 +(vcredist_x86.exe). You can easily find the freely +available file from Microsoft's web site. + +

    +For 64bit Windows, the situation is similar. If +the pre-built files are by +Visual C++ 2008, then you must have +Microsoft Visual C++ Redistributable Package 2008 +(vcredist_x64.exe). +

    +[Go Top] +


    + +Q: LIBSVM supports 1-vs-1 multi-class classification. If instead I would like to use 1-vs-rest, how to implement it using MATLAB interface? +
    + +

    +Please use code in the following directory. The following example shows how to +train and test the problem dna (training and testing). + +

    Load, train and predict data: +

    +[trainY trainX] = libsvmread('./dna.scale');
    +[testY testX] = libsvmread('./dna.scale.t');
    +model = ovrtrain(trainY, trainX, '-c 8 -g 4');
    +[pred ac decv] = ovrpredict(testY, testX, model);
    +fprintf('Accuracy = %g%%\n', ac * 100);
    +
    +Conduct CV on a grid of parameters +
    +bestcv = 0;
    +for log2c = -1:2:3,
    +  for log2g = -4:2:1,
    +    cmd = ['-q -c ', num2str(2^log2c), ' -g ', num2str(2^log2g)];
    +    cv = get_cv_ac(trainY, trainX, cmd, 3);
    +    if (cv >= bestcv),
    +      bestcv = cv; bestc = 2^log2c; bestg = 2^log2g;
    +    end
    +    fprintf('%g %g %g (best c=%g, g=%g, rate=%g)\n', log2c, log2g, cv, bestc, bestg, bestcv);
    +  end
    +end
    +
    +

    +[Go Top] +


    +

    +LIBSVM home page +

    + + diff -Nru libsvm-3.1/java/libsvm/svm.java libsvm-3.12/java/libsvm/svm.java --- libsvm-3.1/java/libsvm/svm.java 2011-03-26 03:26:22.000000000 +0000 +++ libsvm-3.12/java/libsvm/svm.java 2012-03-31 22:18:22.000000000 +0000 @@ -375,7 +375,7 @@ nr_free++; if(2*nr_free < active_size) - svm.info("\nWarning: using -h 0 may be faster\n"); + svm.info("\nWARNING: using -h 0 may be faster\n"); if (nr_free*l > 2*active_size*(l-active_size)) { @@ -456,10 +456,11 @@ // optimization step int iter = 0; + int max_iter = Math.max(10000000, l>Integer.MAX_VALUE/100 ? Integer.MAX_VALUE : 100*l); int counter = Math.min(l,1000)+1; int[] working_set = new int[2]; - while(true) + while(iter < max_iter) { // show progress and do shrinking @@ -628,6 +629,18 @@ } } + + if(iter >= max_iter) + { + if(active_size < l) + { + // reconstruct the whole gradient to calculate objective value + reconstruct_gradient(); + active_size = l; + svm.info("*"); + } + svm.info("\nWARNING: reaching max number of iterations"); + } // calculate rho @@ -1279,7 +1292,7 @@ // // construct and solve various formulations // - public static final int LIBSVM_VERSION=310; + public static final int LIBSVM_VERSION=312; public static final Random rand = new Random(); private static svm_print_interface svm_print_stdout = new svm_print_interface() @@ -1960,6 +1973,10 @@ int[] label = tmp_label[0]; int[] start = tmp_start[0]; int[] count = tmp_count[0]; + + if(nr_class == 1) + svm.info("WARNING: training data in only one class. See README for details.\n"); + svm_node[][] x = new svm_node[l][]; int i; for(i=0;i 2*active_size*(l-active_size)) { @@ -456,10 +456,11 @@ // optimization step int iter = 0; + int max_iter = Math.max(10000000, l>Integer.MAX_VALUE/100 ? Integer.MAX_VALUE : 100*l); int counter = Math.min(l,1000)+1; int[] working_set = new int[2]; - while(true) + while(iter < max_iter) { // show progress and do shrinking @@ -628,6 +629,18 @@ } } + + if(iter >= max_iter) + { + if(active_size < l) + { + // reconstruct the whole gradient to calculate objective value + reconstruct_gradient(); + active_size = l; + svm.info("*"); + } + svm.info("\nWARNING: reaching max number of iterations"); + } // calculate rho @@ -1279,7 +1292,7 @@ // // construct and solve various formulations // - public static final int LIBSVM_VERSION=310; + public static final int LIBSVM_VERSION=312; public static final Random rand = new Random(); private static svm_print_interface svm_print_stdout = new svm_print_interface() @@ -1960,6 +1973,10 @@ int[] label = tmp_label[0]; int[] start = tmp_start[0]; int[] count = tmp_count[0]; + + if(nr_class == 1) + svm.info("WARNING: training data in only one class. See README for details.\n"); + svm_node[][] x = new svm_node[l][]; int i; for(i=0;i num_nonzeros) System.err.print( - "Warning: original #nonzeros " + num_nonzeros+"\n" + "WARNING: original #nonzeros " + num_nonzeros+"\n" +" new #nonzeros " + new_num_nonzeros+"\n" +"Use -l 0 if many original feature values are zeros\n"); diff -Nru libsvm-3.1/java/svm_toy.java libsvm-3.12/java/svm_toy.java --- libsvm-3.1/java/svm_toy.java 2010-12-13 09:43:08.000000000 +0000 +++ libsvm-3.12/java/svm_toy.java 2012-02-03 05:29:04.000000000 +0000 @@ -98,7 +98,7 @@ button_save.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e) - { button_save_clicked(); }}); + { button_save_clicked(input_line.getText()); }}); button_load.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e) @@ -368,7 +368,7 @@ clear_all(); } - void button_save_clicked() + void button_save_clicked(String args) { FileDialog dialog = new FileDialog(new Frame(),"Save",FileDialog.SAVE); dialog.setVisible(true); @@ -376,11 +376,31 @@ if (filename == null) return; try { DataOutputStream fp = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename))); + + int svm_type = svm_parameter.C_SVC; + int svm_type_idx = args.indexOf("-s "); + if(svm_type_idx != -1) + { + StringTokenizer svm_str_st = new StringTokenizer(args.substring(svm_type_idx+2).trim()); + svm_type = atoi(svm_str_st.nextToken()); + } + int n = point_list.size(); - for(int i=0;i(y))?(x):(y)) #endif diff -Nru libsvm-3.1/matlab/libsvmwrite.c libsvm-3.12/matlab/libsvmwrite.c --- libsvm-3.1/matlab/libsvmwrite.c 2011-02-23 23:00:31.000000000 +0000 +++ libsvm-3.12/matlab/libsvmwrite.c 2011-08-27 05:03:31.000000000 +0000 @@ -3,9 +3,11 @@ #include #include "mex.h" +#ifdef MX_API_VER #if MX_API_VER < 0x07030000 typedef int mwIndex; #endif +#endif void exit_with_help() { diff -Nru libsvm-3.1/matlab/Makefile libsvm-3.12/matlab/Makefile --- libsvm-3.1/matlab/Makefile 2011-02-23 23:00:31.000000000 +0000 +++ libsvm-3.12/matlab/Makefile 2011-05-09 23:35:15.000000000 +0000 @@ -46,8 +46,8 @@ svm_model_matlab.o: svm_model_matlab.c ../svm.h $(CXX) $(CFLAGS) -c svm_model_matlab.c -../svm.o: - cd ../; make svm.o +../svm.o: ../svm.cpp ../svm.h + make -C .. svm.o clean: rm -f *~ *.o *.mex* *.obj ../svm.o diff -Nru libsvm-3.1/matlab/make.m libsvm-3.12/matlab/make.m --- libsvm-3.1/matlab/make.m 2011-02-23 23:00:31.000000000 +0000 +++ libsvm-3.12/matlab/make.m 2011-09-04 16:35:25.000000000 +0000 @@ -1,10 +1,21 @@ -% This make.m is used under Windows +% This make.m is for MATLAB and OCTAVE under Windows, Mac, and Unix -% add -largeArrayDims on 64-bit machines - -mex -O -largeArrayDims -I..\ -c ..\svm.cpp -mex -O -largeArrayDims -I..\ -c svm_model_matlab.c -mex -O -largeArrayDims -I..\ svmtrain.c svm.obj svm_model_matlab.obj -mex -O -largeArrayDims -I..\ svmpredict.c svm.obj svm_model_matlab.obj -mex -O -largeArrayDims libsvmread.c -mex -O -largeArrayDims libsvmwrite.c +try + Type = ver; + % This part is for OCTAVE + if(strcmp(Type(1).Name, 'Octave') == 1) + mex libsvmread.c + mex libsvmwrite.c + mex svmtrain.c ../svm.cpp svm_model_matlab.c + mex svmpredict.c ../svm.cpp svm_model_matlab.c + % This part is for MATLAB + % Add -largeArrayDims on 64-bit machines of MATLAB + else + mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims libsvmread.c + mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims libsvmwrite.c + mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims svmtrain.c ../svm.cpp svm_model_matlab.c + mex CFLAGS="\$CFLAGS -std=c99" -largeArrayDims svmpredict.c ../svm.cpp svm_model_matlab.c + end +catch + fprintf('If make.m failes, please check README about detailed instructions.\n'); +end diff -Nru libsvm-3.1/matlab/README libsvm-3.12/matlab/README --- libsvm-3.1/matlab/README 2011-03-16 03:10:27.000000000 +0000 +++ libsvm-3.12/matlab/README 2011-10-30 11:40:38.000000000 +0000 @@ -24,46 +24,56 @@ Installation ============ -On Unix systems, we recommend using GNU g++ as your -compiler and type 'make' to build 'svmtrain.mexglx' and 'svmpredict.mexglx'. -Note that we assume your MATLAB is installed in '/usr/local/matlab', -if not, please change MATLABDIR in Makefile. +On Windows systems, pre-built binary files are already in the +directory '..\windows', so no need to conduct installation. Now we +provide binary files only for 64bit MATLAB on Windows. If you would +like to re-build the package, please rely on the following steps. + +We recommend using make.m on both MATLAB and OCTAVE. Just type 'make' +to build 'libsvmread.mex', 'libsvmwrite.mex', 'svmtrain.mex', and +'svmpredict.mex'. + +On MATLAB or Octave: + + >> make + +If make.m does not work on MATLAB (especially for Windows), try 'mex +-setup' to choose a suitable compiler for mex. Make sure your compiler +is accessible and workable. Then type 'make' to start the +installation. Example: - linux> make -To use Octave, type 'make octave': + matlab>> mex -setup + (ps: MATLAB will show the following messages to setup default compiler.) + Please choose your compiler for building external interface (MEX) files: + Would you like mex to locate installed compilers [y]/n? y + Select a compiler: + [1] Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio + [0] None + Compiler: 1 + Please verify your choices: + Compiler: Microsoft Visual C/C++ 7.1 + Location: C:\Program Files\Microsoft Visual Studio + Are these correct?([y]/n): y + + matlab>> make + +On Unix systems, if neither make.m nor 'mex -setup' works, please use +Makefile and type 'make' in a command window. Note that we assume +your MATLAB is installed in '/usr/local/matlab'. If not, please change +MATLABDIR in Makefile. Example: - linux> make octave + linux> make -On Windows systems, pre-built binary files are already in the directory -`..\windows', so no need to conduct installation. Now we include both -32bit binary files and 64bit binary files, but in future releases, we -will provide binary files only for 64bit MATLAB on Windows. If you have -modified the sources and would like to re-build the package, type -'mex -setup' in MATLAB to choose a compiler for mex first. Then type -'make' to start the installation. +To use octave, type 'make octave': Example: - matlab> mex -setup - (ps: MATLAB will show the following messages to setup default compiler.) - Please choose your compiler for building external interface (MEX) files: - Would you like mex to locate installed compilers [y]/n? y - Select a compiler: - [1] Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio - [0] None - Compiler: 1 - Please verify your choices: - Compiler: Microsoft Visual C/C++ 7.1 - Location: C:\Program Files\Microsoft Visual Studio - Are these correct?([y]/n): y - - matlab> make - + linux> make octave -For list of supported/compatible compilers for MATLAB, please check the -following page: +For a list of supported/compatible compilers for MATLAB, please check +the following page: http://www.mathworks.com/support/compilers/current_release/ @@ -129,9 +139,11 @@ accuracy, is a vector including accuracy (for classification), mean squared error, and squared correlation coefficient (for regression). The third is a matrix containing decision values or probability -estimates (if '-b 1' is specified). If k is the number of classes, -for decision values, each row includes results of predicting -k(k-1)/2 binary-class SVMs. For probabilities, each row contains k values +estimates (if '-b 1' is specified). If k is the number of classes +in training data, for decision values, each row includes results of +predicting k(k-1)/2 binary-class SVMs. For classification, k = 1 is a +special case. Decision value +1 is returned for each testing instance, +instead of an empty vector. For probabilities, each row contains k values indicating the probability that the testing instance is in each class. Note that the order of classes here is the same as 'Label' field in the model structure. @@ -220,8 +232,9 @@ by Rong-En Fan and Ting-Fan Wu. If you find this tool useful, please cite LIBSVM as follows -Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for -support vector machines, 2001. Software available at +Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support +vector machines. ACM Transactions on Intelligent Systems and +Technology, 2:27:1--27:27, 2011. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm For any question, please contact Chih-Jen Lin , diff -Nru libsvm-3.1/matlab/svm_model_matlab.c libsvm-3.12/matlab/svm_model_matlab.c --- libsvm-3.1/matlab/svm_model_matlab.c 2011-02-23 23:00:31.000000000 +0000 +++ libsvm-3.12/matlab/svm_model_matlab.c 2011-08-27 05:03:31.000000000 +0000 @@ -1,12 +1,14 @@ #include #include -#include "svm.h" +#include "../svm.h" #include "mex.h" +#ifdef MX_API_VER #if MX_API_VER < 0x07030000 typedef int mwIndex; #endif +#endif #define NUM_OF_RETURN_FIELD 10 diff -Nru libsvm-3.1/matlab/svmpredict.c libsvm-3.12/matlab/svmpredict.c --- libsvm-3.1/matlab/svmpredict.c 2011-03-08 13:25:57.000000000 +0000 +++ libsvm-3.12/matlab/svmpredict.c 2011-08-27 05:03:31.000000000 +0000 @@ -1,14 +1,16 @@ #include #include #include -#include "svm.h" +#include "../svm.h" #include "mex.h" #include "svm_model_matlab.h" +#ifdef MX_API_VER #if MX_API_VER < 0x07030000 typedef int mwIndex; #endif +#endif #define CMD_LEN 2048 @@ -134,7 +136,8 @@ // decision values are in plhs[2] if(svm_type == ONE_CLASS || svm_type == EPSILON_SVR || - svm_type == NU_SVR) + svm_type == NU_SVR || + nr_class == 1) // if only one class in training data, decision values are still returned. plhs[2] = mxCreateDoubleMatrix(testing_instance_number, 1, mxREAL); else plhs[2] = mxCreateDoubleMatrix(testing_instance_number, nr_class*(nr_class-1)/2, mxREAL); @@ -190,8 +193,11 @@ { double *dec_values = (double *) malloc(sizeof(double) * nr_class*(nr_class-1)/2); predict_label = svm_predict_values(model, x, dec_values); - for(i=0;i<(nr_class*(nr_class-1))/2;i++) - ptr_dec_values[instance_index + i * testing_instance_number] = dec_values[i]; + if(nr_class == 1) + ptr_dec_values[instance_index] = 1; + else + for(i=0;i<(nr_class*(nr_class-1))/2;i++) + ptr_dec_values[instance_index + i * testing_instance_number] = dec_values[i]; free(dec_values); } ptr_predict_label[instance_index] = predict_label; diff -Nru libsvm-3.1/matlab/svmtrain.c libsvm-3.12/matlab/svmtrain.c --- libsvm-3.1/matlab/svmtrain.c 2011-03-08 13:25:57.000000000 +0000 +++ libsvm-3.12/matlab/svmtrain.c 2011-08-27 05:03:31.000000000 +0000 @@ -2,14 +2,16 @@ #include #include #include -#include "svm.h" +#include "../svm.h" #include "mex.h" #include "svm_model_matlab.h" +#ifdef MX_API_VER #if MX_API_VER < 0x07030000 typedef int mwIndex; #endif +#endif #define CMD_LEN 2048 #define Malloc(type,n) (type *)malloc((n)*sizeof(type)) diff -Nru libsvm-3.1/python/Makefile libsvm-3.12/python/Makefile --- libsvm-3.1/python/Makefile 2010-06-16 04:04:46.000000000 +0000 +++ libsvm-3.12/python/Makefile 2011-05-09 23:35:15.000000000 +0000 @@ -1,4 +1,4 @@ all = lib lib: - cd ..; make lib; cd - + make -C .. lib diff -Nru libsvm-3.1/python/README libsvm-3.12/python/README --- libsvm-3.1/python/README 2011-03-23 03:52:01.000000000 +0000 +++ libsvm-3.12/python/README 2012-03-22 03:25:51.000000000 +0000 @@ -33,10 +33,11 @@ the above command. We assume that the shared library is on the LIBSVM main directory or in the system path. -For windows, the shared library libsvm.dll is ready in the directory -`..\windows'. You can also copy it to the system directory (e.g., -`C:\WINDOWS\system32\' for Windows XP). To regenerate the shared library, -please follow the instruction of building windows binaries in LIBSVM README. +For windows, the shared library libsvm.dll for 32-bit python is ready +in the directory `..\windows'. You can also copy it to the system +directory (e.g., `C:\WINDOWS\system32\' for Windows XP). To regenerate +the shared library, please follow the instruction of building windows +binaries in LIBSVM README. Quick Start =========== @@ -56,14 +57,26 @@ # Sparse data >>> y, x = [1,-1], [{1:1, 3:1}, {1:-1,3:-1}] >>> prob = svm_problem(y, x) ->>> param = svm_parameter('-c 4 -b 1') +>>> param = svm_parameter('-t 0 -c 4 -b 1') >>> m = svm_train(prob, param) +# Precomputed kernel data (-t 4) +# Dense data +>>> y, x = [1,-1], [[1, 2, -2], [2, -2, 2]] +# Sparse data +>>> y, x = [1,-1], [{0:1, 1:2, 2:-2}, {0:2, 1:-2, 2:2}] +# isKernel=True must be set for precomputer kernel +>>> prob = svm_problem(y, x, isKernel=True) +>>> param = svm_parameter('-t 4 -c 4 -b 1') +>>> m = svm_train(prob, param) +# For the format of precomputed kernel, please read LIBSVM README. + + # Other utility functions >>> svm_save_model('heart_scale.model', m) >>> m = svm_load_model('heart_scale.model') >>> p_label, p_acc, p_val = svm_predict(y, x, m, '-b 1') ->>> ACC, MSE, SCC = evaluations(y, p_val) +>>> ACC, MSE, SCC = evaluations(y, p_label) # Getting online help >>> help(svm_train) @@ -120,7 +133,7 @@ val: a float indicates the feature value. -- Function: gen_svm_nodearray(xi [,feature_max=None [,issparse=False]]) +- Function: gen_svm_nodearray(xi [,feature_max=None [,isKernel=False]]) Generate a feature vector from a Python list/tuple or a dictionary: @@ -130,11 +143,12 @@ max_idx: the maximal feature index of xi - issparse: if issparse == True, zero feature values are removed. The default - value is False for supporting the pre-computed kernel. - feature_max: if feature_max is assigned, features with indices larger than feature_max are removed. + + isKernel: if isKernel == True, the list index starts from 0 for precomputed + kernel. Otherwise, the list index starts from 1. The default + value is False. - class svm_problem: @@ -150,6 +164,12 @@ Note that if your x contains sparse data (i.e., dictionary), the internal ctypes data format is still sparse. + For pre-computed kernel, the isKernel flag should be set to True: + + >>> prob = svm_problem(y, x, isKernel=True) + + Please read LIBSVM README for more details of pre-computed kernel. + - class svm_parameter: Construct an svm_parameter instance @@ -233,6 +253,8 @@ prob: an svm_problem instance generated by calling svm_problem(y, x). + For pre-computed kernel, you should use + svm_problem(y, x, isKernel=True) param: an svm_parameter instance generated by calling svm_parameter('training_options') @@ -280,9 +302,12 @@ regression). p_vals: a list of decision values or probability estimates (if '-b 1' - is specified). If k is the number of classes, for decision values, - each element includes results of predicting k(k-1)/2 binary-class - SVMs. For probabilities, each element contains k values indicating + is specified). If k is the number of classes in training data, + for decision values, each element includes results of predicting + k(k-1)/2 binary-class SVMs. For classification, k = 1 is a + special case. Decision value [+1] is returned for each testing + instance, instead of an empty list. + For probabilities, each element contains k values indicating the probability that the testing instance is in each class. Note that the order of classes is the same as the 'model.label' field in the model structure. @@ -325,8 +350,9 @@ Science, National Taiwan University. If you find this tool useful, please cite LIBSVM as follows -Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for -support vector machines, 2001. Software available at +Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support +vector machines. ACM Transactions on Intelligent Systems and +Technology, 2:27:1--27:27, 2011. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm For any question, please contact Chih-Jen Lin , diff -Nru libsvm-3.1/python/svm.py libsvm-3.12/python/svm.py --- libsvm-3.1/python/svm.py 2011-03-23 03:52:01.000000000 +0000 +++ libsvm-3.12/python/svm.py 2012-01-15 15:14:27.000000000 +0000 @@ -40,10 +40,12 @@ _types = [c_int, c_double] _fields_ = genFields(_names, _types) -def gen_svm_nodearray(xi, feature_max=None, issparse=None): +def gen_svm_nodearray(xi, feature_max=None, isKernel=None): if isinstance(xi, dict): index_range = xi.keys() elif isinstance(xi, (list, tuple)): + if not isKernel: + xi = [0] + xi # idx should start from 1 index_range = range(len(xi)) else: raise TypeError('xi should be a dictionary, list or tuple') @@ -51,7 +53,7 @@ if feature_max: assert(isinstance(feature_max, int)) index_range = filter(lambda j: j <= feature_max, index_range) - if issparse: + if not isKernel: index_range = filter(lambda j:xi[j] != 0, index_range) index_range = sorted(index_range) @@ -70,7 +72,7 @@ _types = [c_int, POINTER(c_double), POINTER(POINTER(svm_node))] _fields_ = genFields(_names, _types) - def __init__(self, y, x): + def __init__(self, y, x, isKernel=None): if len(y) != len(x): raise ValueError("len(y) != len(x)") self.l = l = len(y) @@ -78,7 +80,7 @@ max_idx = 0 x_space = self.x_space = [] for i, xi in enumerate(x): - tmp_xi, tmp_idx = gen_svm_nodearray(xi) + tmp_xi, tmp_idx = gen_svm_nodearray(xi,isKernel=isKernel) x_space += [tmp_xi] max_idx = max(max_idx, tmp_idx) self.n = max_idx diff -Nru libsvm-3.1/python/svmutil.py libsvm-3.12/python/svmutil.py --- libsvm-3.1/python/svmutil.py 2010-06-16 07:51:10.000000000 +0000 +++ libsvm-3.12/python/svmutil.py 2012-01-15 15:14:27.000000000 +0000 @@ -115,8 +115,8 @@ if isinstance(arg1, (list, tuple)): assert isinstance(arg2, (list, tuple)) y, x, options = arg1, arg2, arg3 - prob = svm_problem(y, x) param = svm_parameter(options) + prob = svm_problem(y, x, isKernel=(param.kernel_type == PRECOMPUTED)) elif isinstance(arg1, svm_problem): prob = arg1 if isinstance(arg2, svm_parameter): @@ -210,7 +210,7 @@ prob_estimates = (c_double * nr_class)() for xi in x: - xi, idx = gen_svm_nodearray(xi) + xi, idx = gen_svm_nodearray(xi, isKernel=(m.param.kernel_type == PRECOMPUTED)) label = libsvm.svm_predict_probability(m, xi, prob_estimates) values = prob_estimates[:nr_class] pred_labels += [label] @@ -224,9 +224,12 @@ nr_classifier = nr_class*(nr_class-1)//2 dec_values = (c_double * nr_classifier)() for xi in x: - xi, idx = gen_svm_nodearray(xi) + xi, idx = gen_svm_nodearray(xi, isKernel=(m.param.kernel_type == PRECOMPUTED)) label = libsvm.svm_predict_values(m, xi, dec_values) - values = dec_values[:nr_classifier] + if(nr_class == 1): + values = [1] + else: + values = dec_values[:nr_classifier] pred_labels += [label] pred_values += [values] diff -Nru libsvm-3.1/README libsvm-3.12/README --- libsvm-3.1/README 2011-03-24 05:10:44.000000000 +0000 +++ libsvm-3.12/README 2012-02-03 05:56:55.000000000 +0000 @@ -78,6 +78,12 @@ heart_scale.model output' to see the prediction accuracy. The `output' file contains the predicted class labels. +For classification, if training data are in only one class (i.e., all +labels are the same), then `svm-train' issues a warning message: +`Warning: training data in only one class. See README for details,' +which means the training data is very unbalanced. The label in the +training data is directly returned when testing. + There are some other useful programs in this package. svm-scale: @@ -97,10 +103,12 @@ You can enter options in the bottom of the window, the syntax of options is the same as `svm-train'. - Note that "load" and "save" consider data in the - classification but not the regression case. Each data point - has one label (the color) which must be 1, 2, or 3 and two - attributes (x-axis and y-axis values) in [0,1]. + Note that "load" and "save" consider dense data format both in + classification and the regression cases. For classification, + each data point has one label (the color) that must be 1, 2, + or 3 and two attributes (x-axis and y-axis values) in + [0,1). For regression, each data point has one target value + (y-axis) and one attribute (x-axis values) in [0, 1). Type `make' in respective directories to build them. @@ -558,7 +566,8 @@ label[0] vs. label[nr_class-1], label[1] vs. label[2], ..., label[nr_class-2] vs. label[nr_class-1], where label can be obtained from the function svm_get_labels. The returned value is - the predicted class for x. + the predicted class for x. Note that when nr_class = 1, this + function does not give any decision value. For a regression model, dec_values[0] and the returned value are both the function value of x calculated using the model. For a @@ -645,7 +654,7 @@ Library usages are similar to the C version. These functions are available: public class svm { - public static final int LIBSVM_VERSION=310; + public static final int LIBSVM_VERSION=312; public static svm_model svm_train(svm_problem prob, svm_parameter param); public static void svm_cross_validation(svm_problem prob, svm_parameter param, int nr_fold, double[] target); public static int svm_get_svm_type(svm_model model); @@ -722,9 +731,10 @@ If you find LIBSVM helpful, please cite it as -Chih-Chung Chang and Chih-Jen Lin, LIBSVM: a library for -support vector machines, 2001. -Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm +Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support +vector machines. ACM Transactions on Intelligent Systems and +Technology, 2:27:1--27:27, 2011. Software available at +http://www.csie.ntu.edu.tw/~cjlin/libsvm LIBSVM implementation document is available at http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm.pdf diff -Nru libsvm-3.1/svm.cpp libsvm-3.12/svm.cpp --- libsvm-3.1/svm.cpp 2011-03-08 13:25:57.000000000 +0000 +++ libsvm-3.12/svm.cpp 2011-12-26 08:46:32.000000000 +0000 @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "svm.h" int libsvm_version = LIBSVM_VERSION; typedef float Qfloat; @@ -474,7 +476,7 @@ nr_free++; if(2*nr_free < active_size) - info("\nWarning: using -h 0 may be faster\n"); + info("\nWARNING: using -h 0 may be faster\n"); if (nr_free*l > 2*active_size*(l-active_size)) { @@ -556,9 +558,10 @@ // optimization step int iter = 0; + int max_iter = max(10000000, l>INT_MAX/100 ? INT_MAX : 100*l); int counter = min(l,1000)+1; - - while(1) + + while(iter < max_iter) { // show progress and do shrinking @@ -725,6 +728,18 @@ } } + if(iter >= max_iter) + { + if(active_size < l) + { + // reconstruct the whole gradient to calculate objective value + reconstruct_gradient(); + active_size = l; + info("*"); + } + info("\nWARNING: reaching max number of iterations"); + } + // calculate rho si->rho = calculate_rho(); @@ -2114,7 +2129,10 @@ int *perm = Malloc(int,l); // group training data of the same class - svm_group_classes(prob,&nr_class,&label,&start,&count,perm); + svm_group_classes(prob,&nr_class,&label,&start,&count,perm); + if(nr_class == 1) + info("WARNING: training data in only one class. See README for details.\n"); + svm_node **x = Malloc(svm_node *,l); int i; for(i=0;iweight_label[i] == label[j]) break; if(j == nr_class) - fprintf(stderr,"warning: class label %d specified in weight is not found\n", param->weight_label[i]); + fprintf(stderr,"WARNING: class label %d specified in weight is not found\n", param->weight_label[i]); else weighted_C[j] *= param->weight[i]; } @@ -2440,13 +2458,14 @@ double svm_predict_values(const svm_model *model, const svm_node *x, double* dec_values) { + int i; if(model->param.svm_type == ONE_CLASS || model->param.svm_type == EPSILON_SVR || model->param.svm_type == NU_SVR) { double *sv_coef = model->sv_coef[0]; double sum = 0; - for(int i=0;il;i++) + for(i=0;il;i++) sum += sv_coef[i] * Kernel::k_function(x,model->SV[i],model->param); sum -= model->rho[0]; *dec_values = sum; @@ -2458,7 +2477,6 @@ } else { - int i; int nr_class = model->nr_class; int l = model->l; @@ -2583,6 +2601,9 @@ FILE *fp = fopen(model_file_name,"w"); if(fp==NULL) return -1; + char *old_locale = strdup(setlocale(LC_ALL, NULL)); + setlocale(LC_ALL, "C"); + const svm_parameter& param = model->param; fprintf(fp,"svm_type %s\n", svm_type_table[param.svm_type]); @@ -2661,6 +2682,10 @@ } fprintf(fp, "\n"); } + + setlocale(LC_ALL, old_locale); + free(old_locale); + if (ferror(fp) != 0 || fclose(fp) != 0) return -1; else return 0; } @@ -2690,7 +2715,10 @@ { FILE *fp = fopen(model_file_name,"rb"); if(fp==NULL) return NULL; - + + char *old_locale = strdup(setlocale(LC_ALL, NULL)); + setlocale(LC_ALL, "C"); + // read parameters svm_model *model = Malloc(svm_model,1); @@ -2721,6 +2749,9 @@ if(svm_type_table[i] == NULL) { fprintf(stderr,"unknown svm type.\n"); + + setlocale(LC_ALL, old_locale); + free(old_locale); free(model->rho); free(model->label); free(model->nSV); @@ -2743,6 +2774,9 @@ if(kernel_type_table[i] == NULL) { fprintf(stderr,"unknown kernel function.\n"); + + setlocale(LC_ALL, old_locale); + free(old_locale); free(model->rho); free(model->label); free(model->nSV); @@ -2807,6 +2841,9 @@ else { fprintf(stderr,"unknown text in model file: [%s]\n",cmd); + + setlocale(LC_ALL, old_locale); + free(old_locale); free(model->rho); free(model->label); free(model->nSV); @@ -2879,6 +2916,9 @@ } free(line); + setlocale(LC_ALL, old_locale); + free(old_locale); + if (ferror(fp) != 0 || fclose(fp) != 0) return NULL; diff -Nru libsvm-3.1/svm.h libsvm-3.12/svm.h --- libsvm-3.1/svm.h 2011-03-08 13:25:57.000000000 +0000 +++ libsvm-3.12/svm.h 2012-02-03 05:56:55.000000000 +0000 @@ -1,7 +1,7 @@ #ifndef _LIBSVM_H #define _LIBSVM_H -#define LIBSVM_VERSION 310 +#define LIBSVM_VERSION 312 #ifdef __cplusplus extern "C" { diff -Nru libsvm-3.1/svm-scale.c libsvm-3.12/svm-scale.c --- libsvm-3.1/svm-scale.c 2009-03-16 15:16:05.000000000 +0000 +++ libsvm-3.12/svm-scale.c 2011-05-28 14:19:13.000000000 +0000 @@ -286,7 +286,7 @@ if (new_num_nonzeros > num_nonzeros) fprintf(stderr, - "Warning: original #nonzeros %ld\n" + "WARNING: original #nonzeros %ld\n" " new #nonzeros %ld\n" "Use -l 0 if many original feature values are zeros\n", num_nonzeros, new_num_nonzeros); diff -Nru libsvm-3.1/svm-toy/gtk/callbacks.cpp libsvm-3.12/svm-toy/gtk/callbacks.cpp --- libsvm-3.1/svm-toy/gtk/callbacks.cpp 2010-09-12 12:11:10.000000000 +0000 +++ libsvm-3.12/svm-toy/gtk/callbacks.cpp 2012-02-03 05:29:04.000000000 +0000 @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "callbacks.h" @@ -166,7 +167,7 @@ case 'h': param.shrinking = atoi(p); break; - case 'b': + case 'b': param.probability = atoi(p); break; case 'w': @@ -380,10 +381,25 @@ if(fileselection_flag == SAVE) { FILE *fp = fopen(filename,"w"); + + const char *p = gtk_entry_get_text(GTK_ENTRY(entry_option)); + const char* svm_type_str = strstr(p, "-s "); + int svm_type = C_SVC; + if(svm_type_str != NULL) + sscanf(svm_type_str, "-s %d", &svm_type); + if(fp) { - for(list::iterator p = point_list.begin(); p != point_list.end();p++) - fprintf(fp,"%d 1:%f 2:%f\n", p->value, p->x, p->y); + if(svm_type == EPSILON_SVR || svm_type == NU_SVR) + { + for(list::iterator p = point_list.begin(); p != point_list.end();p++) + fprintf(fp,"%f 1:%f\n", p->y, p->x); + } + else + { + for(list::iterator p = point_list.begin(); p != point_list.end();p++) + fprintf(fp,"%d 1:%f 2:%f\n", p->value, p->x, p->y); + } fclose(fp); } @@ -399,10 +415,18 @@ { int v; double x,y; - if(sscanf(buf,"%d%*d:%lf%*d:%lf",&v,&x,&y)!=3) - break; - point p = {x,y,v}; - point_list.push_back(p); + if(sscanf(buf,"%d%*d:%lf%*d:%lf",&v,&x,&y)==3) + { + point p = {x,y,v}; + point_list.push_back(p); + } + else if(sscanf(buf,"%lf%*d:%lf",&y,&x)==2) + { + point p = {x,y,current_value}; + point_list.push_back(p); + } + else + break; } fclose(fp); draw_all_points(); diff -Nru libsvm-3.1/svm-toy/gtk/Makefile libsvm-3.12/svm-toy/gtk/Makefile --- libsvm-3.1/svm-toy/gtk/Makefile 2010-11-14 00:59:28.000000000 +0000 +++ libsvm-3.12/svm-toy/gtk/Makefile 2011-05-11 02:15:45.000000000 +0000 @@ -15,8 +15,8 @@ callbacks.o: callbacks.cpp callbacks.h $(CXX) $(CFLAGS) -c callbacks.cpp -../../svm.o: - cd ../..; make svm.o +../../svm.o: ../../svm.cpp ../../svm.h + make -C ../.. svm.o clean: rm -f *~ callbacks.o svm-toy main.o interface.o callbacks.o ../../svm.o diff -Nru libsvm-3.1/svm-toy/qt/Makefile libsvm-3.12/svm-toy/qt/Makefile --- libsvm-3.1/svm-toy/qt/Makefile 2008-12-19 06:42:05.000000000 +0000 +++ libsvm-3.12/svm-toy/qt/Makefile 2011-05-11 02:15:45.000000000 +0000 @@ -9,8 +9,8 @@ svm-toy.moc: svm-toy.cpp $(MOC) svm-toy.cpp -o svm-toy.moc -../../svm.o: - cd ../..; make svm.o +../../svm.o: ../../svm.cpp ../../svm.h + make -C ../.. svm.o clean: rm -f *~ svm-toy svm-toy.moc ../../svm.o diff -Nru libsvm-3.1/svm-toy/qt/svm-toy.cpp libsvm-3.12/svm-toy/qt/svm-toy.cpp --- libsvm-3.1/svm-toy/qt/svm-toy.cpp 2010-09-12 12:11:10.000000000 +0000 +++ libsvm-3.12/svm-toy/qt/svm-toy.cpp 2012-02-03 05:29:04.000000000 +0000 @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "../../svm.h" @@ -286,10 +287,25 @@ if(!filename.isNull()) { FILE *fp = fopen(filename.toAscii().constData(),"w"); + + const char *p = input_line.text().toAscii().constData(); + const char* svm_type_str = strstr(p, "-s "); + int svm_type = C_SVC; + if(svm_type_str != NULL) + sscanf(svm_type_str, "-s %d", &svm_type); + if(fp) { - for(list::iterator p = point_list.begin(); p != point_list.end();p++) - fprintf(fp,"%d 1:%f 2:%f\n", p->value, p->x, p->y); + if(svm_type == EPSILON_SVR || svm_type == NU_SVR) + { + for(list::iterator p = point_list.begin(); p != point_list.end();p++) + fprintf(fp,"%f 1:%f\n", p->y, p->x); + } + else + { + for(list::iterator p = point_list.begin(); p != point_list.end();p++) + fprintf(fp,"%d 1:%f 2:%f\n", p->value, p->x, p->y); + } fclose(fp); } } @@ -308,10 +324,18 @@ { int v; double x,y; - if(sscanf(buf,"%d%*d:%lf%*d:%lf",&v,&x,&y)!=3) - break; - point p = {x,y,v}; - point_list.push_back(p); + if(sscanf(buf,"%d%*d:%lf%*d:%lf",&v,&x,&y)==3) + { + point p = {x,y,v}; + point_list.push_back(p); + } + else if(sscanf(buf,"%lf%*d:%lf",&y,&x)==2) + { + point p = {x,y,current_value}; + point_list.push_back(p); + } + else + break; } fclose(fp); draw_all_points(); diff -Nru libsvm-3.1/svm-toy/windows/svm-toy.cpp libsvm-3.12/svm-toy/windows/svm-toy.cpp --- libsvm-3.1/svm-toy/windows/svm-toy.cpp 2010-09-12 12:11:10.000000000 +0000 +++ libsvm-3.12/svm-toy/windows/svm-toy.cpp 2012-02-03 05:29:04.000000000 +0000 @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "../../svm.h" @@ -410,10 +411,27 @@ if(getfilename(hwnd,filename,1024,1)) { FILE *fp = fopen(filename,"w"); + + char str[1024]; + Edit_GetLine(edit, 0, str, sizeof(str)); + const char *p = str; + const char* svm_type_str = strstr(p, "-s "); + int svm_type = C_SVC; + if(svm_type_str != NULL) + sscanf(svm_type_str, "-s %d", &svm_type); + if(fp) { - for (list::iterator p = point_list.begin(); p != point_list.end(); p++) - fprintf(fp,"%d 1:%f 2:%f\n",p->value,p->x,p->y); + if(svm_type == EPSILON_SVR || svm_type == NU_SVR) + { + for(list::iterator p = point_list.begin(); p != point_list.end();p++) + fprintf(fp,"%f 1:%f\n", p->y, p->x); + } + else + { + for(list::iterator p = point_list.begin(); p != point_list.end();p++) + fprintf(fp,"%d 1:%f 2:%f\n", p->value, p->x, p->y); + } fclose(fp); } } @@ -433,10 +451,18 @@ { int v; double x,y; - if(sscanf(buf,"%d%*d:%lf%*d:%lf",&v,&x,&y)!=3) + if(sscanf(buf,"%d%*d:%lf%*d:%lf",&v,&x,&y)==3) + { + point p = {x,y,v}; + point_list.push_back(p); + } + else if(sscanf(buf,"%lf%*d:%lf",&y,&x)==2) + { + point p = {x,y,current_value}; + point_list.push_back(p); + } + else break; - point p = {x,y,v}; - point_list.push_back(p); } fclose(fp); draw_all_points(); diff -Nru libsvm-3.1/svm-train.c libsvm-3.12/svm-train.c --- libsvm-3.1/svm-train.c 2011-02-05 12:21:25.000000000 +0000 +++ libsvm-3.12/svm-train.c 2011-05-27 03:32:19.000000000 +0000 @@ -92,7 +92,7 @@ if(error_msg) { - fprintf(stderr,"Error: %s\n",error_msg); + fprintf(stderr,"ERROR: %s\n",error_msg); exit(1); } diff -Nru libsvm-3.1/tools/checkdata.py libsvm-3.12/tools/checkdata.py --- libsvm-3.1/tools/checkdata.py 2010-12-31 05:51:25.000000000 +0000 +++ libsvm-3.12/tools/checkdata.py 2011-12-01 12:25:03.000000000 +0000 @@ -84,7 +84,7 @@ if index < 0: err(line_no, "feature index must be positive; wrong feature {0}".format(nodes[i])) line_error = True - elif index < prev_index: + elif index <= prev_index: err(line_no, "feature indices must be in an ascending order, previous/current features {0} {1}".format(nodes[i-1], nodes[i])) line_error = True prev_index = index diff -Nru libsvm-3.1/tools/easy.py libsvm-3.12/tools/easy.py --- libsvm-3.1/tools/easy.py 2010-12-31 05:51:25.000000000 +0000 +++ libsvm-3.12/tools/easy.py 2011-05-11 13:50:19.000000000 +0000 @@ -22,7 +22,7 @@ svmscale_exe = r"..\windows\svm-scale.exe" svmtrain_exe = r"..\windows\svm-train.exe" svmpredict_exe = r"..\windows\svm-predict.exe" - gnuplot_exe = r"c:\tmp\gnuplot\bin\pgnuplot.exe" + gnuplot_exe = r"c:\tmp\gnuplot\binary\pgnuplot.exe" grid_py = r".\grid.py" assert os.path.exists(svmscale_exe),"svm-scale executable not found" diff -Nru libsvm-3.1/tools/grid.py libsvm-3.12/tools/grid.py --- libsvm-3.1/tools/grid.py 2011-02-02 15:55:20.000000000 +0000 +++ libsvm-3.12/tools/grid.py 2012-02-24 14:31:25.000000000 +0000 @@ -22,7 +22,8 @@ else: # example for windows svmtrain_exe = r"..\windows\svm-train.exe" - gnuplot_exe = r"c:\tmp\gnuplot\bin\pgnuplot.exe" + # svmtrain_exe = r"c:\Program Files\libsvm\windows\svm-train.exe" + gnuplot_exe = r"c:\tmp\gnuplot\binary\pgnuplot.exe" # global parameters and their default values @@ -132,6 +133,12 @@ best_log2c,best_log2g,best_rate = best_param + # if newly obtained c, g, or cv values are the same, + # then stop redrawing the contour. + if all(x[0] == db[0][0] for x in db): return + if all(x[1] == db[0][1] for x in db): return + if all(x[2] == db[0][2] for x in db): return + if tofile: gnuplot.write(b"set term png transparent small linewidth 2 medium enhanced\n") gnuplot.write("set output \"{0}\"\n".format(png_filename.replace('\\','\\\\')).encode()) diff -Nru libsvm-3.1/tools/README libsvm-3.12/tools/README --- libsvm-3.1/tools/README 2010-09-12 13:39:24.000000000 +0000 +++ libsvm-3.12/tools/README 2011-10-30 14:07:18.000000000 +0000 @@ -83,7 +83,7 @@ executable files. You can either change paths in the beginning of grid.py or specify them in the command line. For example, -> grid.py -log2c -5,5,1 -svmtrain c:\libsvm\windows\svm-train.exe -gnuplot c:\tmp\gnuplot\bin\pgnuplot.exe -v 10 heart_scale +> grid.py -log2c -5,5,1 -svmtrain "c:\Program Files\libsvm\windows\svm-train.exe" -gnuplot c:\tmp\gnuplot\binary\pgnuplot.exe -v 10 heart_scale Output: two files dataset.png: the CV accuracy contour plot generated by gnuplot Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/libsvm.dll and /tmp/Yz3_unGntQ/libsvm-3.12/windows/libsvm.dll differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/libsvmread.mexw32 and /tmp/Yz3_unGntQ/libsvm-3.12/windows/libsvmread.mexw32 differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/libsvmread.mexw64 and /tmp/Yz3_unGntQ/libsvm-3.12/windows/libsvmread.mexw64 differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/libsvmwrite.mexw32 and /tmp/Yz3_unGntQ/libsvm-3.12/windows/libsvmwrite.mexw32 differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/libsvmwrite.mexw64 and /tmp/Yz3_unGntQ/libsvm-3.12/windows/libsvmwrite.mexw64 differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/svm-predict.exe and /tmp/Yz3_unGntQ/libsvm-3.12/windows/svm-predict.exe differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/svmpredict.mexw32 and /tmp/Yz3_unGntQ/libsvm-3.12/windows/svmpredict.mexw32 differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/svmpredict.mexw64 and /tmp/Yz3_unGntQ/libsvm-3.12/windows/svmpredict.mexw64 differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/svm-scale.exe and /tmp/Yz3_unGntQ/libsvm-3.12/windows/svm-scale.exe differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/svm-toy.exe and /tmp/Yz3_unGntQ/libsvm-3.12/windows/svm-toy.exe differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/svm-train.exe and /tmp/Yz3_unGntQ/libsvm-3.12/windows/svm-train.exe differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/svmtrain.mexw32 and /tmp/Yz3_unGntQ/libsvm-3.12/windows/svmtrain.mexw32 differ Binary files /tmp/YlEcUP4Yws/libsvm-3.1/windows/svmtrain.mexw64 and /tmp/Yz3_unGntQ/libsvm-3.12/windows/svmtrain.mexw64 differ