Skip to content

Commit

Permalink
added very experimental rls code - dont use this for now unless as a …
Browse files Browse the repository at this point in the history
…template for some other prediciton method!!
  • Loading branch information
Jakob Voigts committed Jan 5, 2013
1 parent d29163c commit 303e300
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
31 changes: 31 additions & 0 deletions rls/rlsPredict.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function Ytest = rlsPredict(Xtest,Xtrain,coeffs,whichKernel)
%prediction from RLS coeffs from rlsTrain
% function Ytest = rlsPredict(Xtest,Xtrain,coeffs,whichKernel)
%
% returns:
% Ytest prediction
%
% takes
% Xtest points on which to test
% Xtrain training dataset
% coeffs coefficient from rlsTrain
% whichKErnel kernel to use

rlsAssignkernelfun;

[N,d] = size(Xtrain);
Nt=size(Xtest,1);

for i=1:Nt
% s=0;
%for j=1:N
% s=s+coeffs(j)*kernelfun(Xtrain(j,:),Xtest(i,:));
%end;
Ytest(i)=sum(coeffs.*kernelfun(Xtrain(:,:),Xtest(i,:)));
%Ytest(i) = sum((Xtrain,Xtest(i,:)')*coeffs);
end;

%Ytest = (Xtest*Xtrain')*coeffs;



28 changes: 28 additions & 0 deletions rls/rlsTrain.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function [coeffs,K] = rlsTrain(Ytrain,Xtrain,whichKernel,lambda,varargin)
%rlsTrain regularized least squares coefficient estimator
% function coeffs = rlsTrain(Ytain,Xtrain,whichKErnel,lambda)
%
% returns:
% optimal RLS coefficients in coeffs
% K Kernel matrix of training set
%
% takes
% Xtrain training input
% Ytrain training labels
% whichKErnel kernel to use
% lambda regularization weight
% (optional) kernel matrix K

%% compute kernel matrix
if size (varargin) ==1 % if kernel matrix is supplied
K=varargin{1};
else % compute kernel matrix
rlsAssignkernelfun;
K = KernelMatrix(Xtrain,kernelfun);
end;

%% perform RLS fit

[N,d] = size(Xtrain);

coeffs = ( K+ (eye(N)*lambda) )\Ytrain;

0 comments on commit 303e300

Please sign in to comment.