comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Strange behavior of /cumulative keyword in total()
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Strange behavior of /cumulative keyword in total() [message #63285] Tue, 04 November 2008 08:23 Go to next message
jameskuyper is currently offline  jameskuyper
Messages: 79
Registered: October 2007
Member
Chris wrote:
> Can anybody explain this?
>
> arr = fltarr( 500000) + .1
> cumul = total(array, /cumulative)
>
> print, (cumul - shift(cumul, 1)) [1 : 10]
> print, (cumul - shift(cumul,1)) [499990:499999]
>
>> 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000
> 0.100000 0.100000 0.100000 0.100000
>
>
>> 0.101562 0.101562 0.101562 0.101562 0.101562 0.101562
> 0.101562 0.101562 0.101562 0.101562
>
> Plotting cumul - shift(cumul,1) is even weirder. I can understand the
> net error of cumul growing over time, as floating point precision
> errors accumulate. However, shouldn't the error between any two
> entries in a cumulative sum not accumulate over the array?

The difference between any two entries in the array should be 0.1,
plus a roundoff error that should be proportional to the value of
cumul. Try this:

diff = cumul[1:*]-cumul[0:499998]-0.1
nonzero = where(diff ne 0.0)
plot, cumul[nonzero], abs(diff[nonzero]), psym=3, /xlog, /ylog

I was also going to say that the roundoff error should be random, but
that doesn't look very random to me.
Re: Strange behavior of /cumulative keyword in total() [message #63295 is a reply to message #63285] Tue, 04 November 2008 05:38 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chris writes:

> Can anybody explain this?
>
> arr = fltarr( 500000) + .1
> cumul = total(array, /cumulative)
>
> print, (cumul - shift(cumul, 1)) [1 : 10]
> print, (cumul - shift(cumul,1)) [499990:499999]
>
>> 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000
> 0.100000 0.100000 0.100000 0.100000
>
>
>> 0.101562 0.101562 0.101562 0.101562 0.101562 0.101562
> 0.101562 0.101562 0.101562 0.101562
>
> Plotting cumul - shift(cumul,1) is even weirder. I can understand the
> net error of cumul growing over time, as floating point precision
> errors accumulate. However, shouldn't the error between any two
> entries in a cumulative sum not accumulate over the array?

Two words: double precision.

IDL> arr = fltarr( 500000) + .1D
IDL> cumul = total(arr, /cumulative, /double)
IDL>
IDL> print, (cumul - shift(cumul, 1)) [1 : 10]
0.10000000 0.10000000 0.10000000 0.10000000
0.10000000 0.10000000 0.10000000 0.10000000
0.10000000 0.10000000
IDL> print, (cumul - shift(cumul,1)) [499990:499999]
0.10000000 0.10000000 0.10000000 0.10000000
0.10000000 0.10000000 0.10000000 0.10000000
0.10000000 0.10000000


Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Strange behavior of /cumulative keyword in total() [message #63369 is a reply to message #63285] Tue, 04 November 2008 12:40 Go to previous message
Chris[6] is currently offline  Chris[6]
Messages: 84
Registered: July 2008
Member
> The difference between any two entries in the array should be 0.1,
> plus a roundoff error that should be proportional to the value of
> cumul. Try this:

I see - it's not that roundoff errors are accumulating over the sum,
but that differences of 0.1 are expressed less and less precisely as
numbers grow. To bad the roundoff error isn't random, so that the
effect would wash out...

Thanks for the clarification
chris
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: specialized color tables
Next Topic: segment vector with missing data

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 14:55:05 PDT 2025

Total time taken to generate the page: 1.68168 seconds