primaldoublegeneralfeatures.m.svn-base

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

SVN-BASE
55
字号
function [newTrainXa, newTrainXb, newTestXa, newTestXb, subspaceInfo] = primalDoubleGeneralFeatures(trainXa, trainXb, testXa, testXb, params)
%A function to compute general features on two sets of input data 
%Note: data should be centered first 

if (nargin ~= 5)
  disp('Incorrect number of inputs');
  help primalDoubleGeneralFeatures;
  return;
end

%Store all the parameters 
featureDirection = char(params.featureDirection); 
T = params.iterations; 

Xaj = trainXa; 
Xbj = trainXb; 

numExamples = size(trainXa, 1); 
numXaFeatures = size(trainXa, 2);
numXbFeatures = size(trainXb, 2);

u = ones(numXaFeatures, T);
v = ones(numXbFeatures, T);

s = ones(numExamples, T); 
t = ones(numExamples, T); 

%Compute the projection directions 
for j=1:T
	[u(:, j), v(:, j)] = feval(featureDirection, Xaj, Xbj); 
    
    s(:, j) = Xaj*u(:,j);
    t(:, j) = Xbj*v(:,j);
    
    p(:,j) = Xaj'*s(:, j)/(s(:, j)'*s(:, j));
    q(:,j) = Xbj'*t(:, j)/(t(:, j)'*t(:, j));
    
    Xaj = Xaj - s(:, j)*p(:,j)';  
    Xbj = Xbj - t(:, j)*q(:,j)';  
end


%Compute new features on training and test data 
Y = u/(p'*u); 
Z = v/(q'*v); 

newTrainXa = trainXa*Y; 
newTestXa = testXa*Y; 

newTrainXb = trainXb*Z; 
newTestXb = testXb*Z; 

subspaceInfo.u = u;
subspaceInfo.v = v;

⌨️ 快捷键说明

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