Help with libsvm

504 views
Skip to first unread message

David Dreisigmeyer

unread,
Feb 28, 2014, 3:42:53 PM2/28/14
to emscripte...@googlegroups.com
Hi,

I'm been trying to get libsvm working with emscripten.  Others on the group have had success with this.  Here's what I've done and the output:

---------------

$ emcc -O2 svm.cpp -o svm.bc && emcc -O2 svm-train.cpp -o svm-train.bc && emcc -O2 svm.bc svm-train.bc -o svm-test.js && node svm-test.js && node svm-test.js heart_scale
Usage: svm-train [options] training_set_file [model_file]
options:
-s svm_type : set type of SVM (default 0)
    0 -- C-SVC        (multi-class classification)
    1 -- nu-SVC        (multi-class classification)
    2 -- one-class SVM
    3 -- epsilon-SVR    (regression)
    4 -- nu-SVR        (regression)
-t kernel_type : set type of kernel function (default 2)
    0 -- linear: u'*v
    1 -- polynomial: (gamma*u'*v + coef0)^degree
    2 -- radial basis function: exp(-gamma*|u-v|^2)
    3 -- sigmoid: tanh(gamma*u'*v + coef0)
    4 -- precomputed kernel (kernel values in training_set_file)
-d degree : set degree in kernel function (default 3)
-g gamma : set gamma in kernel function (default 1/num_features)
-r coef0 : set coef0 in kernel function (default 0)
-c cost : set the parameter C of C-SVC, epsilon-SVR, and nu-SVR (default 1)
-n nu : set the parameter nu of nu-SVC, one-class SVM, and nu-SVR (default 0.5)
-p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
-m cachesize : set cache memory size in MB (default 100)
-e epsilon : set tolerance of termination criterion (default 0.001)
-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)
-b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)
-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)
-v n: n-fold cross validation mode
-q : quiet mode (no outputs)
can't open input file heart_scale
The error is: No such file or directory

=======================================

The file heart_scale is definitely in that directory.  The libsvm code is here: http://www.csie.ntu.edu.tw/~cjlin/libsvm/.  (Note: I modified the svm-train.cpp file a little in read_problem to give perror.)

Thanks,

-Dave

Alon Zakai

unread,
Feb 28, 2014, 4:00:40 PM2/28/14
to emscripte...@googlegroups.com
Look for NODEFS for letting code running in node access local files.

- Alon



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David Dreisigmeyer

unread,
Mar 3, 2014, 7:31:34 AM3/3/14
to emscripte...@googlegroups.com
Thanks Alon, very much appreciated.  The --embed-file method worked easily.  Haven't had time yet to look at the FS library.  The following worked for libsvm 3.17 (comparing the gcc compiled version and the emcc one):

====================================

$ make svm-train && ./svm-train heart_scale
c++ -O2 -c svm.cpp
c++ -O2 svm-train.c svm.o -o svm-train -lm
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
*
optimization finished, #iter = 162
nu = 0.431029
obj = -100.877288, rho = 0.424462
nSV = 132, nBSV = 107
Total nSV = 132
$ mkdir data && cp heart_scale data && emcc -O2 svm.cpp svm-train.c -o svm-test.js --embed-file data/ && node svm-test.js data/heart_scale
*
optimization finished, #iter = 162
nu = 0.431029
obj = -100.877288, rho = 0.424462
nSV = 132, nBSV = 107
Total nSV = 132

====================================
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages