[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 | |
---|
| 28 | function W = discc(d,par) |
---|
| 29 | % set default leave-one-out |
---|
| 30 | if nargin < 2 |
---|
| 31 | par = 'loo'; |
---|
| 32 | end |
---|
| 33 | % empty call, to handle d*knnd, or d*knnd([],par) |
---|
| 34 | if nargin < 1 | isempty(d) |
---|
| 35 | if isstr(par) % untrained classifier, par = 'loo' or 'all' |
---|
| 36 | W = mapping('discc',par); |
---|
| 37 | else % fixed classifier, par = knn |
---|
| 38 | W = mapping('discc','fixed',par); |
---|
| 39 | end |
---|
| 40 | return |
---|
| 41 | end |
---|
| 42 | |
---|
| 43 | [nlab,lablist,m,k,c,p,featlist] = dataset(d); |
---|
| 44 | [clab,classlist] = renumlab(featlist); |
---|
| 45 | c = size(classlist,1); |
---|
| 46 | [cl,nc] = renumlab(classlist,lablist); |
---|
| 47 | if size(nc,1) > c |
---|
| 48 | error('Object labels do not match representation set') |
---|
| 49 | end |
---|
| 50 | |
---|
| 51 | if 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 |
---|
| 80 | w = +(dataset(s,2-(t==r))*loglc); |
---|
| 81 | W = mapping('discc',w,lablist,k,c,1); |
---|
| 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 |
---|
| 94 | w = +(dataset(s,2-(t==r))*loglc); |
---|
| 95 | W = mapping('discc',w,lablist,k,c,1); |
---|
| 96 | else |
---|
| 97 | error(['Unknown option ''' par '''']) |
---|
| 98 | end |
---|
| 99 | |
---|
| 100 | else |
---|
| 101 | |
---|
| 102 | % testing for given mapping |
---|
| 103 | |
---|
| 104 | if isa(par,'mapping') |
---|
| 105 | w = +par; |
---|
| 106 | W = d*w(1) + w(2); |
---|
| 107 | else |
---|
| 108 | error('Second parameter should be string or mapping') |
---|
| 109 | end |
---|
| 110 | end |
---|