Re: HISTOGRAM, binsize, and max [message #76092] |
Wed, 18 May 2011 11:41 |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
On May 18, 2:33 pm, Paolo <pgri...@gmail.com> wrote:
> On May 18, 1:08 pm, andry <andry_will...@hotmail.com> wrote:
>
>> Hi Paolo,
>
>> I guess this has to do with the fact that different computers don't
>> behave the same way. What OS and which version of IDL are you with?
>
>> Mine is actually a
>> { x86 linux unix linux 8.0 Jun 18 2010 32 64}
>
> Maybe you have conversion to doubles enabled by default?
>
> With floats you always get 7+1 bins:
>
> IDL> print,1.4/0.2,format='(f20.15)'
> 7.000000000000000
> IDL> print,140.0/20.0,format='(f20.15)'
> 7.000000000000000
>
> With doubles you will get different numbers of bins:
>
> IDL> print,1.4d/0.2d,format='(f20.15)'
> 6.999999999999999
> IDL> print,140d/20d,format='(f20.15)'
> 7.000000000000000
>
> Ciao,
> Paolo
>
>
>
>
>
>
>
>
>
>>> When I try that I always get 8 bins no matter what.
>>> I don't see how you could get 7 bins in that situation...
>
>>> IDL> hist_spd= HISTOGRAM(randomn(seed,10)*200,binsize= .
>>> 20,min=0.,max=1.40) & help,hist_spd
>>> HIST_SPD LONG = Array[8]
>
>>> IDL> hist_spd= HISTOGRAM(randomn(seed,10)*200,binsize=
>>> 20.0,min=0.,max=140.0) & help,hist_spd
>>> HIST_SPD LONG = Array[8]
to clarify:
IDL> hist_spd= HISTOGRAM(float(randomn(seed,
10)*200),binsize=20.0,min=0.0,max=140.0) & help,hist_spd
HIST_SPD LONG = Array[8]
IDL> hist_spd= HISTOGRAM(double(randomn(seed,
10)*200),binsize=20d,min=0d,max=140d) & help,hist_spd
HIST_SPD LONG = Array[8]
IDL> hist_spd= HISTOGRAM(float(randomn(seed,10)*200),binsize=.
20,min=0.,max=1.40) & help,hist_spd
HIST_SPD LONG = Array[8]
IDL> hist_spd= HISTOGRAM(double(randomn(seed,10)*200),binsize=.
20d,min=0.d,max=1.40d) & help,hist_spd
HIST_SPD LONG = Array[7]
Float is consistent, double not.
The reason seems to be the different value you get when dividing
max-min by binsize, caused by the well known issues with floating
representation of numbers.
Ciao,
Paolo
>
>>> Ciao,
>>> Paolo
>
>>>> Cheers,
>
>>>> David
>
>>>> --
>>>> David Fanning, Ph.D.
>>>> Fanning Software Consulting, Inc.
>>>> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
>>>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: HISTOGRAM, binsize, and max [message #76093 is a reply to message #76092] |
Wed, 18 May 2011 11:33  |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
On May 18, 1:08 pm, andry <andry_will...@hotmail.com> wrote:
> Hi Paolo,
>
> I guess this has to do with the fact that different computers don't
> behave the same way. What OS and which version of IDL are you with?
>
> Mine is actually a
> { x86 linux unix linux 8.0 Jun 18 2010 32 64}
Maybe you have conversion to doubles enabled by default?
With floats you always get 7+1 bins:
IDL> print,1.4/0.2,format='(f20.15)'
7.000000000000000
IDL> print,140.0/20.0,format='(f20.15)'
7.000000000000000
With doubles you will get different numbers of bins:
IDL> print,1.4d/0.2d,format='(f20.15)'
6.999999999999999
IDL> print,140d/20d,format='(f20.15)'
7.000000000000000
Ciao,
Paolo
>
>
>
>
>
>
>
>> When I try that I always get 8 bins no matter what.
>> I don't see how you could get 7 bins in that situation...
>
>> IDL> hist_spd= HISTOGRAM(randomn(seed,10)*200,binsize= .
>> 20,min=0.,max=1.40) & help,hist_spd
>> HIST_SPD LONG = Array[8]
>
>> IDL> hist_spd= HISTOGRAM(randomn(seed,10)*200,binsize=
>> 20.0,min=0.,max=140.0) & help,hist_spd
>> HIST_SPD LONG = Array[8]
>
>> Ciao,
>> Paolo
>
>>> Cheers,
>
>>> David
>
>>> --
>>> David Fanning, Ph.D.
>>> Fanning Software Consulting, Inc.
>>> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
>>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: HISTOGRAM, binsize, and max [message #76097 is a reply to message #76093] |
Wed, 18 May 2011 10:08  |
war
Messages: 21 Registered: December 2003
|
Junior Member |
|
|
Hi Paolo,
I guess this has to do with the fact that different computers don't
behave the same way. What OS and which version of IDL are you with?
Mine is actually a
{ x86 linux unix linux 8.0 Jun 18 2010 32 64}
> When I try that I always get 8 bins no matter what.
> I don't see how you could get 7 bins in that situation...
>
> IDL> hist_spd= HISTOGRAM(randomn(seed,10)*200,binsize= .
> 20,min=0.,max=1.40) & help,hist_spd
> HIST_SPD LONG = Array[8]
>
> IDL> hist_spd= HISTOGRAM(randomn(seed,10)*200,binsize=
> 20.0,min=0.,max=140.0) & help,hist_spd
> HIST_SPD LONG = Array[8]
>
> Ciao,
> Paolo
>
>
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
>
|
|
|
Re: HISTOGRAM, binsize, and max [message #76104 is a reply to message #76097] |
Wed, 18 May 2011 08:22  |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
On May 18, 10:23 am, David Fanning <n...@idlcoyote.com> wrote:
> andry writes:
>> Can somebody explain why the following gives different number of
>> elements with the HISTOGRAM function?
>
>> IDL> hist_spd= HISTOGRAM(velocity[indb],binsize= .20,min=0.,max=1.40)
>> IDL> print,hist_spd
>> 6 16 23 0 0
>> 0 0
>> IDL> hist_spd= HISTOGRAM(velocity[indb],binsize= 20.,min=0.,max=140.)
>> IDL> print,hist_spd
>> 45 0 0 0 0
>> 0 0 0
>
>> (whatever velocity content is)
>> My main concern is the number of elements returned by the function.
>> The only difference between the 2 command is that I multiplied the
>> binsize and max with 100. BUT they return 7 and 8 elements?
>
>> I would expect they both return the same number of elements.
>
> People expect a lot of things from computers, but the
> computers don't always oblige. I think this is just the normal
> weirdness with how computers represent numbers. It
> turns out this is different from how humans apparently
> do it. :-)
>
> http://www.idlcoyote.com/math_tips/sky_is_falling.html
> http://www.idlcoyote.com/math_tips/razoredge.html
When I try that I always get 8 bins no matter what.
I don't see how you could get 7 bins in that situation...
IDL> hist_spd= HISTOGRAM(randomn(seed,10)*200,binsize= .
20,min=0.,max=1.40) & help,hist_spd
HIST_SPD LONG = Array[8]
IDL> hist_spd= HISTOGRAM(randomn(seed,10)*200,binsize=
20.0,min=0.,max=140.0) & help,hist_spd
HIST_SPD LONG = Array[8]
Ciao,
Paolo
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: HISTOGRAM, binsize, and max [message #76108 is a reply to message #76104] |
Wed, 18 May 2011 07:23  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
andry writes:
> Can somebody explain why the following gives different number of
> elements with the HISTOGRAM function?
>
> IDL> hist_spd= HISTOGRAM(velocity[indb],binsize= .20,min=0.,max=1.40)
> IDL> print,hist_spd
> 6 16 23 0 0
> 0 0
> IDL> hist_spd= HISTOGRAM(velocity[indb],binsize= 20.,min=0.,max=140.)
> IDL> print,hist_spd
> 45 0 0 0 0
> 0 0 0
>
> (whatever velocity content is)
> My main concern is the number of elements returned by the function.
> The only difference between the 2 command is that I multiplied the
> binsize and max with 100. BUT they return 7 and 8 elements?
>
> I would expect they both return the same number of elements.
People expect a lot of things from computers, but the
computers don't always oblige. I think this is just the normal
weirdness with how computers represent numbers. It
turns out this is different from how humans apparently
do it. :-)
http://www.idlcoyote.com/math_tips/sky_is_falling.html
http://www.idlcoyote.com/math_tips/razoredge.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|