function SVMRFE_inx = svmrfe(trn_data,trn_cls) % Input: % trn_data: sample_num x feat_num matrix % trn_cls: sample_num x 1 matrix % Output: % SVMRFE_inx: output index ranked by SVMRFE % Note: % This code calls RfeRanking.m, which is provided by Dr.MATTEO % MASOTTI at http://www.bo.infn.it/~masotti/MySoftware/RFE/RfeRanking.m % % This code was originally designed for the feature selection in image % steganalysis with binary classification of the following paper: % % Q. Liu, A. Sung, Z. Chen, J. Xu (2008). Feature mining and pattern % classification for steganalysis of LSB matching steganography in % grayscale images. Pattern Recognition 41 (1): 56-66. % % % The function is re-written by Qingzhong Liu @ 06/04/2009. Please cite the % above paper when you use this code. % % kertype = 0; %% 0 --- Linear. You may adjust the parameters in the following lines. Parameters(1) = kertype; Parameters(2) = 1; Parameters(3) = 1; Parameters(4) = 0; Parameters(5) = 1; Parameters(6) = 10; Parameters(7) = 0.001; [smaple_num, feat_dim] = size(trn_data); if smaple_num ~= length(trn_cls) disp('No matching between sample number and class number, ERROR!'); disp('Please correct and try again!'); return end %%%%%%%%%%%% cls_num = unique(trn_cls); if length(cls_num) > 2 disp('More than two class numbers, ERROR!'); disp('Please correct and try again!'); return end inx1 = find(trn_cls == cls_num(1)); inx2 = find(trn_cls == cls_num(2)); label_trn = trn_cls; label_trn(inx1) = -1; label_trn(inx2) = 1; [AlphaY, SVs, Bias, Parameters, nSV, nLabel] = SVMTrain(trn_data', label_trn', Parameters); % SVM training, call OSU-SVM function [rank_feat, ind_feat] = RfeRanking(AlphaY, SVs, Parameters); % call RfeRanking ind_feat2(1:feat_dim,1) = [1:feat_dim]'; ind_feat2(1:feat_dim,2) = ind_feat'; for k = feat_dim-1:-1:2 orig_inx = ind_feat(1:k); RFE_data = trn_data(:,orig_inx); [AlphaY, SVs, Bias, Parameters, nSV, nLabel] = SVMTrain(RFE_data', label_trn', Parameters); % Recursively call SVM training [rank_feat2, ind2] = RfeRanking(AlphaY, SVs, Parameters); % Recursively call RfeRanking for m = 1:length(ind2) inx = ind2(m); ind_feat(m) = ind_feat2(inx,2); end ind_feat2(1:feat_dim,1) = [1:feat_dim]'; ind_feat2(1:feat_dim,2) = ind_feat'; fprintf('SVMRFE feature selection, the %8d -th element feature subset determined!\n',k); end SVMRFE_inx = ind_feat; return