source: distools/pe_kernelm.m @ 25

Last change on this file since 25 was 10, checked in by bduin, 14 years ago
File size: 2.9 KB
Line 
1%PE_KERNELM Pseudo-Euclidean kernel mapping
2%
3%    K = PE_KERNELM(A,B)
4%    W = B*PE_KERNELM
5%    W = PE_KERNELM([],B)
6%    K = A*W
7%
8% INPUT
9%   A     Pseudo-Euclidean dataset of size NxK
10%   B     Pseudo-Euclidean dataset of size MxK
11%
12% OUTPUT
13%   W     PE mapping
14%   K     Kernel matrix, size [N M]
15%
16% DESCRIPTION
17% Computation of a kernel matrix in a pseudo-Euclidean space. The signature
18% of this space should be stored in the datasets A and B, see SETSIG.
19% K = A*J*B', where J is a diagonal matrix with 1's, followed by -1's.
20% J = diag ([ONES(SIG(1),1);  -ONES(SIG(2),1)]);
21% The two-element vector SIG stores the signature of the space. This is the
22% number of 'positive' dimensions, followed by the number of 'negative'
23% dimensions. It is computed by a pseudo-Eucledean embedding, e.g. PSEM,
24% and stored in the related mapping and datasets that are projected in this
25% space.
26%
27% The resulting kernel matrix K is indefinite in case A == B. This routine
28% may be used in support vector routines and other kernelized procedures.
29% Note that most of such routines are not optimal for indefinite kernels.
30%
31% EXAMPLE
32% a = gendatb;                  % generate dataset
33% d = a*proxm(a,'m',1);         % compute L1 distance matrix
34% w = psem(d);                  % embed in PE space
35% b = d*w;                      % project data in this space
36% [trainset testset] = gendat(b,0.5);     % split in trainset and testset
37% ktrain = pe_kernelm(trainset,trainset); % compute train kernel
38% w = svc(ktrain,0);            % compute SV classifier
39% ktest = pe_kernelm(testset,trainset);   % compute test kernel
40% ktest*w*testc                 % inspect error of testset   
41%
42% SEE ALSO
43% DATASETS, MAPPINGS, PE_EM, PE_DISTM
44
45% Copyright: R.P.W. Duin, r.p.w.duin@prtools.org
46% Faculty EWI, Delft University of Technology
47% P.O. Box 5031, 2600 GA Delft, The Netherlands
48
49function w = pe_kernelm(a,b);
50
51  if nargin < 2, b = []; end
52  mapname = 'PE kernel mapping';
53        if (nargin < 1) | (isempty(a) & nargin == 1) 
54                % Definition: pe kernel mapping.
55                w = mapping(mfilename,{b});
56                w = setname(w,mapname);
57  elseif isempty(a)
58    w = mapping(mfilename,'trained',b,getlab(b),size(b,2),size(b,1));
59                w = setname(w,mapname);
60  elseif isdataset(a) & ~isempty(a)
61    if isempty(b)   % store a as rep set, 'training'
62      w = mapping(mfilename,'trained',a,getlab(a),size(a,2),size(a,1));
63                  w = setname(w,mapname);
64    elseif isdataset(b); % compute kernel between a and b
65      w = pe_mtimes(a,b');
66    elseif ismapping(b)
67      if isuntrained(b) % nothing stored yet, do it now, a is rep set
68        w = mapping(mfilename,'trained',a,getlab(a),size(a,2),size(a,1));
69                    w = setname(w,mapname);
70      else % we have already a rep set: compute kernel matrix
71        b = getdata(b);
72        w = pe_mtimes(a,b');
73      end
74    else
75      error('Second parameter should be dataset')
76    end
77   
78  else  % may be double ???
79    a = dataset(a);
80    w = feval(mfilename,a,b);
81   
82  end
83 
84return
85     
86     
Note: See TracBrowser for help on using the repository browser.