function draw_distributions_all()

figure

% dataset1
% two sample distributions
dd = load('dataset1.txt');
draw_distributions(dd, 1);

% dataset2
% two sample distributions
dd = load('dataset2.txt');
draw_distributions(dd, 2);

% dataset3
% two sample distributions
dd = load('dataset3.txt');
draw_distributions(dd, 3);

% dataset4
% two sample distributions
dd = load('dataset4.txt');
draw_distributions(dd, 4);


function draw_distributions(dd, dataset_id)

numr = length(dd);% number of total samples for each distribution
delx = 0.5;

bins = -5:delx:30;
x1 = dd(:,1); 
x2 = dd(:,2); 


ref = (mu(1)+mu(2))/2;

c1 = histc(x1,bins);
c2 = histc(x2,bins);

p1 = c1/delx/numr;
p2 = c2/delx/numr;

% The above is exactly the same as this: 
% cc1 = cumsum(c1)/numr;
% for t=1:length(bins)-1
%     p1(t) = (cc1(t+1)-cc1(t))/delx;
% end
% p1(t+1) = 0;
% cc2 = cumsum(c2)/numr;
% for t=1:length(bins)-1
%     p2(t) = (cc2(t+1)-cc2(t))/delx;
% end
% p2(t+1) = 0;


subplot(2,2,dataset_id)
hold on
plot(bins, p2, 'b');
plot(bins, p1, 'r')
axis([-5 30 0 0.5])
legend('class1', 'class2')
xlabel('value')
ylabel('Pr')
titlestr = sprintf('dataset%d', dataset_id);
title(titlestr)
hold off


