From 3fceef9d67ba256c45c8fcda723749251731f6e2 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Tue, 4 Jun 2013 16:49:42 +0100 Subject: [PATCH] added domains in transformatins and priors --- GPy/core/priors.py | 2 ++ GPy/core/transformations.py | 21 ++++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/GPy/core/priors.py b/GPy/core/priors.py index f9307b94..33bcdc69 100644 --- a/GPy/core/priors.py +++ b/GPy/core/priors.py @@ -6,8 +6,10 @@ import numpy as np import pylab as pb from scipy.special import gammaln, digamma from ..util.linalg import pdinv +from GPy.core.domains import UNDEFINED class prior: + domain = UNDEFINED def pdf(self,x): return np.exp(self.lnpdf(x)) diff --git a/GPy/core/transformations.py b/GPy/core/transformations.py index 2dbe33af..b9748984 100644 --- a/GPy/core/transformations.py +++ b/GPy/core/transformations.py @@ -3,11 +3,10 @@ import numpy as np +from GPy.core.domains import UNDEFINED, POSITIVE, NEGATIVE, BOUNDED class transformation(object): - def __init__(self): - # set the domain. Suggest we use 'positive', 'bounded', etc - self.domain = 'undefined' + domain = UNDEFINED def f(self, x): raise NotImplementedError @@ -24,8 +23,7 @@ class transformation(object): raise NotImplementedError class logexp(transformation): - def __init__(self): - self.domain = 'positive' + domain = POSITIVE def f(self, x): return np.log(1. + np.exp(x)) def finv(self, f): @@ -43,8 +41,8 @@ class logexp_clipped(transformation): min_bound = 1e-10 log_max_bound = np.log(max_bound) log_min_bound = np.log(min_bound) + domain = POSITIVE def __init__(self, lower=1e-6): - self.domain = 'positive' self.lower = lower def f(self, x): exp = np.exp(np.clip(x, self.log_min_bound, self.log_max_bound)) @@ -66,8 +64,7 @@ class logexp_clipped(transformation): return '(+ve_c)' class exponent(transformation): - def __init__(self): - self.domain = 'positive' + domain = POSITIVE def f(self, x): return np.exp(x) def finv(self, x): @@ -82,8 +79,7 @@ class exponent(transformation): return '(+ve)' class negative_exponent(transformation): - def __init__(self): - self.domain = 'negative' + domain = NEGATIVE def f(self, x): return -np.exp(x) def finv(self, x): @@ -98,8 +94,7 @@ class negative_exponent(transformation): return '(-ve)' class square(transformation): - def __init__(self): - self.domain = 'positive' + domain = POSITIVE def f(self, x): return x ** 2 def finv(self, x): @@ -112,8 +107,8 @@ class square(transformation): return '(+sq)' class logistic(transformation): + domain = BOUNDED def __init__(self, lower, upper): - self.domain = 'bounded' assert lower < upper self.lower, self.upper = float(lower), float(upper) self.difference = self.upper - self.lower