Skip to content
Snippets Groups Projects
Commit 1ce4e073 authored by Paul Lasky's avatar Paul Lasky
Browse files

Merge branch 'allow-scaled-beta' into 'master'

allow beta distribution to have user specified loc/scale

See merge request !291
parents ce11e168 17699355
No related branches found
No related tags found
1 merge request!291allow beta distribution to have user specified loc/scale
Pipeline #39806 passed
......@@ -1218,17 +1218,25 @@ class StudentT(Prior):
class Beta(Prior):
def __init__(self, alpha, beta, name=None, latex_label=None, unit=None):
def __init__(self, alpha, beta, minimum=0, maximum=1, name=None,
latex_label=None, unit=None):
"""Beta distribution
https://en.wikipedia.org/wiki/Beta_distribution
This wraps around
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.beta.html
Parameters
----------
alpha: float
first shape parameter
beta: float
second shape parameter
minimum: float
See superclass
maximum: float
See superclass
name: str
See superclass
latex_label: str
......@@ -1237,7 +1245,7 @@ class Beta(Prior):
See superclass
"""
Prior.__init__(self, minimum=0., maximum=1., name=name,
Prior.__init__(self, minimum=minimum, maximum=maximum, name=name,
latex_label=latex_label, unit=unit)
if alpha <= 0. or beta <= 0.:
......@@ -1245,6 +1253,8 @@ class Beta(Prior):
self.alpha = alpha
self.beta = beta
self._loc = minimum
self._scale = maximum - minimum
def rescale(self, val):
"""
......@@ -1255,7 +1265,8 @@ class Beta(Prior):
Prior.test_valid_for_rescaling(val)
# use scipy distribution percentage point function (ppf)
return scipy.stats.beta.ppf(val, self.alpha, self.beta)
return scipy.stats.beta.ppf(
val, self.alpha, self.beta, loc=self._loc, scale=self._scale)
def prob(self, val):
"""Return the prior probability of val.
......@@ -1269,7 +1280,8 @@ class Beta(Prior):
float: Prior probability of val
"""
spdf = scipy.stats.beta.pdf(val, self.alpha, self.beta)
spdf = scipy.stats.beta.pdf(
val, self.alpha, self.beta, loc=self._loc, scale=self._scale)
if np.all(np.isfinite(spdf)):
return spdf
......@@ -1282,7 +1294,8 @@ class Beta(Prior):
return 0.
def ln_prob(self, val):
spdf = scipy.stats.beta.logpdf(val, self.alpha, self.beta)
spdf = scipy.stats.beta.logpdf(
val, self.alpha, self.beta, loc=self._loc, scale=self._scale)
if np.all(np.isfinite(spdf)):
return spdf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment