Re: GEOMETRIC mean computation: TEST of proposed tecniques for



On 21 Lug, 11:33, Raymond Manzoni <raym...@xxxxxxx> wrote:
David Bernier a écrit :





pamela fluente wrote:
Continuing from:
http://groups.google.it/group/sci.math/browse_thread/thread/c2307b8fe...

I don't see my posts (?). Perhaps Google is holding them.
I will try starting a new thread with some tests on your algorithm.

Google can be late in adding messages to Google Groups archives.
I post through a news-server in Canada, and it is independent
completely from Google Groups.

I recommend the product of 20 terms then log(.) of Raymond Manzoni.
It would be faster than my idea. Also, it would be quite helpful
for those who know about computing geometric means efficiently
if

----> you can give constants C>0 and D>0 such that
----> C < | a(n)* a(n+1)* .... a(n+19)| < D
----> *always* for your data...

In the spirit of Raymond Manzoni's idea, it is very important
that multiplying 20 consecutive terms does *not* cause
Overflow or Underflow....

Only you can tell people of sci.math the maximum D and the
minimum C. Also, do you use floating point numbers? If so,
are they 32-bit, 64-bit or something else?

You see, without C and D, we can't say if there is a
possibility of Overflow or Underflow when multiplying
20 terms (both Overflow and Underflow are bad).

Regards,

David Bernier

Hi David,

In fact if your language allows exception handling you may write code
without this knowledge (merely supposing that unapropriate data will be
uncommon!) :

- in a global way (in C++ for example) :

try
//fast complete (say) 32 terms code
except (...)
{
//slower and more cautious code
}

- in a local way (catching failure in one of the sum term only) :

#define MAX 31

while (s+MAX <= sMax)
{
try
r = log(s[0]*...*s[MAX]); //or log(fabs(...))
except (...)
{
//something more cautious log(0) not wished!!!
r= 0;
for (int i=0; i<=MAX; i++)
if (s[i] != 0.0)
r += log(fabs(s[i]));
}
sum += r;
s += MAX;
}

The exception catching method may be of use too for the other methods
proposed....

Best regards!
Raymond- Nascondi testo tra virgolette -

- Mostra testo tra virgolette -

Yes Raymond. I also thought about that.

Instead of checking that the mean is greater that an upport threshold
of below a lower one, using a try catch on overflow.

However, I think this would slow down terribly the method because then
you would need several
operation to reduce your mean within reasonable bounds, and this slows
down.
If you dont, you remain "close" to the error condition, you are going
to get lots of exceptions
and this is also quite slowing down.

So probably we need a careful choice of the 2 threshold and the
reduction factor (2, 1000, or whatever) .


-P


.



Relevant Pages

  • Re: interrupting for overflow and loop termination
    ... > only this int can ever overflow. ... maybe all you need is a sticky overflow bit. ... When a user-level instruction X caused an exception, ... The CAUSE register was set to indicate the reason. ...
    (comp.arch)
  • Re: Infinity + Infinity (or NegInfinity - NegInfinity)
    ... (trap overflow flag set). ... It doesn't have a VAX style global trap enable flag so one has ... Add and AddTrapOverflow instructions, ... The exception to this is when the operation is ADC/SBB, because it is impossible to determine what the previous content of the carry flag was. ...
    (comp.arch)
  • Re: math.nroot [was Re: A brief question.]
    ... >>> wish sometimes that Python would make up it's mind about what it does ... >> exception on overflow, invalid operation, and divide by 0, and "should ... >> not", by default, raise an exception on underflow or inexact. ... you can at least be pretty sure that an infinite result is the ...
    (comp.lang.python)
  • Re: Integer arithmetic
    ... the exception (and then what: ... it gives your language an advantage over unsafe C if your ... Perhaps in debug mode, overflow exceptions can work. ... I think there has been some research done on the overhead of doing ...
    (comp.lang.misc)