function [A, err] = optimalLinearPredictor(X, Y)
% optimal linear predictor Y -> X
% return the coefficients in A and the yielded MSE


if (1) 
   %disp('compute acorr');
   acorr = Y*Y';
   %disp('compute corr');
   corr = Y*X';
   
   %disp('invert acorr');
   c = cond(acorr);
   if (c < 10e10)
      A = inv(acorr)*corr;
   else      
      A = zeros([size(Y,1) 1]);
      A(floor(end/2)) = 1;
   end
else
   A = zeros([size(Y,1) 1]);
   A(1) = mean(X);
end

%disp('compute error');
err = mean((X-A'*Y).^2);
