]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/classify.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / classify.m
1 function [CLASS,ERR,POSTERIOR,LOGP,COEF]=classify(sample,training,classlabel,TYPE)
2 % CLASSIFY classifies sample data into categories 
3 % defined by the training data and its group information 
4 %
5 %  CLASS = classify(sample, training, group) 
6 %  CLASS = classify(sample, training, group, TYPE) 
7 %  [CLASS,ERR,POSTERIOR,LOGP,COEF] = CLASSIFY(...) 
8 %
9 %  CLASS contains the assigned group. 
10 %  ERR is the classification error on the training set weighted by the 
11 %       prior propability of each group. 
12 %
13 %  The same classifier as in TRAIN_SC are supported. 
14 %
15 % ATTENTION: no cross-validation is applied, therefore the 
16 %    classification error is too optimistic (overfitting). 
17 %    Use XVAL instead to obtain cross-validated performance. 
18
19 % see also: TRAIN_SC, TEST_SC, XVAL
20 %
21 % References: 
22 % [1] R. Duda, P. Hart, and D. Stork, Pattern Classification, second ed. 
23 %       John Wiley & Sons, 2001. 
24
25 %       $Id$
26 %       Copyright (C) 2008,2009 by Alois Schloegl <alois.schloegl@gmail.com>    
27 %       This function is part of the NaN-toolbox
28 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
29
30 % This program is free software; you can redistribute it and/or
31 % modify it under the terms of the GNU General Public License
32 % as published by the Free Software Foundation; either version 3
33 % of the  License, or (at your option) any later version.
34
35 % This program is distributed in the hope that it will be useful,
36 % but WITHOUT ANY WARRANTY; without even the implied warranty of
37 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38 % GNU General Public License for more details.
39
40 % You should have received a copy of the GNU General Public License
41 % along with this program; if not, write to the Free Software
42 % Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
43
44 if nargin<4
45         TYPE = 'linear';
46 end; 
47
48 if strcmp(TYPE,'linear')
49         TYPE = 'LDA';
50 elseif strcmp(TYPE,'quadratic')
51         TYPE = 'QDA2'; % result is closer to Matlab 
52 elseif strcmp(TYPE,'diagLinear')
53         TYPE = 'NBC';
54 elseif strcmp(TYPE,'diagQuadratic')
55         TYPE = 'NBC';
56 elseif strcmp(TYPE,'mahalanobis')
57         TYPE = 'MDA';
58 end;    
59
60 [group,I,classlabel] = unique(classlabel);
61
62 CC = train_sc(training,classlabel,TYPE); 
63 R  = test_sc(CC,sample);
64 CLASS = group(R.classlabel); 
65
66 if nargout>1,
67         R  = test_sc(CC,training,[],classlabel);
68         ERR = 1-R.ACC; 
69 end; 
70
71 if nargout>2,
72         warning('output arguments POSTERIOR,LOGP and COEF not supported')
73         POSTERIOR = [];
74         LOGP = [];
75         COEF = [];
76 end; 
77