function r=rate(t,q)

eps=ones(length(t,1))/10^10; % small unit to prevent overflows

r=-sum( q.*log2(q+eps)./(t+eps) );
