1 | %DISNORM Normalization of a dissimilarity matrix |
---|
2 | % |
---|
3 | % V = DISNORM(D,OPT) |
---|
4 | % F = E*V |
---|
5 | % |
---|
6 | % INPUT |
---|
7 | % D NxN dissimilarity matrix or dataset, which sets the norm |
---|
8 | % E Matrix to be normalized, e.g. D itself |
---|
9 | % OPT 'max' : maximum dissimilarity is set to 1 by global rescaling |
---|
10 | % 'mean': average dissimilarity is set to 1 by global rescaling (default) |
---|
11 | % |
---|
12 | % OUTPUT |
---|
13 | % V Fixed mapping |
---|
14 | % F Normalized dissimilarity data |
---|
15 | % |
---|
16 | % DEFAULT |
---|
17 | % OPT = 'mean' |
---|
18 | % |
---|
19 | % DESCRIPTION |
---|
20 | % Operation on dissimilarity matrices, like the computation of classifiers |
---|
21 | % in dissimilarity space, may depend on the scaling of the dissimilarities |
---|
22 | % (a single scalar for the entire matrix). This routine computes a scaling |
---|
23 | % for a giving matrix, e.g. a training set and applies it to other |
---|
24 | % matrices, e.g. the same training set or based on a test set. |
---|
25 | |
---|
26 | % Copyright: Elzbieta Pekalska, ela.pekalska@googlemail.com |
---|
27 | % Faculty EWI, Delft University of Technology and |
---|
28 | % School of Computer Science, University of Manchester |
---|
29 | |
---|
30 | |
---|
31 | function V = disnorm(D,opt) |
---|
32 | if nargin < 2, |
---|
33 | opt = 'mean'; |
---|
34 | end |
---|
35 | |
---|
36 | if nargin == 0 | isempty(D) |
---|
37 | V = mapping(mfilename,{opt}); |
---|
38 | V = setname(V,'Disnorm'); |
---|
39 | return |
---|
40 | end |
---|
41 | |
---|
42 | if ~isdataset(D) |
---|
43 | D = dataset(D,1); |
---|
44 | D = setfeatlab(D,getlabels(D)); |
---|
45 | end |
---|
46 | |
---|
47 | %DEFINE mapping |
---|
48 | if isstr(opt) |
---|
49 | % discheck(D); |
---|
50 | opt = lower(opt); |
---|
51 | if strcmp(opt,'mean') |
---|
52 | n = size(D,1); |
---|
53 | m = sum(sum(+D))/(n*(n-1)); |
---|
54 | elseif strcmp(opt,'max') |
---|
55 | m = max(D(:)); |
---|
56 | else |
---|
57 | error('Wrong OPT.') |
---|
58 | end |
---|
59 | if nargout > 1 |
---|
60 | D = D./m; |
---|
61 | end |
---|
62 | V = mapping(mfilename,'trained',{m},[],size(D,2),size(D,2)); |
---|
63 | return; |
---|
64 | end |
---|
65 | |
---|
66 | |
---|
67 | % APPLY mapping |
---|
68 | if ismapping(opt) |
---|
69 | opt = getdata(opt,1); |
---|
70 | V = D./opt; |
---|
71 | return; |
---|
72 | end |
---|
73 | |
---|