function [] = compareBIC(n)

% we have n points labeled y=0 and n points labeled 1

% score for M_0 (single region [0,1])

bic0 = 2*n*log(0.5)-0.5*log(2*n);

% M_1 splits [0,1] into region1 = [0,1/2) and region2 = [1/2,1].

D = zeros(n+1,n+1); % the score difference bic1-bic0

for i=0:n,
  for j=0:n,
    n11 = i; % number of y=1 in region1
    n10 = j;  % number of y=0 in region1
    n21 = n-i; % number of y=1 in region2
    n20 = n-j; % number of y=0 in region2
       
    bic1 = -0.5*2*log(2*n);

    if (n11+n10>0),
      p1 = n11/(n11+n10);
      bic1 = bic1 - (n11+n10)*binaryEntropy(p1); 
    end;
    if (n21+n20>0),
      p2 = n21/(n21+n20);
      bic1 = bic1 - (n21+n20)*binaryEntropy(p2); 
    end;

    D(i+1,j+1) = bic1-bic0; 
  end;
end;

tx = [0:n]/n;
ty = [0:n]/n;

contour(tx,ty,D',[0 0],'k-');
xlabel('fraction of points y=1 in region 1')
ylabel('fraction of points y=0 in region 1')
grid;

% ------------------------------

function [h] = binaryEntropy(p) 

h = 0;
if (p>0 && (1-p)>0),
  h = -p*log(p)-(1-p)*log(1-p);
end;

