libsvm-svdd安裝過程詳解(轉)


從libsvm官網上下了svdd工具箱,沒想到安裝過程耗費了我一天的時間,搜索論壇也毫無結果,出現類似的問題,終於在liqi3837671的博客看到了問題的解決方法,寫下來,讓同學們少走些彎路吧。(該方法請在libsvm3.1版本上安裝,高版本libsvm按照此方法安裝由於文件更新問題會失敗)
1、下載svdd工具箱(http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/),里面有一個matlab文件夾和3個文件svm.cpp、svm.h、svm-train.c。
2、將matlab文件夾中的文件svm_model_matlab.c、svmtrain.c拷貝到libsvm的matlab文件夾中,會提示文件名相同,是否覆蓋,點是。
3、將svm.cpp、svm.h、svm-train.c這3個文件拷貝到libsvm文件夾下,也會有文件名相同,是否覆蓋的提示,同樣點是。
4、按照faruto版主的帖子libsvm安裝方法一文中的要求重新安裝libsvm,設置搜索路徑、mex -setup、make等等。最關鍵就在於make后出現的問題
>> make
svmtrain.c 
svmtrain.c(457) : error C2065: 'ptr' : undeclared identifier 
svmtrain.c(457) : warning C4047: '=' : 'int' differs in levels of indirection from 'double *' 
svmtrain.c(458) : error C2065: 'ptr' : undeclared identifier 
svmtrain.c(458) : error C2109: subscript requires array or pointer type 

C:\MATLAB~1\BIN\MEX.PL: Error: Compile of 'svmtrain.c' failed. 會出現這樣的提示
5、打開svmtrain.c文件,拖到第455行,相關代碼如下:
if(cross_validation)
  {
   
   if(param.svm_type == R2 || param.svm_type == R2q)
   {
    mexPrintf("\"R^2\" cannot do cross validation.\n");
    fake_answer(plhs);
    return;
   }
   double *ptr;
   plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
   ptr = mxGetPr(plhs[0]);
   ptr[0] = do_cross_validation();
  
  }
將double *ptr;放到這段語句的上端,就不能出現上述那個錯誤:
if(cross_validation)
  {
   double *ptr;
   if(param.svm_type == R2 || param.svm_type == R2q)
   {
    mexPrintf("\"R^2\" cannot do cross validation.\n");
    fake_answer(plhs);
    return;
   }

   plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
   ptr = mxGetPr(plhs[0]);
   ptr[0] = do_cross_validation();
  
  }
6、修改完svmtrain.c文件后,關閉matlab,重新按照步驟4操作,就可正確運行了。
>> load heart_scale;
>> model = svmtrain(heart_scale_label,heart_scale_inst,'-s 5');
*
optimization finished, #iter = 75
radius = 0.750478
obj = -0.315256, rho = -0.096973
nSV = 139, nBSV = 131
>> [predict_label,accuracy] = svmpredict(heart_scale_label,heart_scale_inst,model);
Accuracy = 46.6667% (126/270) (classification)

補充內容 (2013-11-30 10:06):
林智仁主頁上更新了svdd對應到3.17版本,可以用 libsvm3.17 對應 svdd3.17 測試安裝的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM