help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in geomean()


From: kyfsympsn
Subject: Re: Bug in geomean()
Date: Mon, 1 Oct 2012 08:25:09 -0700 (PDT)

Thanks 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

--Using the current method negative entries return a complex result, however
I don't think it makes sense given the definition and uses of the geometric
mean (wikipedia also says the geometric mean should only be performed on
positive numbers). 
Using my suggested modification, negative entries will fail (as they do in
matlab), although it would be useful to the user to say why, so i guess line
116 should become:

if (sum(sum(x<0))==0)
   y = exp (sum(log(x), dim) ./n);
else
    error ("mean: X must not contain any negative values");
end


--complex entries will work out ok, as exp, sum and log will handle them
correctly


I'm not sure how one goes about officially suggesting a change, and I'm
likely to only be a short term octave user (as i need to run some legacy
code at work), so if its easier for someone else to make the change, then be
my guest.

Many thanks
Keith




--
View this message in context: 
http://octave.1599824.n4.nabble.com/Bug-in-geomean-tp4644842p4644848.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]