function out=handMutualInfo(data)
% takes data in {0,1} format

if size(data,1)==1
    data=data';
elseif min(size(data))>1
    error('data is not nx1 or 1xn');
end

prob=sum(data)/length(data);
ni=length(data);

pairList=[data(1:ni-1) data(2:ni)];

px1=sum(pairList(:,1)==1)/size(pairList,1);
px0=1-px1;
py1=sum(pairList(:,2)==1)/size(pairList,1);
py0=1-py1;

pairID=pairList(:,1)+0.5*pairList(:,2);

listN=size(pairList,1);

px1y1=sum(pairID==1.5)/listN;
px1y0=sum(pairID==1)/listN;
px0y1=sum(pairID==0.5)/listN;
px0y0=sum(pairID==0)/listN;

MI=px1y1*log2(px1y1/(px1*py1))+px1y0*log2(px1y0/(px1*py0));
MI=MI+px0y1*log2(px0y1/(px0*py1))+px0y0*log2(px0y0/(px0*py0));

out=MI;
