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

📄 cachedkernel.m.svn-base

📁 a function inside machine learning
💻 SVN-BASE
字号:
function K = cachedKernel(X1Indices, X2Indices, kernelParams) 
%A function to use a kernel saved to disc, with a cache to speed things up 
kernelFileName = char(kernelParams.kernelFileName); 

%First time around create the cache 
if isempty(whos('global', 'kernelCache'))
    cacheSize = kernelParams.kernelCacheSize; 
    
    fprintf('Creating kernel cache of size %d by %d from %s ... \n', cacheSize, cacheSize, kernelFileName); 
    global kernelCache; 
    global kernelCacheInfo; 
    
    
    
    kernelCacheInfo.size = cacheSize; 
    kernelCacheInfo.fileName = kernelFileName; 
    kernelCacheInfo.colIndices = zeros(cacheSize, 1); 
    kernelCacheInfo.rowIndices = zeros(cacheSize, 1); 
    
    %Just load the kernel 
    kernelCacheInfo.colIndices = 1:cacheSize; 
    kernelCacheInfo.rowIndices = 1:cacheSize; 
    kernelCache = savedKernel(1:cacheSize, 1:cacheSize, kernelParams); 
    disp('... done.'); 
else
    global kernelCache;
    global kernelCacheInfo;
end

K = zeros(length(X1Indices), length(X2Indices));

%First load all entries from the cache 
%If the kernel cache has no common rows or columns (i.e. kernelCacheRowI or
%kernelCacheRowI is empty) then we cannot use the cache 
[rowCacheIndices, tempX1Indices, kernelCacheRowI]  = intersect(X1Indices, kernelCacheInfo.rowIndices);
[colCacheIndices, tempX2Indices, kernelCacheColI] = intersect(X2Indices, kernelCacheInfo.colIndices);

K(tempX1Indices, tempX2Indices) = kernelCache(kernelCacheRowI, kernelCacheColI); 

%Now load everything thats remaining. In this case, we look for the
%remaining row or column indices intersected with all column or row indices
%respectively 
[X1RemIndices, tempX1Indices]  = setdiff(X1Indices, kernelCacheInfo.rowIndices);
[X2RemIndices, tempX2Indices] = setdiff(X2Indices, kernelCacheInfo.colIndices);

if length(X2RemIndices) ~= 0 
    K(:, tempX2Indices) = savedKernel(X1Indices, X2RemIndices, kernelParams);
end

if length(X1RemIndices) ~= 0 
    K(tempX1Indices, :) = savedKernel(X1RemIndices, X2Indices, kernelParams);
end 

⌨️ 快捷键说明

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