Hmmm... may not have sent that to you.
function(k) {
return (2 * (h(k) - h(rowSums(k)) - h(colSums(k))));
}
function(k) {
p = k / sum(k) + (k == 0);
return (sum(k * log(p)));
}
This is the pithiest implementation that I know of.
On Mon, Jun 2, 2008 at 5:50 PM, Sean Owen <[EMAIL PROTECTED]> wrote:
> PS what's the R code? sorry if I am missing something basic.
>
> On Sun, Jun 1, 2008 at 8:32 PM, Ted Dunning <[EMAIL PROTECTED]> wrote:
> > The R code is instructive here. Everywhere you are about to take the log
> of
> > a zero probability, you should add 1. This is equivalent to saying that
> >
> > lim_{x -> 0} x log x = 0
>
> OK true but...
>
> > One easy way to do this is to wrap your log function:
> >
> > safeLog = {x -> return (x==0)?0:Math.log(x)}
>
> ... log(x) approaches -infinity as x approaches 0 so why is 0 a good
> substitute for log(0)?
>
> But I would buy that, for purposes of this function, "log(p)" can be
> replaced with "log(p+1)" so at least the output value is >= 0 and less
> than 1?
>
--
ted