mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-15 06:52:39 +02:00
fix: uniform prior can be positive and negative, depending on lower and upper bound
This commit is contained in:
parent
038412acbb
commit
28487a9551
1 changed files with 8 additions and 2 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy.special import gammaln, digamma
|
from scipy.special import gammaln, digamma
|
||||||
from ...util.linalg import pdinv
|
from ...util.linalg import pdinv
|
||||||
from paramz.domains import _REAL, _POSITIVE
|
from paramz.domains import _REAL, _POSITIVE, _NEGATIVE
|
||||||
import warnings
|
import warnings
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
|
|
@ -92,7 +92,6 @@ class Gaussian(Prior):
|
||||||
# self.constant = -0.5 * np.log(2 * np.pi * self.sigma2)
|
# self.constant = -0.5 * np.log(2 * np.pi * self.sigma2)
|
||||||
|
|
||||||
class Uniform(Prior):
|
class Uniform(Prior):
|
||||||
domain = _REAL
|
|
||||||
_instances = []
|
_instances = []
|
||||||
|
|
||||||
def __new__(cls, lower=0, upper=1): # Singleton:
|
def __new__(cls, lower=0, upper=1): # Singleton:
|
||||||
|
|
@ -108,6 +107,13 @@ class Uniform(Prior):
|
||||||
def __init__(self, lower, upper):
|
def __init__(self, lower, upper):
|
||||||
self.lower = float(lower)
|
self.lower = float(lower)
|
||||||
self.upper = float(upper)
|
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):
|
def __str__(self):
|
||||||
return "[{:.2g}, {:.2g}]".format(self.lower, self.upper)
|
return "[{:.2g}, {:.2g}]".format(self.lower, self.upper)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue