source: prextra/featsel2.m @ 5

Last change on this file since 5 was 5, checked in by bduin, 14 years ago
File size: 2.0 KB
RevLine 
[5]1%FEATSEL2 Pairwise feature selection for classification
2%
3% [W,R] = FEATSEL2(A,CRIT,K,T,FID)
4%
5% INPUT
6%   A    Training dataset
7%   CRIT Name of the criterion or untrained mapping
8%        (default: 'NN', i.e. the 1-Nearest Neighbor error)
9%   K    Number of features to select (default: K = 0, return optimal set)
10%   T    Tuning dataset (optional)
11%   FID  File ID to write progress to (default [], see PRPROGRESS)
12%
13% OUTPUT
14%   W    Output feature selection mapping
15%   R    Matrix with step-by-step results
16%
17% DESCRIPTION
18%
19% Best pairs of features are evaluated inidividually, i.e. independently
20% from other pairs.
21%
22% SEE ALSO
23% MAPPINGS, DATASETS, FEATEVAL, FEATSELF, FEATSELLR, FEATSEL,
24% FEATSELO, FEATSELB, FEATSELI, FEATSELP, FEATSELM, PRPROGRESS
25
26% Copyright: A. Harol, R.P.W. Duin, r.p.w.duin@prtools.org
27% Faculty EWI, Delft University of Technology
28% P.O. Box 5031, 2600 GA Delft, The Netherlands
29
30function [w,r] = featself(a,crit,ksel,t,fid)
31                 
32  prtrace(mfilename);
33       
34  if (nargin < 2) | isempty(crit)
35    prwarning(2,'no criterion specified, assuming NN');
36    crit = 'NN';
37  end
38  if (nargin < 3) | isempty(ksel)
39    ksel = 0;
40  end
41  if (nargin < 4)
42    prwarning(3,'no tuning set supplied (risk of overfit)');
43    t = [];
44  end
45        if (nargin < 5)
46                fid = [];
47        end
48       
49        if nargin == 0 | isempty(a)
50                % Create an empty mapping:
51                w = mapping(mfilename,{crit,ksel,t});
52        else   
53                [m,k] = size(a);
54                for j1=1:k
55                        for j2=j1+1:k
56                                J(j1,j2) = feateval(a(:,[j1,j2]),crit,t);
57                        end
58                end
59                w = pairs_sort(J, ksel);
60                w = featsel(k,w);
61                prprogress(fid,'featself  finished\n')
62        end
63        w = setname(w,'Pairwise FeatSel');
64
65return
66
67function mn = pairs_sort(J, MAX_F)     
68% Artsiom Harol
69        if MAX_F == 0, MAX_F = size(J,1); end
70  ind2=find(J(:));
71  a=J(ind2);
72  [b,ind_sort]=sort(-a);
73  %ind_sort=(flipud(ind_sort'))';
74  ind2=ind2(ind_sort);
75  [m,n]=ind2sub(size(J),ind2);
76 
77  mn=[m(:)';n(:)'];
78 % mn=[m(1:MAX_F)';n(1:MAX_F)'];
79  [umn] = unique(mn);
80  for k=1:length(umn)
81    ind = find(umn(k) == mn);
82    mn(ind(2:end)) = [];
83  end 
84  mn = mn(1:MAX_F)';
85return; 
Note: See TracBrowser for help on using the repository browser.