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

📄 dualgeneralfeaturesapprox.m.svn-base

📁 a function inside machine learning
💻 SVN-BASE
字号:
function [testInfo, projectionInfo] = dualGeneralFeaturesApprox(trainData, testData, subspaceInfo, params)
%Compute kernel matrix approximation for dual general features using
%\tilde{K}  = K - K_{j-1}

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

%doubleDeflation = 0 for left sided, 1 for double 
if isfield(params, 'doubleDeflation') 
    doubleDeflation = params.doubleDeflation; 
else 
    doubleDeflation = 0; 
end 

%Subspace parameters 
[nameX, nameY] = getSpaceNames(params);
T = min(params.iterations, size(subspaceInfo.(nameX).tau, 2));
numTrainExamples = getNumDataExamples(trainData); 
numTestExamples = getNumDataExamples(testData); 

%kernel parameters 
kernelFunction = char(params.X.kernel.name); 
kernelParams = params.X.kernel.params; 

s = subspaceInfo.(nameX).s(:, 1:T);
tau =  subspaceInfo.(nameX).tau(:, 1:T);

tic;

%This is symmetric kernel matrix K - K_{j-1}
if doubleDeflation == 1
    r = subspaceInfo.(nameX).r(1:T); 
    b = subspaceInfo.(nameX).b(:, 1:T);
    
    I = speye(numTrainExamples, numTrainExamples);
    tauHat = zeros(numTestExamples, T);
    sHat = zeros(numTestExamples, T);

    fprintf('Computing projections ... ');
    %Need to compute \hat{tau} and \hat{q}

    %testTrainKb
    testTrainKj = feval(kernelFunction, getDataFieldValue(testData, nameX), getDataFieldValue(trainData, nameX), kernelParams);

    for i=1:T
        tauHat(:, i) = testTrainKj*b(:, i);
        sHat(:, i) = testTrainKj*tau(:, i)/(tau(:, i)'*tau(:, i));

        testTrainKj = testTrainKj * (I - b(:, i)*s(:, i)' - tau(:, i)*tau(:, i)'/(tau(:, i)'*tau(:, i)) + b(:, i)*tau(:, i)'/r(i));
    end

    newTestTrainK = tauHat*s' + sHat*tau' - tauHat*diag(r)*tau';
   
else 
    %This is a non-symmetric kernel matrix K - K_{j-1}
    [tInfo, pInfo] = dualGeneralFeaturesProject(trainData, testData, subspaceInfo, params);
    tauHat = getDataFieldValue(tInfo.data, 'X'); 
    
    newTestTrainK = tauHat(:, 1:T)*s'*tau*inv(tau'*tau)*tau';
end

testTime = toc;

%We call the new output variable X there aren't any other names to confuse
%things. Also if we use a kernel K, don't want the output to be called K
testInfo = struct; 
testInfo.data = data; 
testInfo.data  = addDataField(testInfo.data, 'K', newTestTrainK, 'kernel'); 

fprintf('done, took %d seconds.\n', testTime);

projectionInfo = struct;
projectionInfo.testTime = testTime;
projectionInfo.X.tauHat = tauHat;

if doubleDeflation == 1
    projectionInfo.X.sHat = sHat;
end

⌨️ 快捷键说明

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