dualmaxsparsekernelapprox.m

来自「a function inside machine learning」· M 代码 · 共 28 行

M
28
字号
function b = dualMaxSparseKernelApprox(K, Kj, Y, Yj)
%Find the sparse direction that is the best approximation of the kernel
%matrix. This is given by max 2b'KKKKb/b'K^2b - (b'KKKb/b'K^2b)^2. 
%Here we assume uj = Xj'bj but is the expression to compute double
%deflation correct? Note, we can't just pick columns of the deflated kernel
%matrix in this case 

if (nargin ~= 4)
    fprintf('%s\n', help(sprintf('%s', mfilename)));
    error('Incorrect number of inputs - see above usage instructions.');
end

numExamples = size(K, 1); 

KK = Kj*Kj; 
KKK = KK*Kj; 
KKKK = KKK*Kj; 

vals = 2*diag(KKKK)./diag(KK) - (diag(KKK)./diag(KK)).^2; 

[val, index] = max(vals); 

b = sparse(numExamples, 1); 
b(index) = 1/sqrt(Kj(index, index)); %Normalise by bj'Kjbj = 1;



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?