I am sure this is trivial, but I am looking for a transformation that nonuniformly discretizes all values of a range into several bins. The bins should be variant and I'd like them to be smaller around the middle of my distribution and grows larger around both ends. Say, instead of one fixed \delta as the step size for a uniform binning as below: enter image description here

I'd like to have the following binning:

enter image description here

Where around the middle of the distribution, I have $\delta_{min}$ and they grow gradually (linearly) to $\delta_{max}$ on both ends.

Do we have a transformation/regularization which does the following without the need to know the value of each element inside the bin and can generate all variable deltas at runtime? For instance, for the uniform binning I can write $d=\frac{maxValue- minValue}{\#ofBins}$ and I can update the values of all members of each bin (W) to the middle of each bin.

  • $\begingroup$ What do you mean by data-independent? Do you mean that the same bins will be created independent of the values you are transforming? If so, then you can simply specify the bins ahead of time before doing anything else. If not, I'm not clear on what you mean.... $\endgroup$ – roundsquare Oct 5 '19 at 15:06
  • $\begingroup$ @roundsquare, sorry for the misunderstanding. I was referring to a data-independent binning for such transformation that does not require to need the values of x to select the width of the bins and only needs the minValue and maxValues to do so, $\endgroup$ – Amir Oct 6 '19 at 2:03
  • 1
    $\begingroup$ got it, makes sense. Just to be clear then, if all you know is the min/max values, there is no way to guarantee that the distribution will be similar to the figure in your question. For example, assume that the minValue = 0 and maxValue = 100. You would have no way to know if, for example, the values are uniformly distributed, 90% of the values are greater than 90, etc... That doesn't mean you can't do such a binning, it just means that you don't know if your bins will be (very) unevenly distributed. $\endgroup$ – roundsquare Oct 6 '19 at 14:01
  • $\begingroup$ Out of curiosity, what is the situation in which you know the min/max values but don't know the other values? Is it just an extremely large data set? $\endgroup$ – roundsquare Oct 6 '19 at 14:07
  • $\begingroup$ I am dealing with the static graph generation of TensorFlow for which you don't know the values of the variable before running the graph. $\endgroup$ – Amir Oct 6 '19 at 15:35

The most general solution uses a nondecreasing function $F:(0,1]\to[0,1]$ and the desired interval $(a,b]$ of values to bin.

To create $n$ bins, divide the unit interval $(0,1]$ into $n$ non-overlapping sections

$$B_i = \left(\frac{i-1}{n}, \frac{i}{n}\right],\ i=1, 2, \ldots, n$$

and assign any number $x$ with $a\lt x \le b$ into bin $i$ where $i$ is the unique value with

$$F_{a,b}(x) = F\left(\frac{x-a}{b-a}\right) \in B_i.$$

When $x$ is uniformly distributed between $a$ and $b,$ the expected proportion of values in bin $i$ therefore is $F_{a,b}(i/n)- F_{a,b}((i-1)/n).$

In the plots of the question, the blue graphs represent the derivative of $F$ and these expected proportions, by the Fundamental Theorem of Calculus, are the relative areas between the vertical lines. You may construct such an $F,$ then, by stipulating what you want the expected "concentration" of points at each value of $x$ to be--a non-negative number $f(x)$--and computing

$$F_{a,b}(x) = C\int_a^x f(t)\mathrm{d}t.$$

The value of $C$ is chosen to make $F_{a,b}(b) = 1.$

For examples, the usual uniform binning corresponds to the identity function $F$ on $(0,1]$ for which $f(x)=1.$ Logarithmic binning corresponds to $F_{a,b}(x) = \log(x/a)/log(b/a),$ for which $f_{a,b}(x) = 1/(ax\log(b/a)).$

  • $\begingroup$ thanks @whuber for the reply. Correct me if I am wrong, but the logarithmic binning still needs to know the histogram of the weights. I'd like to have a data-free nonuniform binning within only max and min of the distribution. $\endgroup$ – Amir Oct 5 '19 at 6:56
  • 1
    $\begingroup$ That's precisely what my log binning prescription does: it depends only on $a$ and $b$ and not on the data. $\endgroup$ – whuber Oct 5 '19 at 16:48
  • 1
    $\begingroup$ You specify the number of bins $n$ and just follow the recipe. For instance, with $a=1,b=8,$ and $n=3,$ $$F_{1,8}(x)=\log(x)/\log(8)=\frac{1}{3}\log_2(x)$$ and the endpoints for the $B_i$ are at $0,1/3,2/3,1.$ Thus you solve the equations $$\frac{1}{3}\log_2(x) \in \{0,1/3,2/3,1\}$$ with solutions $\{1,2,4,8\}$ to determine the bin cutpoints. It's advisable to place the data based on the midpoints of the $B_i,$ which are at $1/6,1/2,5/6$ corresponding to values $$x\in \{2^{3/6},2^{3/2},2^{5/2}\}\approx \{1.4,2.8,5.6\}.$$ $\endgroup$ – whuber Oct 6 '19 at 15:21
  • 1
    $\begingroup$ The $B_i$ are bins for the values of $F(x),$ not for $x$ itself. The cutpoints, as stated, solve four equations. For instance, one of them is $$\frac{1}{3}\log_2(x)=\frac{2}{3}.$$ The rules of algebra and logarithms give the solution $x=2^{3\times 2/3}=4.$ $\endgroup$ – whuber Oct 6 '19 at 17:14
  • 1
    $\begingroup$ right right! all clear now and thanks again. I appreciate your time. $\endgroup$ – Amir Oct 6 '19 at 18:34

Use quantiles.

The lowest 10% are the first bin, the next 10% are the second bin ...

If you hypothesize a data distribution, you can also use quantiles of the distribution for such a binning.

For example to split a standard normal distribution into 11 bins, you would use: $-\infty$ -1.28155 -0.84162 -0.52440 -0.25335 0.00000 0.25335 0.52440 0.84162 1.28155 $\infty$

  • 1
    $\begingroup$ It needs to know the data a priori. I 'd like a data independent nonuniform binning, otherwise they were many options available $\endgroup$ – Amir Oct 5 '19 at 14:35
  • 1
    $\begingroup$ You can use quantiles of an assumed Gaussian distribution, for example. $\endgroup$ – Has QUIT--Anony-Mousse Oct 6 '19 at 5:24
  • $\begingroup$ that's a great idea. $\endgroup$ – Amir Oct 6 '19 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.