libsvm
libsvm copied to clipboard
Java: Error in number formatting during scaling
I have executed the following two commands:
$java -cp libsvm.jar svm_scale -l 0 -y -1.0 1.0 -s /tmp/SVMScaleRange_341a7b72-40d9-420f-8a9c-f67e47b65eaa /home/hmf/git/adw/data/libsvm/a1a > a1a.scaled
$java -cp libsvm.jar svm_scale -l 0 -y -1.0 1.0 -r /tmp/SVMScaleRange_341a7b72-40d9-420f-8a9c-f67e47b65eaa /home/hmf/git/adw/data/libsvm/a1a.t > a1a.t.scaled
Exception in thread "main" java.lang.NumberFormatException: For input string: "-1,000000000000000"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at svm_scale.run(svm_scale.java:251)
at svm_scale.main(svm_scale.java:348)
The problem is that in svm_scale:288 a formatter is being used:
Formatter formatter = new Formatter(new StringBuilder());
So the current locale is used. In my case this means that floating point numbers use a comma as decimal separator. So a comma is written but parsing expects a period. I think we have several options here:
- Change the use of the code to use a simple toString() conversion (issues with precision?)
- Force the locale using a
Stringformatter (see [1]) - Force the applications locale (see [1])
- Use the constructor
Formatter(Locale l, Appendable a)and useLocale.US
I think (4) is trivial and the way to go.
TIA
[1] https://stackoverflow.com/questions/5236056/force-point-as-decimal-separator-in-java