p = 0:0.01:0.5;
HX_Y = p.*log2(1./p) + (1 - p).*log2(1./(1 - p));
HXY = (HX_Y + 1)/2;
plot(p, HXY), grid;
HXY(1) = 0.5;
%HXY(end) = 0.5;

%%
data_bzip2 = load('result_bz2_hi_res.dat');
data_gzip = load('result_gzip_hi_res.dat');
data_lzma = load('result_lzma_hi_res.dat');
data_lzw = load('result_lzw_hi_res.dat');

plot(p, data_bzip2(:, 2)./data_bzip2(:, 3), 'b-x',...
    p, data_gzip(:, 2)./data_gzip(:, 3), 'g-x',...
    p, data_lzma(:, 2)./data_lzma(:, 3), 'r-x',...
    p,HXY, 'c-x'), grid;

legend('bzip', 'gzip', 'lzma', 'entropy');

semilogy(p, data_bzip2(:, 2)./data_bzip2(:, 3) - HXY', 'b-x',...
    p, data_gzip(:, 2)./data_gzip(:, 3) - HXY', 'g-x',...
    p, data_lzma(:, 2)./data_lzma(:, 3) - HXY', 'r-x',...
    p, data_lzw(:, 2)./data_lzw(:, 3) - HXY', 'c-x'),...
    grid;

legend('bzip', 'gzip', 'lzma', 'lzw');

%%
dlmwrite('result_bz2.dat', [p', data_bzip2(:, 2)./data_bzip2(:, 3) - HXY'], ' ');
dlmwrite('result_gzip.dat', [p', data_gzip(:, 2)./data_gzip(:, 3) - HXY'], ' ');
dlmwrite('result_lzma.dat', [p', data_lzma(:, 2)./data_lzma(:, 3) - HXY'], ' ');
dlmwrite('result_lzw.dat', [p', data_lzw(:, 2)./data_lzma(:, 3) - HXY'], ' ');
