source: distools/disnorm.m @ 16

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

disnorm updated

File size: 1.2 KB
Line 
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
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
20% Copyright: Elzbieta Pekalska, ela.pekalska@googlemail.com
21% Faculty EWI, Delft University of Technology and
22% School of Computer Science, University of Manchester
23
24
25function V = disnorm(D,opt)
26if nargin < 2,
27        opt = 'mean';
28end
29
30if nargin == 0 | isempty(D)
31  V = mapping(mfilename,{opt});
32  V = setname(V,'Disnorm');
33  return
34end
35
36if ~isdataset(D)
37        D = dataset(D,1);
38        D = setfeatlab(D,getlabels(D));
39end
40
41%DEFINE mapping
42if isstr(opt)
43        discheck(D);
44        opt = lower(opt);
45        if strcmp(opt,'mean')
46                n = size(D,1);
47                m = sum(sum(+D))/(n*(n-1));
48        elseif strcmp(opt,'max')
49                m = max(D(:));
50        else
51                error('Wrong OPT.')
52        end
53        if nargout > 1
54                D = D./m;
55        end     
56    V = mapping(mfilename,'trained',{m},[],size(D,2),size(D,2));
57        return;
58end
59
60
61% APPLY mapping
62if ismapping(opt)
63        opt = getdata(opt,1);
64        V = D./opt;
65        return;
66end                     
67       
Note: See TracBrowser for help on using the repository browser.