itload('iter_cond_debug3.it');

ndat = 1000; % check if true!

prop_mean=zeros(3,40);
prop_var=zeros(3,40);
for it=0:39
    si = num2str(it);
    eval(['eff_w(it+1) = 1/(w' si '''*w' si ');']);
    eval(['prop_mean(1:3,it+1) = Mpred_mean' si ';']);
    eval(['prop_var(1:3,it+1) = Mpred_var' si '(1:3);']);
end

figure(2)
subplot(1,2,1)
hold off
plot(eff_w)
xlabel('iteration');
title('Effective sample size');
%title('Non-normalized importance weights')

subplot(1,2,2);
hold off
plot(prop_mean');
hold on
plot(prop_mean'+2*sqrt(prop_var'),'.');
plot(prop_mean'-2*sqrt(prop_var'),'.');

%plot(ones(size(prop_mean,2),1)*[3 2],'--')
xlabel('iteration');
title('Mean value of the joint merger $\tilde{f}(\bm{x})$');

% itload('../merger_iter_test.it');
% XG = reshape(Grid(1,:),Npoints,Npoints);
% YG = reshape(Grid(2,:),Npoints,Npoints);
% 
% figure(2);
% M1 = reshape(exp(Res1),Npoints,Npoints);
% contour(XG,YG,M1,7);
% 
% figure(3);
% hold off
% mm = max(max(Res2));
% for i=1:size(Res2,1)
%     M2 = reshape(Res2(i,:),Npoints,Npoints);
%     contour(XG,YG,M2,[0:mm/7:mm]);
%     hold on
% end

