source: distools/discc.m @ 157

Last change on this file since 157 was 79, checked in by bduin, 11 years ago
File size: 2.8 KB
RevLine 
[10]1%DISCC Dissimilarity based combining classifier
2%
3%       W = discc(D,par)
4%
5% If D is a square dissimilarity matrix then the distances to each
6% representation object are used for building a classifier such that
7% sigmoid(a*d+b), can be used to estimate the posterior probability of a
8% new object at distance d. The scalar parameters a and b are optimized
9% over the training set using a maximum likelihood estimator.
10% W is a set of parallel classifiers such that D*W*classc yields the posterior
11% probabilities. Note that D*W*maxc yields the same classification results as
12% the NN classifier.
13%
14% par = 'loo' - (default) compute leave-one-out optimization for a and b.
15%               it is assumed that the first objects in the training set
16%               constitute the representation set.
17%       'all' - include all dissimilarities for optimization of k
18%               (representation set should not be included in training set)
19%
20% See also mappings, datasets, classc, classd, testd, knnd
21%
22% $Id: discc.m,v 1.2 2001/07/10 16:35:58 pavel Exp $
23
24% Copyright: R.P.W. Duin, duin@ph.tn.tudelft.nl
25% Faculty of Applied Physics, Delft University of Technology
26% P.O. Box 5046, 2600 GA Delft, The Netherlands
27
28function W = discc(d,par)
29                        % set default leave-one-out
30if nargin < 2
31        par = 'loo';
32end
33                        % empty call, to handle d*knnd, or d*knnd([],par)
34if nargin < 1 | isempty(d)
35        if isstr(par)   % untrained classifier, par = 'loo' or 'all'
[79]36                W = prmapping('discc',par);
[10]37        else                    % fixed classifier, par = knn
[79]38                W = prmapping('discc','fixed',par);
[10]39        end
40        return
41end
42
[79]43[nlab,lablist,m,k,c,p,featlist] = prdataset(d);
[10]44[clab,classlist] = renumlab(featlist);
45c = size(classlist,1);
46[cl,nc] = renumlab(classlist,lablist);
47if size(nc,1) > c
48        error('Object labels do not match representation set')
49end
50
51if isstr(par)
52       
53        % training (find parameters a and b)
54                       
55        if strcmp(par,'loo')
56                n = k*(k-1) + (m-k)*k;
57                s = zeros(n,1);
58                t = zeros(n,1);
59                r = zeros(n,1);
60                K = 0;
61                for j=1:k
62                        if j == 1
63                                J = 2:k;
64                        elseif j < k
65                                J = [1:(j-1) j+1:k];
66                        else
67                                J = [1:k-1];
68                        end
69                        s(K+1:K+k-1) = d(j,J)';
70                        t(K+1:K+k-1) = repmat(nlab(j),k-1,1);
71                        r(K+1:K+k-1) = nlab(J);
72                        K = K+k-1;
73                end
74                for j=k+1:m
75                        s(K+1:K+k) = d(j,:)';
76                        t(K+1:K+k) = repmat(nlab(j),k,1);
77                        r(K+1:K+k) = nlab(1:k);
78                        K = K+k;
79                end
[79]80                w = +(prdataset(s,2-(t==r))*loglc);
81                W = prmapping('discc',w,lablist,k,c,1);
[10]82        elseif strcmp(par,'all')
83                n = m*k;
84                s = zeros(n,1);
85                t = zeros(n,1);
86                r = zeros(n,1);
87                K = 0; 
88                for j=1:m
89                        s(K+1:K+k) = d(j,:)';
90                        t(K+1:K+k) = repmat(nlab(j),k,1);
91                        r(K+1:K+k) = nlab(1:k);
92                        K = K+k;
93                end
[79]94                w = +(prdataset(s,2-(t==r))*loglc);
95                W = prmapping('discc',w,lablist,k,c,1);
[10]96        else
97                error(['Unknown option ''' par ''''])
98        end
99       
100else
101
102        % testing for given mapping
103               
[79]104        if isa(par,'prmapping')
[10]105                w = +par;
106                W = d*w(1) + w(2);
107        else
108                error('Second parameter should be string or mapping')
109        end
110end
Note: See TracBrowser for help on using the repository browser.