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

📄 primaldoublegeneralfeatures.m.svn-base

📁 a function inside machine learning
💻 SVN-BASE
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -