Talk:Sparkline in unicode: Difference between revisions

Line 120:
 
[[User:Hout|Hout]] ([[User talk:Hout|talk]]) 18:21, 26 February 2019 (UTC)
 
:: > I '''don't''' think that we can really give a test case like test 2 above, and define what the output should be.
 
: We surely can. The range has 8000 sequential integers and there are 8 bins. Each bin should contain 1000 of the integers. This bug even has a name: ''fencepost error''.
 
: ''NB: To avoid confusion, I'm going to discuss this in the context of data that are a sequence of consecutive integers. The same reasoning can be applied to floats if you imagine them as integers that are all divided by some common denominator. Which is exactly what they are. Discontinuous or unordered data doesn't affect the math at all; it's just easier to think about when <code>n==max-min+1</code>.''
 
: <code>max-min</code> is one smaller than the number of integers in the range; the mathematically correct bin assignment is simply <code>int( bins * (v-min) / (max-min+1) )</code>. The <code>+1</code> is a fencepost; the formula yields a non-negative integer smaller than the number of bins.
 
: There are two problems with this "correct" approach:
 
:: 1. Real-life floating-point division is imperfect. The division may return 1, which would give an out-of-bounds index.
 
:: 2. If our data is ''not'' integers, the size of the fencepost is not <code>1</code>. Determining its actual size might get complicated.
 
: The suggested solution&mdash;<code>max-min</code> denominator with clamping&mdash;is simpler and more robust. It does not generalize to arbitrary binning problems, because it makes the last bin too wide. For our purposes, though, it's as correct as anything else: the "error" is maximized when <code>n==9</code> and it's clear that there's no way to avoid having seven bins with one value each, plus one bin with two values.
 
: Good arguments may exist for the necessarily-larger bin to be inconsistently decided, or for it to be any other than the first or last bin, but I can't think of any.
 
:: -- [[User:Oopsiedaisy|Oopsiedaisy]], 26 February 2019 (UTC)
 
==Bar choices==