added domains to priors

This commit is contained in:
Max Zwiessele 2013-06-04 17:03:29 +01:00
parent dbc4bc3f3c
commit e02804a671
2 changed files with 83 additions and 80 deletions

View file

@ -6,10 +6,11 @@ import numpy as np
import pylab as pb import pylab as pb
from scipy.special import gammaln, digamma from scipy.special import gammaln, digamma
from ..util.linalg import pdinv from ..util.linalg import pdinv
from GPy.core.domains import UNDEFINED from GPy.core.domains import REAL, POSITIVE
import warnings
class prior: class prior:
domain = UNDEFINED domain = None
def pdf(self, x): def pdf(self, x):
return np.exp(self.lnpdf(x)) return np.exp(self.lnpdf(x))
@ -31,7 +32,7 @@ class Gaussian(prior):
.. Note:: Bishop 2006 notation is used throughout the code .. Note:: Bishop 2006 notation is used throughout the code
""" """
domain = REAL
def __init__(self, mu, sigma): def __init__(self, mu, sigma):
self.mu = float(mu) self.mu = float(mu)
self.sigma = float(sigma) self.sigma = float(sigma)
@ -61,7 +62,7 @@ class log_Gaussian(prior):
.. Note:: Bishop 2006 notation is used throughout the code .. Note:: Bishop 2006 notation is used throughout the code
""" """
domain = POSITIVE
def __init__(self, mu, sigma): def __init__(self, mu, sigma):
self.mu = float(mu) self.mu = float(mu)
self.sigma = float(sigma) self.sigma = float(sigma)
@ -91,7 +92,7 @@ class multivariate_Gaussian:
.. Note:: Bishop 2006 notation is used throughout the code .. Note:: Bishop 2006 notation is used throughout the code
""" """
domain = REAL
def __init__(self, mu, var): def __init__(self, mu, var):
self.mu = np.array(mu).flatten() self.mu = np.array(mu).flatten()
self.var = np.array(var) self.var = np.array(var)
@ -140,7 +141,7 @@ def gamma_from_EV(E,V):
:param V: variance :param V: variance
""" """
warnings.warn("use Gamma.from_EV to create Gamma Prior", FutureWarning)
a = np.square(E) / V a = np.square(E) / V
b = E / V b = E / V
return gamma(a, b) return gamma(a, b)
@ -155,6 +156,7 @@ class gamma(prior):
.. Note:: Bishop 2006 notation is used throughout the code .. Note:: Bishop 2006 notation is used throughout the code
""" """
domain = POSITIVE
def __init__(self, a, b): def __init__(self, a, b):
self.a = float(a) self.a = float(a)
self.b = float(b) self.b = float(b)
@ -193,6 +195,7 @@ class inverse_gamma(prior):
.. Note:: Bishop 2006 notation is used throughout the code .. Note:: Bishop 2006 notation is used throughout the code
""" """
domain = POSITIVE
def __init__(self, a, b): def __init__(self, a, b):
self.a = float(a) self.a = float(a)
self.b = float(b) self.b = float(b)

View file

@ -3,10 +3,10 @@
import numpy as np import numpy as np
from GPy.core.domains import UNDEFINED, POSITIVE, NEGATIVE, BOUNDED from GPy.core.domains import POSITIVE, NEGATIVE, BOUNDED
class transformation(object): class transformation(object):
domain = UNDEFINED domain = None
def f(self, x): def f(self, x):
raise NotImplementedError raise NotImplementedError