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 测试安装的。

posted @ 2014-04-23 16:40  dupuleng  阅读(4190)  评论(4编辑  收藏  举报