llibsvm-svdd-3.1的编译make

来源:互联网 发布:网络安全教育主题班会 编辑:程序博客网 时间:2024/06/04 18:29

从libsvm官网上的LibSVM Tools(http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/)中下载svdd-3.1工具箱

网站原文说:

LIBSVM for SVDD and finding the smallest sphere containing all data

SVDD is another type of one-class SVM. We implement the formulation in Tax and Duin, Support Vector Data Description, Machine Learning, vol. 54, 2004, 45-66. Please download this zip file, put sources into libsvm-3.1 (http://www.csie.ntu.edu.tw/~cjlin/libsvm/oldfiles/), and make the code. The options are

  • -s 5 SVDD
  • -s 6 gives the square of the radius for L1-SVM
  • -s 7 gives the square of the radius for L2-SVM

 

其中明确强调要把svdd-3.1工具箱放到libsvm-3.1中,注意版本,其他版本会安装错误。

 

[教程] llibsvm-svdd-3.1安装过程详解http://www.matlabsky.com/forum.php?mod=viewthread&tid=35981)中介绍了详细的过程及出现的问题,在此直接copy过来了。原文出现在

liqi3837671的博客“在libsvm中遇到的svdd-3.1程序不能被matlab mex编译的问题 ”(http://liqi3837671.blog.163.com/blog/static/165912886201217101744904/

 


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)

 

 

 

 

 

 

原创粉丝点击