Home > utils > prt_centre_kernel.m

prt_centre_kernel

PURPOSE ^

This function centres the kernel matrix, respecting the independence of

SYNOPSIS ^

function [C,Cs,Css] = prt_centre_kernel(K, Ks, Kss)

DESCRIPTION ^

 This function centres the kernel matrix, respecting the independence of
 training and test partitions. See Shawe-Taylor and Cristianini for
 background on this approach.

 Shawe-Taylor, J. and Cristianini, N. (2004). Kernel methods for Pattern
 analysis. Cambridge University Press.
__________________________________________________________________________
 Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [C,Cs,Css] = prt_centre_kernel(K, Ks, Kss)
0002 
0003 % This function centres the kernel matrix, respecting the independence of
0004 % training and test partitions. See Shawe-Taylor and Cristianini for
0005 % background on this approach.
0006 %
0007 % Shawe-Taylor, J. and Cristianini, N. (2004). Kernel methods for Pattern
0008 % analysis. Cambridge University Press.
0009 %__________________________________________________________________________
0010 % Copyright (C) 2011 Machine Learning & Neuroimaging Laboratory
0011 
0012 % Written by D. Hardoon, A. Marquand and J. Mourao-Miranda
0013 % Id: $
0014 
0015 l = size(K,1);
0016 j = ones(l,1);
0017 C = K - (j*j'*K)/l - (K*j*j')/l + ((j'*K*j)*j*j')/(l^2);
0018 
0019 if( nargin > 1 )
0020     tk =  (1/l)*sum(K,1); % (1 x l)
0021     tl = ones(size(Ks,1),1); % (n x 1)
0022     Cs = Ks - ( tl * tk); % ( n x l )
0023     tk2 = (1/(size(Ks,2)))*sum(Cs,2); % ( n x 1 )
0024     Cs = Cs - (tk2 * j'); % ( n x l )
0025     
0026     % Two equivalent ways to achieve the same thing
0027     %Cs = Ks - repmat(sum(K),size(Ks,1),1)/l - repmat(sum(Ks,2),1,size(Ks,2))/size(Ks,2) + repmat(j'*K*j,size(Ks,1),size(Ks,2))/(l^2);
0028     %Cs = Ks - (tl*sum(K))/l - (sum(Ks,2)*j')/size(Ks,2) + ((j'*K*j)*tl*j')/(l^2);
0029     
0030     if nargin > 2
0031         ttj = ones(size(Kss,1),1);
0032         Css = Kss - (sum(Ks,2)*ttj')/l - (ttj*sum(Ks,2)')/l + ((j'*K*j)*ttj*ttj')/(l^2);
0033     end
0034 end 
0035 
0036 end

Generated on Sun 20-May-2012 13:24:48 by m2html © 2005