TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
feature_sel_module.m
Go to the documentation of this file.
1 function [iFeatSelected, train_data, test_data] = feature_sel_module(train_data, test_data, labelsTrain, parameters)
2 %feature selection module
3 iFeatSelected = [];
4 train_data(isnan(train_data)) = 0;
5 if ~isfield(parameters, 'pca_tresh')
6  pca_tresh = 0.95;
7 else
8  pca_tresh = parameters.pca_tresh;
9 end
10 if ~isfield(parameters, 'is_regression')
11  parameters.is_regression = 0;
12 end
13 cca_tresh = 12;
14 nbFeatures = size(train_data,2);
15 switch parameters.featSelection
16  case 'forward'
17  c = cvpartition(labelsTrain,'k',10);
18  opts = statset('display','iter');
19  classifier = 'diaglinear';
20  priorP = ones(1,parameters.nbClasses)/parameters.nbClasses;
21  fun = @(XT,yT,Xt,yt)...
22  (((sum((yt==2)&(classify(Xt,XT,yT,classifier,priorP)==1))/sum(yt==2))*10+(sum((yt==1)&(classify(Xt,XT,yT,classifier,priorP)==2))/sum(yt==1)))/11);
23  [inmodel, ~]= sequentialfs(fun,train_data,labelsTrain,'cv',c,'direction','forward', 'options',opts); %
24  iFeatSelected = find(inmodel);
25  case 'Fisher'
26  [listFeatures,FC] = fisherCrit(train_data,labelsTrain, parameters.nbClasses);
27  FisherThreshold = 0.3;
28  iFeatSelected = listFeatures(FC>FisherThreshold);
29  if length(iFeatSelected) < 3
30  iFeatSelected = listFeatures(1:3);
31  end
32 
33  case 'none'
34  iFeatSelected = 1:size(train_data,2);
35 end
36 if isempty(iFeatSelected)
37  iFeatSelected = 1:nbFeatures;
38 end
39 train_data = train_data(:,iFeatSelected);
40 test_data = test_data(:,iFeatSelected);
feature_sel_module
function feature_sel_module(in train_data, in test_data, in labelsTrain, in parameters)
fisherCrit
function fisherCrit(in features, in labels, in nbClasses)