[10] | 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 | |
---|
| 52 | function W = dissimt(D,type,p) |
---|
| 53 | if nargin < 3, |
---|
| 54 | p = 1; |
---|
| 55 | end |
---|
| 56 | if nargin < 2, |
---|
| 57 | type = 'pow'; |
---|
| 58 | end |
---|
| 59 | if nargin == 0 | isempty(D) |
---|
| 60 | W = mapping(mfilename,'fixed',{type,p}); |
---|
| 61 | W = setname(W,'Fixed proximity transformation'); |
---|
| 62 | return |
---|
| 63 | end |
---|
| 64 | |
---|
| 65 | if p <= 0 or p == inf, |
---|
| 66 | error('Wrong PAR.'); |
---|
| 67 | end |
---|
| 68 | |
---|
| 69 | switch lower(type) |
---|
| 70 | case {'i','identity'} |
---|
| 71 | W = D; |
---|
| 72 | case {'scale'} |
---|
| 73 | W = D./p; |
---|
| 74 | case {'neg','negative'} |
---|
| 75 | W = -D; |
---|
| 76 | case {'neg2','negative2'} |
---|
| 77 | W = -D.^2; |
---|
| 78 | case {'rev','reverse'} |
---|
| 79 | W = 1./(p+D); |
---|
| 80 | case {'rev2','reverse2'} |
---|
| 81 | W = 1./(p^2+D.^2); |
---|
| 82 | case {'d2s','s2d'} |
---|
| 83 | if any(D > 1 | D < 0), |
---|
| 84 | error('Proximity data should be in [0,1].') |
---|
| 85 | end |
---|
| 86 | W = 1-D; |
---|
| 87 | case {'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); |
---|
| 92 | case {'pow','power'} |
---|
| 93 | W = D.^p; |
---|
| 94 | case {'exp','exponent'} |
---|
| 95 | W = exp(-D/p); |
---|
| 96 | case {'exp2','exponent2'} |
---|
| 97 | W = exp(-D.^2/p^2); |
---|
| 98 | case {'gauss'} |
---|
| 99 | W = exp(-D.^2/(2*p^2)); |
---|
| 100 | case {'log','logarithm'} |
---|
| 101 | W = log(D/p); |
---|
| 102 | case {'nlog','neglog'} |
---|
| 103 | W = -log((D+1)/p); |
---|
| 104 | case {'nlog2','neglog2'} |
---|
| 105 | W = -log((D.^2+1)/p^2); |
---|
| 106 | case {'sigm','sigmoid'} |
---|
| 107 | W = 2./(1+exp(-D/p))-1; |
---|
| 108 | case {'sigm2','sigmoid2'} |
---|
| 109 | W = 2./(1+exp(-D.^2/p^2))-1; |
---|
| 110 | case {'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 | case {'sim2dis'} |
---|
| 116 | m = size(D,1); |
---|
| 117 | DD = diag(+D); |
---|
| 118 | DD = +(sqrt(-D-D'+repmat(DD,1,m)+repmat(DD',m,1))); |
---|
| 119 | W = setdata(D,real(DD)); |
---|
| 120 | otherwise |
---|
| 121 | error('Transformation is unknown.'); |
---|
| 122 | end |
---|
| 123 | return |
---|