Repository: awslabs/gluonts

Issue:
Binned distribution gives wrong quantiles if the probability of first bin is nonzero
## Description
While expanding bin centers, [the code](https://github.com/awslabs/gluon-ts/blob/a9cde7bf92178b4cf8010a4c8600940b595f2ae3/src/gluonts/distribution/binned.py#L154) incorrectly adds the probabilities of the first bin to the bin centers ([`zeros_cdf` has the probabilities of the initial bin for all batch elements/time points](https://github.com/awslabs/gluon-ts/blob/a9cde7bf92178b4cf8010a4c8600940b595f2ae3/src/gluonts/distribution/binned.py#L138)).

Also the [index](https://github.com/awslabs/gluon-ts/blob/a9cde7bf92178b4cf8010a4c8600940b595f2ae3/src/gluonts/distribution/binned.py#L146) returned is always zero and hence the quantile returned is the first bin + probability of the first bin, unless the initial bin probability is zero which is always the case in [tests](https://github.com/awslabs/gluon-ts/blob/a9cde7bf92178b4cf8010a4c8600940b595f2ae3/test/distribution/test_distribution_sampling.py#L84).

## To Reproduce
```
In [1]: import mxnet as mx                                                                                                                                                                     
from
In [2]: from gluonts.distribution import Binned                                                                                                                                                

In [3]: binned = Binned(bin_probs=mx.nd.array([[0.5, 0.2, 0.15, 0.15]]), bin_centers=mx.nd.array([[1e-4, 1e-3, 1e-2, 1e-1]]))                                                                  

In [4]: binned.quantile(mx.nd.array([0.1, 0.5, 0.7, 0.9, 0.999]))                                                                                                                              
Out[4]: 

[[0.5001]
 [0.5001]
 [0.5001]
 [0.5001]
 [0.5001]]
<NDArray 5x1 @cpu(0)>

```
## Fix
Replacing `broadcast_add` by `broadcast_mul` [here](https://github.com/awslabs/gluon-ts/blob/a9cde7bf92178b4cf8010a4c8600940b595f2ae3/src/gluonts/distribution/binned.py#L138) seems to solve both  problems. I think `zeros_cdf` was meant to be zeros not the probabilities of the first bin.

After fix:

```
In [4]: binned.quantile(mx.nd.array([0.1, 0.5, 0.7, 0.9, 0.999]))                                                                                                                              
Out[4]: 

[[1.e-04]
 [1.e-03]
 [1.e-02]
 [1.e-01]
 [1.e-01]]
<NDArray 5x1 @cpu(0)>

```


Discussion:
@rshyamsundar the bin centers appear not to be sorted in your example: does the distribution assume that they are?
Right, it assumes it is sorted but the result would still be wrong. Let me update the example.

Resolving patch:
diff --git a/src/gluonts/distribution/binned.py b/src/gluonts/distribution/binned.py
--- a/src/gluonts/distribution/binned.py
+++ b/src/gluonts/distribution/binned.py
@@ -129,9 +129,10 @@ def quantile(self, level: Tensor) -> Tensor:
         F = self.F
 
         probs = self.bin_probs.swapaxes(0, 1)  # (num_bins, batch)
-        zeros_batch_size = F.slice_axis(probs, axis=0, begin=0, end=1).squeeze(
-            axis=0
-        )  # (batch_size,)
+        # (batch_size,)
+        zeros_batch_size = F.zeros_like(
+            F.slice_axis(probs, axis=0, begin=0, end=1).squeeze(axis=0)
+        )
 
         level = level.expand_dims(axis=0)
         # cdf shape (batch_size, levels)


Test patch:
diff --git a/test/distribution/test_distribution_sampling.py b/test/distribution/test_distribution_sampling.py
--- a/test/distribution/test_distribution_sampling.py
+++ b/test/distribution/test_distribution_sampling.py
@@ -81,7 +81,7 @@
         Binned,
         {
             "bin_probs": mx.nd.array(
-                [[0, 0.3, 0.1, 0.05, 0.2, 0.1, 0.25]]
+                [[0.1, 0.2, 0.1, 0.05, 0.2, 0.1, 0.25]]
             ).repeat(axis=0, repeats=2),
             "bin_centers": mx.nd.array(
                 [[-5, -3, -1.2, -0.5, 0, 0.1, 0.2]]