-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added very experimental rls code - dont use this for now unless as a …
…template for some other prediciton method!!
- Loading branch information
Jakob Voigts
committed
Jan 5, 2013
1 parent
d29163c
commit 303e300
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |