function h = hnats(pp, qq) %HNATS (cross-)entropy for discrete distributions measured in nats % % h = hnats(pp, qq) % = -pp(:)'*log(qq(:)), but with zeros from pp removed. % % If one argument is given, encoding distribution qq is equal to the source % distribution pp. % % See also, HBITS, H2NATS, H2BITS, KL_NATS, KL_BITS % Iain Murray, September 2008 if nargin < 2 qq = pp; elseif ~isequal(size(pp), size(qq)) error('Input probability arrays must have the same size.'); end mask = (pp(:)~=0); m = @(x) x(mask); s = @(x) m(x(:)); h = -s(pp)'*reallog(s(qq));