% estimate predictors using LARS in Reproducing Kernel Hilbert Spaces

% y= output datal
% u = input data;
% iy = index of the component for which the predictor is being built
% p = number of eigenfunctions
% beta = decay rate of eigenfunctions (need to find a smart rule)
% regularization)
% T= length of eigenfunctions

function [X,Phi,Q] = RKHS_Pred_LARS_all_k_computeRegressors_fixed_betaT(y,u,iy,p,beta,T);

%load Eigenfunctions05

dT=1;  % sampling time
if isempty(T),
    T = 50; % length of eigenfunctions (not a bias issue..) 
end;
[Phi lambda] = stable_spline(p,beta,T,dT);

Phi = Phi(:,1:p);
lambda = lambda(1:p);

Q = diag(1./lambda); % for computing the norm in the RKHS

[N,ny]=size(y);
[N,nu]=size(u);
Nx = p*ones(1,nu+ny);

% compute regression matrix;
for j=1:ny,
    for i=1:p,
        X(:,(j-1)*p+i)=filter(Phi(:,i),1,y(:,j)); % assume one delay from all outputs
    end;
end;

for j=1:nu,
    for i=1:p,
        X(:,p*ny+(j-1)*p+i)=filter(Phi(:,i),1,u(:,j)); % assume one delay from all inputs
    end;
end;

%keyboard
