[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in geomean()
From: |
Sergei Steshenko |
Subject: |
Re: Bug in geomean() |
Date: |
Mon, 1 Oct 2012 09:19:09 -0700 (PDT) |
----- Original Message -----
> From: kyfsympsn <address@hidden>
> To: address@hidden
> Cc:
> Sent: Monday, October 1, 2012 5:25 PM
> Subject: Re: Bug in geomean()
>
>T hanks Jordi,
>
>
>> I think it's a good habit to inspect the source code if you want to
>> know how something is being done.
>
> Yeah, sorry... making the switch from Matlab, so I'm not yet in the habit of
> "looking under the hood" at the source code :-)
>
>
>> Can you provide a patch? It should take into account the cases of
>> complex, negative, or zero entries.
>
> the basic fix is to change that line 116 from:
> y = prod (x, dim) .^ (1/n);
> to:
> y = exp (sum(log(x), dim) ./n);
>
> --zero entries in x will correctly return 0
>
[snip]
>
> Many thanks
> Keith
According to how I was taught math and computing taking log(x) for x == 0 is
illegal even if it in the end produces the expected result.
Regards,
Sergei.