dualsparsegeneralfeaturesproject.m.svn-base

来自「a function inside machine learning」· SVN-BASE 代码 · 共 40 行

SVN-BASE
40
字号
function [testInfo, projectionInfo] = dualSparseGeneralFeaturesProject(trainData, testData, subspaceInfo, params)
%Extract new features on a test set

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

%Subspace parameters 
[nameX, nameY] = getSpaceNames(params); 

b = subspaceInfo.(nameX).b; 
Q = subspaceInfo.(nameX).Q;   %Note: all normalisations integrated into Q 
exampleIndices = subspaceInfo.(nameX).exampleIndices; 
nzElements = subspaceInfo.(nameX).nzElements; 

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

fprintf('Computing projections ... ');
diagBElements = diag(nzElements);

%testTrainKb
tic 
newTestX = feval(kernelFunction, getDataFieldValue(testData, nameX), getDataFieldValue(trainData, nameX, exampleIndices), kernelParams);
newTestX = newTestX*diagBElements;
newTestX = newTestX*Q;
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.data = data; 
testInfo.data  = addDataField(testInfo.data, 'X', newTestX, 'examples'); 

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

projectionInfo = struct; 
projectionInfo.testTime = testTime; 

⌨️ 快捷键说明

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