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
5 % CLASS = classify(sample, training, group)
6 % CLASS = classify(sample, training, group, TYPE)
7 % [CLASS,ERR,POSTERIOR,LOGP,COEF] = CLASSIFY(...)
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.
13 % The same classifier as in TRAIN_SC are supported.
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.
19 % see also: TRAIN_SC, TEST_SC, XVAL
22 % [1] R. Duda, P. Hart, and D. Stork, Pattern Classification, second ed.
23 % John Wiley & Sons, 2001.
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/
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.
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.
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.
48 if strcmp(TYPE,'linear')
50 elseif strcmp(TYPE,'quadratic')
51 TYPE = 'QDA2'; % result is closer to Matlab
52 elseif strcmp(TYPE,'diagLinear')
54 elseif strcmp(TYPE,'diagQuadratic')
56 elseif strcmp(TYPE,'mahalanobis')
60 [group,I,classlabel] = unique(classlabel);
62 CC = train_sc(training,classlabel,TYPE);
63 R = test_sc(CC,sample);
64 CLASS = group(R.classlabel);
67 R = test_sc(CC,training,[],classlabel);
72 warning('output arguments POSTERIOR,LOGP and COEF not supported')