Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More robust fixes for numerical issues #229

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CXX ?= g++
CFLAGS = -Wall -Wconversion -O3 -fPIC
SHVER = 4
SHVER = 5
OS = $(shell uname)
ifeq ($(OS),Darwin)
SHARED_LIB_FLAG = -dynamiclib -Wl,-install_name,libsvm.so.$(SHVER)
Expand Down
7 changes: 7 additions & 0 deletions matlab/svmtrain.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void exit_with_help()
"-e epsilon : set tolerance of termination criterion (default 0.001)\n"
"-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)\n"
"-b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n"
"-f floatprecision : set the floating-point precision of kernel values (default 0)\n"
" 0 -- float\n"
" 1 -- double\n"
"-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n"
"-v n: n-fold cross validation mode\n"
"-q : quiet mode (no outputs)\n"
Expand Down Expand Up @@ -125,6 +128,7 @@ int parse_command_line(int nrhs, const mxArray *prhs[], char *model_file_name)
param.p = 0.1;
param.shrinking = 1;
param.probability = 0;
param.use_double_precision_kernel_values = 0;
param.nr_weight = 0;
param.weight_label = NULL;
param.weight = NULL;
Expand Down Expand Up @@ -187,6 +191,9 @@ int parse_command_line(int nrhs, const mxArray *prhs[], char *model_file_name)
case 'b':
param.probability = atoi(argv[i]);
break;
case 'f':
param.use_double_precision_kernel_values = atoi(argv[i]);
break;
case 'q':
print_func = &print_null;
i--;
Expand Down
8 changes: 6 additions & 2 deletions python/libsvm/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ def __init__(self, y, x, isKernel=False):
class svm_parameter(Structure):
_names = ["svm_type", "kernel_type", "degree", "gamma", "coef0",
"cache_size", "eps", "C", "nr_weight", "weight_label", "weight",
"nu", "p", "shrinking", "probability"]
"nu", "p", "shrinking", "probability", "use_double_precision_kernel_values"]
_types = [c_int, c_int, c_int, c_double, c_double,
c_double, c_double, c_double, c_int, POINTER(c_int), POINTER(c_double),
c_double, c_double, c_int, c_int]
c_double, c_double, c_int, c_int, c_int]
_fields_ = genFields(_names, _types)

def __init__(self, options = None):
Expand Down Expand Up @@ -274,6 +274,7 @@ def set_to_default_values(self):
self.p = 0.1
self.shrinking = 1
self.probability = 0
self.use_double_precision_kernel_values = 0
self.nr_weight = 0
self.weight_label = None
self.weight = None
Expand Down Expand Up @@ -331,6 +332,9 @@ def parse_options(self, options):
elif argv[i] == "-b":
i = i + 1
self.probability = int(argv[i])
elif argv[i] == '-f':
i = i + 1
self.use_double_precision_kernel_values = int(argv[i])
elif argv[i] == "-q":
self.print_func = PRINT_STRING_FUN(print_null)
elif argv[i] == "-v":
Expand Down
3 changes: 3 additions & 0 deletions python/libsvm/svmutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def svm_train(arg1, arg2=None, arg3=None):
-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 model for probability estimates, 0 or 1 (default 0)
-f floatprecision : set the floating-point precision of kernel values (default 0)
0 -- float
1 -- double
-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)
Expand Down
7 changes: 7 additions & 0 deletions svm-train.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void exit_with_help()
"-e epsilon : set tolerance of termination criterion (default 0.001)\n"
"-h shrinking : whether to use the shrinking heuristics, 0 or 1 (default 1)\n"
"-b probability_estimates : whether to train a SVC or SVR model for probability estimates, 0 or 1 (default 0)\n"
"-f floatprecision : set the floating-point precision of kernel values (default 0)\n"
" 0 -- float\n"
" 1 -- double\n"
"-wi weight : set the parameter C of class i to weight*C, for C-SVC (default 1)\n"
"-v n: n-fold cross validation mode\n"
"-q : quiet mode (no outputs)\n"
Expand Down Expand Up @@ -176,6 +179,7 @@ void parse_command_line(int argc, char **argv, char *input_file_name, char *mode
param.p = 0.1;
param.shrinking = 1;
param.probability = 0;
param.use_double_precision_kernel_values = 0;
param.nr_weight = 0;
param.weight_label = NULL;
param.weight = NULL;
Expand Down Expand Up @@ -225,6 +229,9 @@ void parse_command_line(int argc, char **argv, char *input_file_name, char *mode
case 'b':
param.probability = atoi(argv[i]);
break;
case 'f':
param.use_double_precision_kernel_values = atoi(argv[i]);
break;
case 'q':
print_func = &print_null;
i--;
Expand Down
Loading