📄 primalgeneralfeatures.m.svn-base
字号:
function [newTrainX, newTestX, u, p] = primalGeneralFeatures(trainX, trainY, testX, T, featureDirection)
% Compute features based on the General Feature Extraction Framework for a
% set of training examples and label.
%
% Usage: [newTrainX, newTestX, u, p] = primalGeneralFeatures(trainX, trainY, testX, T, featureDirection)
% Inputs/Outputs:
% trainX - an (l x n) matrix whose rows are the training inputs
% trainY - (l x m) containing the corresponding output vectors
% testX - an (l x n) matrix whose rows are the test inputs
% T - the number of iterations to be performed
% featureDirection - a string specifying a function which computes a
% projection direction on centered matrices trainX and trainY at each
% iteration
%
% newTrainX - the new training data matrix
% newTestX - the new test data matrix
% u - the matrix with columns composed of the projection directions
% p - the matrix with columns composed of the p's
%
% Copyright (C) 2006 Charanpal Dhanjal
% This library is free software; you can redistribute it and/or
% modify it under the terms of the GNU Lesser General Public
% License as published by the Free Software Foundation; either
% version 2.1 of the License, or (at your option) any later version.
%
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% Lesser General Public License for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License along with this library; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
% USA
if (nargin ~= 5)
fprintf('%s\n', help('primalGeneralFeatures'));
error('Incorrect number of inputs - see above usage instructions.');
end
Xj = trainX;
numExamples = size(trainX, 1);
numFeatures = size(trainX, 2);
u = ones(numFeatures, T);
t = ones(numExamples, T);
%Compute the projection directions
for j=1:T
u(:, j) = feval(featureDirection, Xj, trainY);
t(:, j) = Xj*u(:,j);
p(:,j) = Xj'*t(:, j)/(t(:, j)'*t(:, j));
Xj = Xj - t(:, j)*p(:,j)';
end
%Compute new features on training and test data
Z = u/(p'*u);
newTrainX = trainX*Z;
newTestX = testX*Z;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -