source: distools/disnorm.m @ 70

Last change on this file since 70 was 18, checked in by bduin, 14 years ago

clevald, parzenddc, parzend_map and kem added

File size: 1.6 KB
RevLine 
[10]1%DISNORM Normalization of a dissimilarity matrix
2%
[18]3%       V = DISNORM(D,OPT)
[10]4%   F = E*V
5%
6% INPUT
7%   D    NxN dissimilarity matrix or dataset, which sets the norm
[18]8%   E    Matrix to be normalized, e.g. D itself
[10]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%
[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.
[10]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
31function V = disnorm(D,opt)
32if nargin < 2,
33        opt = 'mean';
34end
35
36if nargin == 0 | isempty(D)
37  V = mapping(mfilename,{opt});
38  V = setname(V,'Disnorm');
39  return
40end
41
[16]42if ~isdataset(D)
43        D = dataset(D,1);
44        D = setfeatlab(D,getlabels(D));
45end
46
[10]47%DEFINE mapping
48if isstr(opt)
[18]49%       discheck(D);
[10]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;
64end
65
66
67% APPLY mapping
68if ismapping(opt)
69        opt = getdata(opt,1);
70        V = D./opt;
71        return;
72end                     
73       
Note: See TracBrowser for help on using the repository browser.