function alpha = learnKernelReg(X,y,lambda,f_krnl,krnl_p)
% alpha = learnKernelReg(X,y,lambda,f_krnl,krnl_p)
%
% X,y labeled training examples
% lambda regularization parameter (default 1)
% f_krnl function handle of kernel function with kernel parameter krnl_p
% (default rbf and 1)
%
% Trains kernel regression model and returns dual weight vector

if nargin < 3
	lambda = 1;
end
if nargin < 4
	f_krnl = @rbf;
	krnl_p = 1;
end
if nargin < 5
	krnl_p = {};
end

K = f_krnl(X, X, krnl_p);
m = size(K,2);

alpha = inv(K + lambda*(eye(m)))*y;
