cjlin1 / libsvm

LIBSVM -- A Library for Support Vector Machines
https://www.csie.ntu.edu.tw/~cjlin/libsvm/
BSD 3-Clause "New" or "Revised" License
4.54k stars 1.64k forks source link

One-Class SVM yielding different results with OpenMP in Matlab #151

Open seijikun opened 4 years ago

seijikun commented 4 years ago

I see very weird behavior when applying OpenMP as stated in the FAQ, in combination with one-class-SVMs.

When I train a one-class SVM with OpenMP in Matlab, I get a different accuracy (way better) than when I train the one-class SVM without OpenMP. However, when using Octave, I get the same results in both cases.

Accuracy-Results(Matlab):

normalAccuracy = 0.5;
parallelAccuracy = 1;

Accuracy-Results(Octave):

normalAccuracy = 0.5;
parallelAccuracy = 0.5;

I added a complete example-project for reproduction: libsvmtest.tar.gz The FAQ only mentions SVC_Q::get_Q and SVR_Q::get_Q to apply the OpenMP pragmas, so I did not apply it on ONE_CLASS_Q::get_Q for this experiment. OpenMP is therefore only used for the prediction.

ZYQue commented 4 years ago

Hello,

I try to reproduce by your files but I get parallelAccuracy=0.5 in Matlab. Could you please provide the decision values in both normal and parallel cases?

seijikun commented 4 years ago

Sure! Here are the stored svmModels: svmModels.tar.gz

Some system-information: Operating-System: Linux openSUSE Tumbleweed Octave: 5.1.0 Matlab: R2019a Update 5 (9.6.0.1174912) 64-bit (glnxa64) libsvm: 3.24 gcc: 9.2.1 20190820 [gcc-9-branch revision 274748]

ZYQue commented 4 years ago

Sorry, maybe I didn't make myself clear. For decision values, I mean:

[predicted_label, accuracy, decision_values/prob_estimates] = svmpredict(testing_label_vector, testing_instance_matrix, model [, 'libsvm_options']);

(you can see it in matlab/README)

When I run your code, I get the same decision_values in parallel as normal. So the parallelAccuracy is 0.5, the same as normalAccuracy. Please compare your decision values in normal and parallel to make sure what leads the weird output.

ZYQue commented 4 years ago

In addition, I did check your provided models and found they look good. But since you said you only applied OpenMP in prediction, I think it's normal that we can get the same models. If there is something wrong, it may happen on svmpredict(). That's why I want to see the decision values you generate.

seijikun commented 4 years ago

Oh, I'm sorry, I misunderstood! Here they are: predictResults.tar.gz

ZYQue commented 4 years ago

Hello,

Your decision values in parallel seem abnormal. Since we cannot reproduce your case, it's hard to make a conclusion where is wrong. We recommend you to substitute C for Matlab to avoid other influences. If your result still seems weird, we are pleased to discuss with you.