libsvm在64位linux下matlab編譯

現在寫一下在matlab中從安裝libsvm到使用。

1,安裝

系統版本:redhat 6.0  

libsvm的版本:3.1.  下載地址:http://www.csie.ntu.edu.tw/~cjlin/libsvm/

matlab版本:2010b. 


1) 首先將matlab當前目錄設爲libsvm\matlab所在目錄,並且保證Makefile文件中MATLABDIR路徑爲matlab安裝所在路徑,例如:

MATLABDIR ?= /RLNK/PACKAGE/MATLAB.2010b


2)在matlab命令窗口中輸入:-mex -setup

出現

    Options files control which compiler to use, the compiler and link command
    options, and the runtime libraries to link against.

    Using the 'mex -setup' command selects an options file that is
    placed in ~/.matlab/R2010b and used by default for 'mex'. An options
    file in the current working directory or specified on the command line
    overrides the default options file in ~/.matlab/R2010b.
 
    To override the default options file, use the 'mex -f' command
    (see 'mex -help' for more information).

The options files available for mex are:

  1: /rlnk/package/matlab.2010b.64/bin/gccopts.sh :
      Template Options file for building gcc MEX-files
 
  2: /rlnk/package/matlab.2010b.64/bin/mexopts.sh :
      Template Options file for building MEX-files via the system ANSI compiler
 

  0: Exit with no changes


選擇了 1
Enter the number of the compiler (0-2):
1

確定
Overwrite /dcs/pg10/xingjie/.matlab/R2010b/mexopts.sh ([y]/n)?
y

/rlnk/package/matlab.2010b.64/bin/gccopts.sh is being copied to
/dcs/pg10/xingjie/.matlab/R2010b/mexopts.sh


**************************************************************************
  Warning: The MATLAB C and Fortran API has changed to support MATLAB
           variables with more than 2^32-1 elements.  In the near future
           you will be required to update your code to utilize the new
           API. You can find more information about this at:
           http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9
           Building with the -largeArrayDims option enables the new API.
**************************************************************************

3)輸入make,編譯。

這裏我發現輸入make總是編譯報錯,輸入 !make 就能正常通過編譯。估計是compiler選擇的問題。只能從工程角度表示可以解決問題,但不知到是什麼原理,對Linux不熟,求懂行者解答。

另外在網上看到有人也遇到類似問題,用 !make 無法解決,但是將.c文件中所有的註釋符號由 // 換成 /* */ ,並且吧Makefile中所有 .obj 後綴 換成  .o 後綴就可以了。同樣不懂,求解答。

編譯成功後就會發現目錄下多了:

libsvmread.mexa64
libsvmwrite.mexa64
svmpredict.mexa64
svmtrain.mexa64

這就說明編譯成功了。

2,使用

這裏使用libsvm自帶的例子測試一下。
load heart_scale.mat
 model = svmtrain(heart_scale_label, heart_scale_inst, '-c 1 -g 0.07');
 [predict_label, accuracy, dec_values] = svmpredict(heart_scale_label, heart_scale_inst, model); % test the training data

可以看到結果:

Accuracy = 86.6667% (234/270) (classification)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章