
clear;
close all;
load reg_least_sq;

% select which training set to use...
train = train_small;
%train = train_med;
%train = train_large;

X = train.X;
y = train.y;

Lambda = [.01:.01:2.0];
w_0 = pinv(X'*X)*(X'*y); % computes the least-squares estimate (no regularization)
W = reg_least_sq_path(X,y,Lambda,w_0);

figure(1);
plot(Lambda,W');
title('w-parameters vs. lambda');

% generate additional plots requested in the problem...
l = length(Lambda);
D = zeros(l,5);
for k = 1:l

  w = W(:,k);

  % half avg. squared training error
  D(k,1) = 

  % l1 regularization penalty
  D(k,2) = 

  % objective
  D(k,3) = 

  % test error
  D(k,4) = 

  % l0 norm (number of non-zero components) 
  D(k,5) = 

end

figure(2);
plot(Lambda,D(:,1)');
title('training error vs lambda');

figure(3);
plot(Lambda,D(:,2)');
title('regularization penalty vs lambda');

figure(4);
plot(Lambda,D(:,3)');
title('objective vs lambda');

figure(5);
plot(Lambda,D(:,4)');
title('test error vs lambda');

figure(6);
plot(Lambda,D(:,5)');
title('number features vs lambda');


