fix: uniform prior can be positive and negative, depending on lower and upper bound

This commit is contained in:
mzwiessele 2017-10-02 11:47:25 +01:00
parent 038412acbb
commit 28487a9551

View file

@ -5,7 +5,7 @@
import numpy as np
from scipy.special import gammaln, digamma
from ...util.linalg import pdinv
from paramz.domains import _REAL, _POSITIVE
from paramz.domains import _REAL, _POSITIVE, _NEGATIVE
import warnings
import weakref
@ -92,7 +92,6 @@ class Gaussian(Prior):
# self.constant = -0.5 * np.log(2 * np.pi * self.sigma2)
class Uniform(Prior):
domain = _REAL
_instances = []
def __new__(cls, lower=0, upper=1): # Singleton:
@ -108,6 +107,13 @@ class Uniform(Prior):
def __init__(self, lower, upper):
self.lower = float(lower)
self.upper = float(upper)
assert self.lower < self.upper, "Lower needs to be strictly smaller than upper."
if self.lower >= 0:
self.domain = _POSITIVE
elif self.upper <= 0:
self.domain = _NEGATIVE
else:
self.domain = _REAL
def __str__(self):
return "[{:.2g}, {:.2g}]".format(self.lower, self.upper)