Skip to content

Commit

Permalink
Improve docstring with Gamma function comment
Browse files Browse the repository at this point in the history
Mention that the continuous approximation is done using n! = Gamma(n+1)

Additionally use :code: and :math: qualifiers on different terms to give
specific highlighting in the rendered docs
  • Loading branch information
matthewfeickert committed Sep 20, 2018
1 parent b02d7ae commit 94b6e8e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
14 changes: 8 additions & 6 deletions pyhf/tensor/mxnet_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ def einsum(self, subscripts, *operands):
return self.astensor([])

def poisson(self, n, lam):
"""
The continous approximation to the probability mass function of the Poisson
distribution given the parameter `lam` evaluated at `n`.
r"""
The continous approximation, using :math:`n! = \Gamma\left(n+1\right)`,
to the probability mass function of the Poisson distribution evaluated
at :code:`n` given the parameter :code:`lam`.
Example:
Expand Down Expand Up @@ -372,9 +373,10 @@ def poisson(self, n, lam):
return nd.exp((nd.log(lam) * n) - lam - nd.gammaln(n + 1.))

def normal(self, x, mu, sigma):
"""
The probability density function of the Normal distribution given the parameters
evaluated at `x`.
r"""
The probability density function of the Normal distribution evaluated
at :code:`x` given parameters of mean of :code:`mu` and standard deviation
of :code:`sigma`.
Example:
Expand Down
16 changes: 9 additions & 7 deletions pyhf/tensor/numpy_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ def einsum(self, subscripts, *operands):
return np.einsum(subscripts, *operands)

def poisson(self, n, lam):
"""
The continous approximation to the probability mass function of the Poisson
distribution given the parameter `lam` evaluated at `n`.
r"""
The continous approximation, using :math:`n! = \Gamma\left(n+1\right)`,
to the probability mass function of the Poisson distribution evaluated
at :code:`n` given the parameter :code:`lam`.
Example:
Expand All @@ -182,12 +183,13 @@ def poisson(self, n, lam):
"""
n = np.asarray(n)
lam = np.asarray(lam)
return np.exp((np.log(lam) * n) - lam - gammaln(n + 1.))
return np.exp(n * np.log(lam) - lam - gammaln(n + 1.))

def normal(self, x, mu, sigma):
"""
The probability density function of the Normal distribution given parameters
of mean of `mu` and standard deviation of `sigma` evaluated at `x`.
r"""
The probability density function of the Normal distribution evaluated
at :code:`x` given parameters of mean of :code:`mu` and standard deviation
of :code:`sigma`.
Example:
Expand Down
14 changes: 8 additions & 6 deletions pyhf/tensor/pytorch_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ def einsum(self, subscripts, *operands):
return torch.einsum(subscripts, ops)

def poisson(self, n, lam):
"""
The continous approximation to the probability mass function of the Poisson
distribution given the parameter `lam` evaluated at `n`.
r"""
The continous approximation, using :math:`n! = \Gamma\left(n+1\right)`,
to the probability mass function of the Poisson distribution evaluated
at :code:`n` given the parameter :code:`lam`.
Example:
Expand All @@ -196,9 +197,10 @@ def poisson(self, n, lam):
return torch.exp(torch.distributions.Poisson(lam).log_prob(n))

def normal(self, x, mu, sigma):
"""
The probability density function of the Normal distribution given parameters
of mean of `mu` and standard deviation of `sigma` evaluated at `x`.
r"""
The probability density function of the Normal distribution evaluated
at :code:`x` given parameters of mean of :code:`mu` and standard deviation
of :code:`sigma`.
Example:
Expand Down
14 changes: 8 additions & 6 deletions pyhf/tensor/tensorflow_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ def einsum(self, subscripts, *operands):
return tf.einsum(subscripts, *operands)

def poisson(self, n, lam):
"""
The continous approximation to the probability mass function of the Poisson
distribution given the parameter `lam` evaluated at `n`.
r"""
The continous approximation, using :math:`n! = \Gamma\left(n+1\right)`,
to the probability mass function of the Poisson distribution evaluated
at :code:`n` given the parameter :code:`lam`.
Example:
Expand Down Expand Up @@ -230,9 +231,10 @@ def poisson(self, n, lam):
return tf.exp(tf.contrib.distributions.Poisson(lam).log_prob(n))

def normal(self, x, mu, sigma):
"""
The probability density function of the Normal distribution given parameters
of mean of `mu` and standard deviation of `sigma` evaluated at `x`.
r"""
The probability density function of the Normal distribution evaluated
at :code:`x` given parameters of mean of :code:`mu` and standard deviation
of :code:`sigma`.
Example:
Expand Down

0 comments on commit 94b6e8e

Please sign in to comment.