MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: BinCounts

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60938] Re: BinCounts
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Tue, 4 Oct 2005 01:25:03 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 10/3/05 at 4:06 AM, Alberto.Verga at laposte.net (Alberto Verga)
wrote:

>Why does BinCounts[] give lists with unpredictable Dimensions[]?

>With[{n = 205}, ll = RandomArray[NormalDistribution[0, 1], {n}];
>Dimensions[BinCounts[ll, {Min[ll], Max[ll], (Max[ll] -
>Min[ll])/n}]]]

>You may try different values of n (or the same n and different
>samples of the random numbers), and verify that the lenght of the
>list depends on the random realization: somtimes you get n,
>somtimes n+1.

The problem is machine precision arithmetic. That is:

In[53]:=
With[{n = 205},ll = RandomArray[NormalDistribution[0, 1], {n}]; 
   {Dimensions[BinCounts[ll, {Min[ll], Max[ll],
              (Max[ll] - Min[ll])/n}]], {Min[ll], 
     Max[ll], (Max[ll] - Min[ll])/n}}]
Out[53]=
{{205}, {-3.302584971143743, 2.7338025952981977, 
         0.029445793007033857}}
In[54]:=
Ceiling[-Subtract @@ Most[Last[%]]/Last[Last[%]]]
Out[54]=
205

In[58]:=
With[{n = 205},ll = RandomArray[NormalDistribution[0, 1], {n}]; 
   {Dimensions[BinCounts[ll, {Min[ll], Max[ll],
              (Max[ll] - Min[ll])/n}]], {Min[ll], 
     Max[ll], (Max[ll] - Min[ll])/n}}]
Out[58]=
{{206}, {-2.4474345430719238, 2.3650239930276675, 
         0.023475407493168735}}
In[59]:=
Ceiling[-Subtract @@ Most[Last[%]]/Last[Last[%]]]
Out[59]=
206

Or in other words when the nearest machine precision number to the bin range divied by the bin width is less than or equal to n you get n bins. Otherwise you get n+1 bins.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Finding length in recursive definition?
  • Next by Date: "Mathematica in Education and Research"
  • Previous by thread: Re: BinCounts
  • Next by thread: LogGamma[z] vs Log[Gamma[z]] behavior