% klagenfurt lectures collection

%$ loading the data
load weightHeight.dat;    % the variable 
d_w = weightHeight(:,1);
d_h = weightHeight(:,2);
clear weightHeight;
Y = d_h;
s_n  = 5;
s_th = 100;

%% visualisation init
xa = (42:2:120)';
clf; hold on; box on;
plot(d_w,d_h,'ro');
%xlim([45 115]); ylim([135 195]);

%% MAXLIK using linear basis
X  = [d_w.^3 d_w.^2 d_w ones(size(d_h))];
XX = [xa.^3 xa.^2  xa ones(size(xa))];
% parameter estimation
pv_th = (X'*X/s_n^2 + eye(size(X,2))/s_th^2);
pm_th = pv_th\(X'*Y)/s_n^2;
% plotting
T=200;
theta = gsamp(pm_th,pv_th^(-1),T);
for ii=1:T
  plot(xa,XX*theta(ii,:)','linewidth',1);
end;

