⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sparsecovariances.m

📁 a function inside machine learning
💻 M
字号:
function [covariances, bs] = sparseCovariances(K, Kj, Y, Yj, columnIndices)
%Comnpute the covariances of the columns of the kernel matrix (normalised
%so that cov = b'Kj'*Y*v and b'Kb = 1). ColumnIndices should be a column
%vector. The variable called bs is the values of the selected b's  

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

numExamples = size(K, 1); 
numColumns = size(K, 2); 
tol = 10^6; 

warning('off','MATLAB:divideByZero');
invNormVector = 1./sqrt(K(sub2ind(size(K), columnIndices , (1:numColumns)')));  
%invNormVector = 1./sqrt(diag(K(columnIndices, :)));  
warning('on','MATLAB:divideByZero');

infiniteIndices = setdiff((invNormVector > tol) .* (1:numColumns)', 0);
invNormVector(infiniteIndices) = 0;

YK = Y'*Kj;
covariances = abs(sqrt(sum(YK.^2, 1))' .* invNormVector); 
bs = invNormVector; 




⌨️ 快捷键说明

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