Quantile function of Poisson distribution kills gradiant

Asger_Jon_Vistisen: <p>OK, so in the source “code” of the poisson distribution under icdf we find the following:</p>
<pre><code class="lang-auto">
    def icdf(self, value):
        """
        Returns the inverse cumulative density/mass function evaluated at
        `value`.

        Args:
            value (Tensor):
        """
        raise NotImplementedError

</code></pre>
<p>So I tried to implement my own version, and indeed I have, except that it keeps killing the gradient.</p>
<p>In the following, x is an n by N tensor representing a sample of a random vector with n random variables and N samples. Lambda contains N identical column vectors of length n such that Lambda[i, any] is the mean of variable at i. The tensor x is uniformly distributed with mean 1/2 and variance 1/12.</p>
<p>Consider the quantile function Q of the Poisson distribution and compare it to the Taylor-Maclaurin power series for the exponential function. Then for some probability p, k = Q(p).</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/c/bc49d429e121c5c002948c680ea13bd9f4f24f53.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/bc49d429e121c5c002948c680ea13bd9f4f24f53" title="2020-09-12 13.34.49"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/c/bc49d429e121c5c002948c680ea13bd9f4f24f53_2_375x500.jpeg" alt="2020-09-12 13.34.49" data-base62-sha1="qRFWorhBMfGQI7McfRsa3S8l4CT" width="375" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/c/bc49d429e121c5c002948c680ea13bd9f4f24f53_2_375x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/b/c/bc49d429e121c5c002948c680ea13bd9f4f24f53_2_562x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/b/c/bc49d429e121c5c002948c680ea13bd9f4f24f53_2_750x1000.jpeg 2x" data-dominant-color="B1ACA9"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">2020-09-12 13.34.49</span><span class="informations">2736×3648 1.67 MB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>We can replace factorial of the tensor with the gamma function, but torch has only the log Gamma for some reason, so we need to replace n! with torch.exp(torch.lgamma(n+1)).</p>
<p>So my code does this by incrementing tensor k by Heaviside of the difference between the left and right-hand sides:</p>
<pre><code class="lang-auto">k = torch.zeros(n, N)
Taylor = torch.pow(Lambda, k) / torch.exp(torch.lgamma(k + 1))
while torch.sum(torch.exp(Lambda) * x - Taylor) &gt; 0:
   k = k + torch.heaviside(torch.sum(torch.exp(Lambda) * x - Taylor))
   Taylor = Taylor + torch.pow(Lambda, k) / torch.exp(torch.lgamma(k + 1))

</code></pre>
<p>But the grads disappear whenever I use the above procedure in a function.</p>
<p>Some help would be much appreciated! Scipy does have a such a feature, is it possible to use it on the gpu perhaps?</p>
<p>Sincerely,<br>
// Asger Jon Vistisen</p>

googlebot: <p>You’re implementing a discrete function, thus there no gradients.</p>