source: distools/disspaces.m @ 10

Last change on this file since 10 was 10, checked in by bduin, 14 years ago
File size: 2.9 KB
RevLine 
[10]1%DISSPACES Compute various spaces out of a dissimilarity matrix
2%
3%   [X,E,W] = DISSPACES(D,W,FLAG)
4%
5% INPUT
6%   D    Dataset, square dissimilarity matrix, size NxN
7%   W    Pseudo-Euclidean mapping, W = PE_EM(D)
8%        signature [P,Q], see PE_EM
9%   FLAG 1 normalize distances by DISNORM (default)
10%        0 do not normalize
11%
12% OUTPUT
13%   X   Cell array of five datasets related to embedded 'spaces'
14%       - Nx(N-1) PE space
15%       - Nx(N-1) Associated space
16%       - NxP     Positive space
17%       - NxQ     Negative space
18%       - Nx(N-1) Corrected space
19%   E   Cell array of five datasets related to dissimilarity 'spaces'.
20%       These are the NxN (Pseudo-)Euclidean dissimilarity matrices
21%       computed from the above embedded spaces
22%   W   Cell array with the mappings from D to E
23%
24% SEE ALSO
25% PE_EM
26
27% Copyright: R.P.W. Duin, r.p.w.duin@prtools.org
28% Faculty EWI, Delft University of Technology
29% P.O. Box 5031, 2600 GA Delft, The Netherlands
30
31function [X,D,W] = disspaces(d,wpe,normalize)
32
33        if nargin < 3, normalize = 1; end
34  if nargin < 2 | isempty(wpe)
35                wpe = pe_em(d);
36        end
37       
38  % Pseudo-Euclidean space
39  xpe = d*wpe;
40  xpe = setname(xpe,'PE Space');
41  dis = setname(d,'Dis Space');
42  if normalize, dis = dis*disnorm(dis); end
43  sig = getsig(wpe);
44
45  % Associated space, neglect signature
46  was = wpe*setsig;
47  xas = d*was;
48  xas = setname(xas,'Ass Space');
49  das = sqrt(distm(xas));
50  if normalize, das = das*disnorm(das); end
51  das = setname(das,'Ass Dis Space');
52 
53  % Positive space, use sig(1) features only
54  wps = wpe(:,1:sig(1))*setsig;
55  xps = d*wps;
56  xps = setname(xps,'Pos Space');
57  dps = sqrt(distm(xps));
58  if normalize, dps = dps*disnorm(dps); end
59  dps = setname(dps,'Pos Dis Space');
60 
61  % Negative space, use sig(2) features only (start at sig(1)+1)
62        if sig(2) == 0
63                xns = setdat(d,zeros(size(d,1),1));
64                dns = setdat(d,zeros(size(d,1),size(d,1)));
65        else
66                wns = wpe(:,sig(1)+1:end)*setsig;
67                xns = d*wns;
68                dns = sqrt(distm(xns));
69                if normalize, dns = dns*disnorm(dns); end
70        end
71        xns = setname(xns,'Neg Space');
72        dns = setname(dns,'Neg Dis Space');
73 
74  % Corrected space (add off-diagonal constant)
75  L = getdata(wpe,'eval');
76  m = size(d,1);
77  dcs = sqrt(d.^2+2*(-min(L))*(ones(m)-eye(m)));
78  %dcs = dcs*disnorm(dcs);
79  if normalize, dcs = dcs./meanstd(dcs); end
80  dcs = setname(dcs,'Cor Dis Space');
81  xcs = dcs*pe_em(dcs); % compute space fom dis mat
82  xcs = setname(xcs,'Cor Space');
83  if nargout > 2 % save some time
84    wcs = affine(prinv(+d)*(+xcs),[],d); % OK for original data
85        end
86 
87  X = {xpe,xas,xps,xns,xcs};
88  D = {dis,das,dps,dns,dcs};
89  if nargout > 2 % save some time
90    W = {wpe,was,wps,wns,wcs};
91        end
92       
93       
94function [u,s] = meanstd(d)
95
96  m = size(d,1);
97  d = +d;
98  d = reshape(d(1:end-1),m+1,m-1); % remove all zeros on diagonal
99  d = d(2:m+1,:);
100  u = mean(d(:));
101  s = std(d(:));
Note: See TracBrowser for help on using the repository browser.