dualsparsegeneralfeatureslm3.m.svn-base

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

SVN-BASE
48
字号
function  [newTrainX, newTestX, subspaceInfo] = dualSparseGeneralFeaturesLM3(trainX, trainY, testX, params)
%A function to compute general features in the dual space without
%requiring the kernel matrix to be entirely in memory. Designed for datasets
%with a large number of examples. Uses a random subset of the kernel matrix
%columns at each iteration to find the dual projection direction. 
%
%Inputs 
%   trainX - training examples 
%   trainY - training labels 
%   testX - test examples 
%   params - struct of parameters 
%Outputs 
%   newTrainX - new training examples 
%   newTestX - new test examples 
%   subspaceInfo - struct containing some meta-data 

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


if size(trainX, 2) ~= size(testX, 2) 
    error('Train and test sets must have same number of features\n'); 
end 

trainData = data; 
trainData = addDataField(trainData, 'X', trainX, 'examples'); 
trainData = addDataField(trainData, 'Y', trainY, 'labels'); 

testData = data; 
testData = addDataField(testData, 'X', testX, 'examples'); 


paramsX.X.kernel.name = char(params.kernelFunctionName); 
paramsX.X.kernel.params = params; 

params.X.kernel = paramsX.X.kernel;

[subspaceInfo, trainInfo] = dualSparseGeneralFeaturesLM3Train(trainData, params);
[testInfo, projectionInfo] = dualSparseGeneralFeaturesProject(trainData, testData, subspaceInfo, paramsX);

newTrainX = getDataFieldValue(trainInfo.data, 'X'); 
newTestX = getDataFieldValue(testInfo.data, 'X'); 

subspaceInfo.projectionInfo = projectionInfo; 
subspaceInfo.X = rmfield(subspaceInfo.X, 'Q'); 

⌨️ 快捷键说明

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