IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
featurestability.m
Go to the documentation of this file.
1 %>@ingroup maths
2 %> @file
3 %> @brief Calculates the stability curve for a set of feature subsets
4 %>
5 %> This function is suitable for feature subsets found using Sequential Forward Feature Selection
6 %>
7 %> Kuncheva's "consistency" formula is I_c = (r-k^2/nf)/(k-k^2/nf), where r is the number of common elements in the two sets, and k is the
8 %> number of elements of either sets
9 %>
10 %>
11 %> <h3>References</h3>
12 %>
13 %> Kuncheva, L. I. A stability index for feature selection, 390-395.
14 %>
15 %> @param subsets matrix or cell of subsets. If matrix, each row is a subset. A subset contains feature indexes. If cell of subsets, all
16 %> subsets must have the same number of elements
17 %> @param nf Number of features
18 %> @param type ='kun'. Type of stability measuse. Possibilities are:
19 %> @arg 'kun' Kuncheva's Stability Index
20 %> @arg ... (open for others)
21 %> @param type2='mul'
22 %> @arg 'uni' evaluates position in subsets individually
23 %> @arg 'mul' evaluates considering m-sized subsets (m = 1..k)
24 
25 %> @return y nf x stability curve
26 function y = featurestability(subsets, nf, type, type2)
27 
28 if nargin < 3 || isempty(type)
29  type = 'kun';
30 end;
31 
32 if nargin < 4 || isempty(type2)
33  type2 = 'mul';
34 end;
35 flag_uni = strcmp(type2, 'uni');
36 
37 %> translates type into a function handle
38 switch type
39  case 'kun'
40  f_type = @feacons_kun;
41  otherwise
42  irerror(sprintf('Feature consistency type "%s" not implemented', type));
43 end;
44 
45 % if cell, converts to matrix
46 if iscell(subsets)
47  subsets = subsets2matrix(subsets);
48 end;
49 
50 [nsub, k] = size(subsets);
51 
52 y = zeros(1, k);
53 for m = 1:k
54  if flag_uni
55  temp = subsets(:, m);
56  else
57  temp = subsets(:, 1:m);
58  end;
59  for i = 1:nsub
60  for j = i+1:nsub
61  y(m) = y(m)+f_type(temp(i, :), temp(j, :), nf);
62  end;
63  end;
64 end;
65 y = y*2/(nsub*(nsub-1)); % takes the average consistency
function irerror(in s)
function featurestability(in subsets, in nf, in type, in type2)
function subsets2matrix(in subsets)
function feacons_kun(in s1, in s2, in nf)