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

📄 dualgreedygstrain.m.svn-base

📁 a function inside machine learning
💻 SVN-BASE
字号:
function [subspaceInfo, trainInfo] = dualGreedyGSTrain(trainData, params)
%A kernel greedy version of Gram Schmidt 

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

[nameX, nameY] = getSpaceNames(params); 
[numTrainExamples, numFeatures] = getDataFieldSize(trainData, nameX);

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

trainKj = feval(kernelFunction, getDataFieldValue(trainData, nameX), getDataFieldValue(trainData, nameX), kernelParams);

b = zeros(numTrainExamples, T); 
tau = zeros(numTrainExamples, T); 

%We just deflate the columns of the kernel matrix by the column with max
%diagonal (I think)
for j=1:T 
    displayCount(j, T, 30);
    
    [maxK, maxInd] = max(diag(trainKj));
    
    b(maxInd, j) = 1/sqrt(maxK); %This just ensures ||q|| = ||b'Kb|| = 1
    tau(:, j) = trainKj*b(:, j); 
    
    trainKj = trainKj - tau(:, j)*tau(:, j)'/(tau(:, j)'*b(:, j));
end 

%Think the new data is the projection of the examples onto the q's which in
%kernel case is Xq = XX'b = tau 
trainInfo.data = data; 
trainInfo.data = addDataField(trainInfo.data, 'X', tau, 'examples'); 

a = b; 

%Deflate the b's to get a 
for i=1:T
    for j=i-1:-1:1
        a(:, i) = a(:, i) - a(:, i)'*tau(:, j)*b(:, j)/(b(:, j)'*tau(:, j));
    end
end

subspaceInfo = struct; 
subspaceInfo.X.a = a;  
subspaceInfo.X.b = b; 
subspaceInfo.X.tau = tau; 

⌨️ 快捷键说明

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