Histogram [message #44556] |
Tue, 28 June 2005 09:24  |
James[1]
Messages: 9 Registered: August 2004
|
Junior Member |
|
|
Hi guys !
I have a question regarding histograms in general. Is there a "right"
criteria (e.g. strict matmematical rule, etc..) of chosing the bin size ?
I'm playing with some data and obviously the histogram looks differently
with different bin sizes. Any help and references would be extremely
helpful !
Cheers,
James
|
|
|
|
|
|
|
|
|
Re: Histogram [message #72826 is a reply to message #44556] |
Mon, 11 October 2010 07:16   |
David Grier
Messages: 35 Registered: July 2010
|
Member |
|
|
On 10/11/10 9:39 AM, silje wrote:
> Hey!
> I'm trying to get a grip of the Histogram function in IDL, but have
> run into a problem that I don't understand. As you can see from the
> code below I have created an array with six differend elements,but
> when I call HISTOGRAM with a binsize equal to 0.1 then it seems like
> 1.2 and 1.3 is put in the same bin. Why is this?
>
>
> IDL> arr = [1.1,1.2,1.3,1.4,1.5,1.6]
> IDL> print, HISTOGRAM(FLOAT(arr), binsize=0.1)
> 1 2 1 1 1
>
>
> Thanks!
> Best regards Silje
This question hinges on (1) where HISTOGRAM places the origin of
its bins and (2) the representation of floating point numbers.
If you explicitly specify where you want the bins to start, then
HISTOGRAM does what you were expecting:
IDL> print, HISTOGRAM(arr, binsize=0.1, min=1.05)
1 1 1 1 1 1
The command you tried automatically set the origin of the first bin
to 1.1. Each data point then falls right on the dividing line between
two bins. Which way they should fall is clear in decimal notation.
The answer can be different when the same numbers are represented at
finite numerical precision. Your example exercises this distinction.
Here's why:
IDL> print, 1.1 + 2.*0.1 - 1.3
1.19209e-7
which is not zero. Therefore, your third data point falls into the
second bin because of round-off error.
Doing the same calculation in double precision "solves" the problem
IDL> print, 1.1d + 2.d*0.1d - 1.3d
0.0000000
TTFN,
David
|
|
|
|
Re: HISTOGRAM [message #82940 is a reply to message #44556] |
Wed, 23 January 2013 05:06  |
d.poreh
Messages: 406 Registered: October 2007
|
Senior Member |
|
|
On Wednesday, January 23, 2013 3:44:27 AM UTC-8, Helder wrote:
> On Wednesday, January 23, 2013 12:12:54 PM UTC+1, dave poreh wrote:
>
>> Folks,
>
>>
>
>> HI,
>
>>
>
>> I am trying to plot:
>
>>
>
>> IDL> hist = HISTOGRAM(x(2,*),MIN = -400, MAX =100, BINSIZE = 4)
>
>>
>
>> % Program caused arithmetic error: Floating illegal operand
>
>>
>
>> Turns out, with cg's everything is ok.
>
>>
>
>> Can you please help me?
>
>>
>
>> Cheers,
>
>>
>
>> Dave
>
>
>
> I'm not a histogram expert, but I had problems for badly defined BINSIZEs.
>
> If you read cgHistoplot help/definition of binsize you will find:
>
> "I've tried to protect you from most of the bad things"
>
> And:
>
> "While it is pointed out in the HISTOGRAM documentation, it is extremely important that the BINSIZE be of the same data type as the data you are going to calculate the histogram of."
>
>
>
> You put in binsize 4. Are your data integers? If not you might have a look at that...
>
>
>
> Cheers,
>
> Helder
Thanks Helder,
It was data type problem, and now working:)
Cheers,
Dave
|
|
|
Re: HISTOGRAM [message #82943 is a reply to message #44556] |
Wed, 23 January 2013 03:44  |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Wednesday, January 23, 2013 12:12:54 PM UTC+1, dave poreh wrote:
> Folks,
>
> HI,
>
> I am trying to plot:
>
> IDL> hist = HISTOGRAM(x(2,*),MIN = -400, MAX =100, BINSIZE = 4)
>
> % Program caused arithmetic error: Floating illegal operand
>
> Turns out, with cg's everything is ok.
>
> Can you please help me?
>
> Cheers,
>
> Dave
I'm not a histogram expert, but I had problems for badly defined BINSIZEs.
If you read cgHistoplot help/definition of binsize you will find:
"I've tried to protect you from most of the bad things"
And:
"While it is pointed out in the HISTOGRAM documentation, it is extremely important that the BINSIZE be of the same data type as the data you are going to calculate the histogram of."
You put in binsize 4. Are your data integers? If not you might have a look at that...
Cheers,
Helder
|
|
|
Re: HISTOGRAM [message #82944 is a reply to message #44556] |
Wed, 23 January 2013 03:26  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den onsdagen den 23:e januari 2013 kl. 12:12:54 UTC+1 skrev dave poreh:
> Folks,
>
> HI,
>
> I am trying to plot:
>
> IDL> hist = HISTOGRAM(x(2,*),MIN = -400, MAX =100, BINSIZE = 4)
>
> % Program caused arithmetic error: Floating illegal operand
>
> Turns out, with cg's everything is ok.
>
> Can you please help me?
>
> Cheers,
>
> Dave
If everything is ok, what do you need help for?
|
|
|