source: distools/kcenterm.m @ 41

Last change on this file since 41 was 10, checked in by bduin, 14 years ago
File size: 2.0 KB
Line 
1%KCENTERM Kernel Weighted Centering Mapping
2%
3%   W = kcenterm(K,V)
4%
5% INPUT
6%   K   NxN kernel or similarity matrix (dataset)
7%   V   'C' (default) or Nx1 weight vector of nonnegative values; sum(V)=1
8%
9% OUTPUT
10%   W   Kernel weighted centering mapping
11%
12% DEFAULT
13%   V   = 'C';
14%
15% DESCRIPTION
16% Defines a mapping that centers the given NxN kernel matrix K:=K(X,X)
17% such that the weighted mean coincides with the origin in the vector space
18% induced by K. The nonnegative weights of the mean are defined by an
19% Nx1 vector V; sum(V) = 1. V = 'C' stands for V=ones(N,1)/N, hence
20% the true centering.
21%
22% The mapping works with both positive (semi-)definite and indefinite
23% kernels. V can be applied to a new MxN kernel Knew:=K(Xnew,X).
24%
25% SEE ALSO
26% KPCA, MAPPINGS, DATASETS
27%
28
29% Copyright: Ela Pekalska, ela.pekalska@googlemail.com
30% Faculty EWI, Delft University of Technology and
31% School of Computer Science, University of Manchester
32%
33
34function [V,KK] = kcenterm(K,v)
35
36if nargin < 2 | isempty(v)
37  v = 'c';
38end
39
40if nargin < 1 | isempty(K)
41   V = mapping(mfilename);
42   V = setname(V,'kcenterm');
43   return
44end
45
46
47if (isdataset(K) | isa(K,'double'))
48  if ismapping(v)
49
50    [m,n] = size(K);
51    pars  = getdata(v);
52
53    v   = pars{1};
54    Kwm = pars{2};
55
56    H  = eye(n) - v*ones(1,n);
57    V  = (K - repmat(Kwm',m,1))* H;
58    return;
59  end
60end
61
62
63
64lab      = getlab(K);
65lablist  = getlablist(K);
66[n,m,c]  = getsize(K);
67
68tol = 1e-12;
69if ~issym(K,tol),
70  error('Kernel matrix K should be symmetric.')
71end
72
73if v == 'c',
74  v = ones(n,1)/n;
75end
76
77if length(v)==1
78  l = intersect(v,1:n)
79  v = zeros(n,1);
80  v(l) = 1;
81end
82
83if length(v) ~= n,
84  error('V has a wrong size.');
85end
86
87if any(v) < 0 | any(v) > 1,
88  error('V should have elements in [0,1].');
89end
90
91if abs(sum(v) - 1) > tol
92  error('sum(V) ~= 1.');
93end
94
95
96% Center K such that the weighted mean coincides with the origin
97Kwm  = K*v;
98if nargout > 1
99  H  = eye(n) - v*ones(1,n);
100  KK = H * K * H;
101end
102
103V = mapping(mfilename,'trained',{v,Kwm},[],m,m);
104V = setname(V,'kcenterm');
105return
Note: See TracBrowser for help on using the repository browser.