source: distools/dissimt.m

Last change on this file was 98, checked in by bduin, 10 years ago
File size: 3.2 KB
Line 
1%DISSIMT  Fixed DISsimilarity-SIMilarity transformation
2%
3%    W = DISSIMT([],TYPE,PAR)
4%           OR
5%    T = DISSIMT(P,TYPE,PAR)
6%
7% INPUT
8%   P     NxN or NxM proximity matrix or dataset
9%   TYPE  Type of the transformation that acts on proximity data
10%         (optional; default: 'POW'):
11%         'I',    'identity':   P
12%         'SCALE', 'scale':             P ./ PAR
13%         'NEG',  'negative':   -P
14%         'NEG2', 'negative2':  -P.^2
15%         'REV',  'reverse':    1./(PAR + P)
16%         'REV2', 'reverse':    1./(PAR^2 + P.^2)
17%         'D2S',  'S2D':        1-P
18%         'D2SSQ','S2DSQ':      sqrt(1-P)
19%         'POW',  'power':      P.^PAR
20%         'EXP',  'exponent':   exp(-P./PAR)
21%         'EXP2', 'exponent2':  exp((-P.^2)./(PAR^2))
22%         'GAUSS':              exp((-P.^2)./(2*PAR^2))
23%         'LOG',  'logarithm':  log(P/PAR)
24%         'NLOG', 'neglog':     -log((P+1)./PAR)
25%         'NLOG2','neglog2':    -log((P.^2+1)./PAR^2)
26%         'SIGM', 'sigmoid':    2./(1+exp(-P./PAR))-1
27%         'SIGM2','sigmoid2':   2./(1+exp(-(P.^2)./PAR^2))-1
28%         'SIM2DIS'
29%         'DIS2SIM'
30%   PAR   Parameter, PAR > 0 (optional; default: 1)
31%
32% OUTPUT
33%   W     Fixed mapping
34%   T     NxN or NxM proximity matrix or dataset
35%
36% DESCRIPTION
37% A fixed mapping that transforms proximity data. Note that in some cases
38% similarity is transformed into dissimilarity, or vice versa.
39% If a proximity data P is supplied, the data are directly mapped, so there
40% is no mapping defined. Hence, DISSIMT([],TYPE,PAR) is a mapping, while
41% DISSIMT(P,TYPE,PAR) returns data.
42%
43% DEFAULT
44%   PAR = 1
45%
46
47% Copyright: Elzbieta Pekalska, ela.pekalska@googlemail.com
48% Faculty EWI, Delft University of Technology and
49% School of Computer Science, University of Manchester
50
51
52function W = dissimt(D,type,p)
53if nargin < 3,
54  p = 1;
55end
56if nargin < 2,
57  type = 'pow';
58end
59if nargin == 0 | isempty(D)
60  W = prmapping(mfilename,'fixed',{type,p});
61  W = setname(W,'Fixed proximity transformation');
62  return
63end
64
65if p <= 0 or p == inf,
66  error('Wrong PAR.');
67end
68
69switch lower(type)
70case {'i','identity'}
71   W = D;
72case {'scale'}
73   W = D./p;
74case {'neg','negative'}
75   W = -D;
76case {'neg2','negative2'}
77   W = -D.^2;
78case {'rev','reverse'}
79   W = 1./(p+D);
80case {'rev2','reverse2'}
81   W = 1./(p^2+D.^2);
82case {'d2s','s2d'}
83   if any(D > 1 | D < 0),
84     error('Proximity data should be in [0,1].')
85   end
86   W = 1-D;
87case {'d2ssq','s2dsq'}
88   if any(D > 1 | D < 0),
89     error('Proximity data should be in [0,1].')
90   end
91   W = sqrt(1-D);
92case {'pow','power'}
93   W = D.^p;
94case {'exp','exponent'}
95   W = exp(-D/p);
96case {'exp2','exponent2'}
97   W = exp(-D.^2/p^2);
98case {'gauss'}
99   W = exp(-D.^2/(2*p^2));
100case {'log','logarithm'}
101   W = log(D/p);
102case {'nlog','neglog'}
103   W = -log((D+1)/p);
104case {'nlog2','neglog2'}
105   W = -log((D.^2+1)/p^2);
106case {'sigm','sigmoid'}
107   W = 2./(1+exp(-D/p))-1;
108case {'sigm2','sigmoid2'}
109   W = 2./(1+exp(-D.^2/p^2))-1;
110case {'dis2sim'}
111        m = size(D,1);
112        one = ones(m,1);
113        H = eye(m) - one*one'/m;
114        W = -H*D.^2*H/2;
115  W = setdata(D,W);
116case {'sim2dis'}
117        m = size(D,1);
118        DD = diag(+D);
119        DD = +(sqrt(-D-D'+repmat(DD,1,m)+repmat(DD',m,1)));
120        W = setdata(D,real(DD));
121otherwise
122   error('Transformation is unknown.');
123end
124return
Note: See TracBrowser for help on using the repository browser.