Student Support Forum: 'BinCounts bug' topicStudent Support Forum > General > "BinCounts bug"

 < Previous Comment Help | Reply To Comment | Reply To Topic
 Author Comment/Response Fprum Moderator 11/05/07 12:19pm I got a lot of help from Peter Pein in understanding what the issues were in your example. It looks like a couple of things are going on. First V6 counts into different bins than V5. Here is an example of the different behaviors: ---6.0---- In[28]:= BinCounts[{100}, {98, 102, 1}] Out[28]= {0,0,1,0} ----5.2---- In[2]:= < 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, > 0, 0, 1, 1, 0, 0, 1, 1}, -2} The last 1 causes rounding up and we get: In[1]:= FromDigits[ {{1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0}, -2}, 2] 3602879701896397 Out[1]= ----------------- 18014398509481984 In[2]:= % > 1/5 Out[2]= True so it is very slightly larger. Here are the results of floating point numbers just above and below 0.2: In[1]:= 494 Interval[0.2] Out[1]= Interval[{98.8, 98.8}] In[2]:= InputForm[%] Out[2]//InputForm= Interval[{98.79999999999998, 98.80000000000004}] So we can expect a number between these bounds, but not necessarily 98.8 in decimal. Based on this, the position of the middle 1 in the BinCounts example is an artifact of machine arithmetic and consistent with the docs, and the user can use an exact step of 1/5 to avoid this. --------- So, this works: In[28]:= BinCounts[{101.13528790591918`,100,98.85051300731969`},{98.8,101,1/5}] Out[28]= {1,0,0,0,0,0,1,0,0,0,0,1} Tom Zeller URL: ,

 Subject (listing for 'BinCounts bug') Author Date Posted BinCounts bug Humphrey 10/05/07 11:00am Re: BinCounts bug Peter Pein 10/11/07 2:20pm Re: Re: BinCounts bug Humphrey 10/12/07 08:09am Re: BinCounts bug Fprum Modera... 11/05/07 12:19pm
 < Previous Comment Help | Reply To Comment | Reply To Topic