histogram function question [message #90517] |
Fri, 06 March 2015 06:03  |
Dae-Kyu Shin
Messages: 25 Registered: February 2015
|
Junior Member |
|
|
hi
here is a example code
data = [0, 0.3, 1.3d]
h1 = HISTOGRAM(data, nbin=3, min=0, max=1, loc=loc1)
h2 = HISTOGRAM(data, binsize=0.5d, min=0, max=1, loc=loc2)
print, h1
print, h2
h1 = 2 0 1
h2 = 2 0 0
h1 and h2 is not equal!!
is it correct??
thanks
|
|
|
|
Re: histogram function question [message #90519 is a reply to message #90517] |
Fri, 06 March 2015 06:24   |
Dae-Kyu Shin
Messages: 25 Registered: February 2015
|
Junior Member |
|
|
2015년 3월 6일 금요일 오후 11시 3분 5초 UTC+9, Dae-Kyu Shin 님의 말:
> hi
>
> here is a example code
>
>
> data = [0, 0.3, 1.3d]
> h1 = HISTOGRAM(data, nbin=3, min=0, max=1, loc=loc1)
> h2 = HISTOGRAM(data, binsize=0.5d, min=0, max=1, loc=loc2)
>
> print, h1
> print, h2
>
> h1 = 2 0 1
> h2 = 2 0 0
>
>
> h1 and h2 is not equal!!
> is it correct??
>
>
> thanks
IDL verssion : 8.4
|
|
|
Re: histogram function question [message #90520 is a reply to message #90517] |
Fri, 06 March 2015 06:26   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Dae-Kyu Shin writes:
>
> hi
>
> here is a example code
>
>
> data = [0, 0.3, 1.3d]
> h1 = HISTOGRAM(data, nbin=3, min=0, max=1, loc=loc1)
> h2 = HISTOGRAM(data, binsize=0.5d, min=0, max=1, loc=loc2)
>
> print, h1
> print, h2
>
> h1 = 2 0 1
> h2 = 2 0 0
>
>
> h1 and h2 is not equal!!
> is it correct??
I don't think so:
IDL> data = [0, 0.3, 1.3d]
IDL> h1 = cghistogram(data, nbin=3, min=0.0, max=1.0 ,loc=loc1)
IDL> h2 = cghistogram(data, binsize=0.5d, min=0.0, max=1.0 ,loc=loc2)
IDL> print, h1
2 0 0
IDL> print, h2
2 0 0
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|
|
Re: histogram function question [message #90523 is a reply to message #90522] |
Fri, 06 March 2015 07:15   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Friday, March 6, 2015 at 3:31:31 PM UTC+1, Matthew Argall wrote:
>> Note: The data type of the value specified for MIN should match the data type of the input array. Since MIN is converted to the data type of the input array, specifying mismatched data types may produce undesired results.
>>
>> In the first case, 0.3 and 1.3 are truncated to 0 and 1, respectively.
>
> Maybe I should learn how to read, too :-p The MIN, MAX, and BINSIZE values are converted to the input type, not the other way around.
>
> However, the behavior is as if the input array is converted to integer type...
cgHistogram works because it calculates the histogram() *always* using binsize. When nbins is present instead of binsize, cgHistogram calculates binsize (after taking care of the types).
As far as the example goes, the result is the same also when the type of min, max and binsize are the same as the input data.
I find the result a bit strange, because the bin locations are not what I would expect them to be! I would have expected the bin locations to be:
nbins=3 -> [0-0.3, 0.3-0.6 and 0.6-1.0]
Because histogram should distribute 3 bins evenly between 0.0 and 1.0.
binsize=0.5 -> [0.0-0.5 and 0.5-1.0] (for only 2 bins... not 3)
Because the bins sizes should be starting at 0.0 and have a size of 0.5.
So I would have expected the following two results:
2, 0, 0
and
2, 0
Maybe this is just a problem with my understanding of the histogram function. I'll read about it over weekend and maybe I will have an idea of what's happening...
I guess, that generally speaking, the histogram function is wyginwye (well known acronym for "what you get is not what you expect").
IDL> data = [0, 0.3, 1.3d]
IDL> print, HISTOGRAM(data, nbin=3, min=0d, max=1d, loc=loc1), HISTOGRAM(data, binsize=0.5d, min=0d, max=1d, loc=loc2)
IDL> print, loc1, loc2
2 0 1
2 0 0
0.00000000 0.50000000 1.0000000
0.00000000 0.50000000 1.0000000
I'll stick to cgHistogram. At least it's consistent!
h
|
|
|
Re: histogram function question [message #90524 is a reply to message #90517] |
Fri, 06 March 2015 08:08   |
Burch
Messages: 28 Registered: December 2013
|
Junior Member |
|
|
On Friday, March 6, 2015 at 8:03:05 AM UTC-6, Dae-Kyu Shin wrote:
> hi
>
> here is a example code
>
>
> data = [0, 0.3, 1.3d]
> h1 = HISTOGRAM(data, nbin=3, min=0, max=1, loc=loc1)
> h2 = HISTOGRAM(data, binsize=0.5d, min=0, max=1, loc=loc2)
>
> print, h1
> print, h2
>
> h1 = 2 0 1
> h2 = 2 0 0
>
>
> h1 and h2 is not equal!!
> is it correct??
>
>
> thanks
There is a note in the documentation for the MAX keyword:
"Note: If NBINS is specified, the value for MAX will be adjusted to NBINS*BINSIZE + MIN. This ensures that the last bin has the same width as the other bins."
So it seems for h1 BINSIZE is calculated to be
(max - min)/(nbins-1) = 0.5
and then max is adjusted to
nbins*binsize + min = 1.5,
whereas in h2 there is no *internal* adjustment to MAX.
-Jeff
|
|
|
|
|
Re: histogram function question [message #90527 is a reply to message #90526] |
Fri, 06 March 2015 09:48  |
Fabzi
Messages: 305 Registered: July 2010
|
Senior Member |
|
|
On 06.03.2015 17:43, Heinz Stege wrote:
> I may be wrong in my quick judgement, calling this a bug. However I
> think, that it is an "inartfully behaviour".
agreed. If the "loc" values are the same, then the binsize is the same,
then the histogram should be the same.
Fabien
|
|
|