-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclfLda.m
52 lines (47 loc) · 1.42 KB
/
clfLda.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
% Create a Linear Discriminant Analysis (LDA) classifier.
%
% Same algorithm as matlab's function 'classify' (in the statistics
% toolbox). Nice to have in form that actually stores a model that can be
% applied multiple times. For the meaning and usage of prior and type see
% classify.m
%
% USAGE
% clf = clfLda( p, [type], [prior] )
%
% INPUTS
% p - data dimension
% type - ['linear'] 'linear', 'quadratic', 'mahalanobis'
% prior - [] prior to use
%
% OUTPUTS
% clf - an LDA model ready to be trained (see clfLdaTrain)
%
% EXAMPLE
%
% See also NFOLDXVAL, CLASSIFY, CLFLDATRAIN, CLFLDAFWD
% Piotr's Image&Video Toolbox Version 2.0
% Written and maintained by Piotr Dollar pdollar-at-cs.ucsd.edu
% Please email me if you find bugs, or have suggestions or questions!
function clf = clfLda( p, type, prior )
if( nargin<3 ); prior=[]; end
%%% get type
if( nargin < 2 || isempty(type) )
type = 1; % 'linear'
elseif ischar(type)
i = strmatch(lower(type), {'linear','quadratic','mahalanobis'});
if( length(i)>1 );
error('Ambiguous value for TYPE: %s.', type);
elseif( isempty(i));
error('Unknown value for TYPE: %s.', type);
end;
type = i;
else
error('TYPE must be a string.');
end
%%% save clfLda parameters
clf.prior = prior;
clf.p = p;
clf.type = 'lda';
clf.clfLdaType = type;
clf.funTrain = @clfLdaTrain;
clf.funFwd = @clfLdaFwd;