From 7a5872e11d1ba4410ecf997400963039bd1e26db Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 2 Sep 2015 12:15:06 +0100 Subject: [PATCH 1/4] Model uses the new HeteroscedasticGaussian likelihood --- GPy/models/gp_heteroscedastic_regression.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/GPy/models/gp_heteroscedastic_regression.py b/GPy/models/gp_heteroscedastic_regression.py index 19cb18d8..2fe3b788 100644 --- a/GPy/models/gp_heteroscedastic_regression.py +++ b/GPy/models/gp_heteroscedastic_regression.py @@ -30,10 +30,7 @@ class GPHeteroscedasticRegression(GP): kernel = kern.RBF(X.shape[1]) #Likelihood - #likelihoods_list = [likelihoods.Gaussian(name="Gaussian_noise_%s" %j) for j in range(Ny)] - noise_terms = np.unique(Y_metadata['output_index'].flatten()) - likelihoods_list = [likelihoods.Gaussian(name="Gaussian_noise_%s" %j) for j in noise_terms] - likelihood = likelihoods.MixedNoise(likelihoods_list=likelihoods_list) + likelihood = likelihoods.HeteroscedasticGaussian(Y_metadata) super(GPHeteroscedasticRegression, self).__init__(X,Y,kernel,likelihood, Y_metadata=Y_metadata) From f780693577d0b52555a60061df5dd294b7afee9f Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 2 Sep 2015 13:29:33 +0100 Subject: [PATCH 2/4] New likelihood: HeteroscedasticGaussian --- GPy/likelihoods/__init__.py | 1 + GPy/likelihoods/gaussian.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/GPy/likelihoods/__init__.py b/GPy/likelihoods/__init__.py index 3157bd5b..3c39157d 100644 --- a/GPy/likelihoods/__init__.py +++ b/GPy/likelihoods/__init__.py @@ -1,6 +1,7 @@ from .bernoulli import Bernoulli from .exponential import Exponential from .gaussian import Gaussian +from .gaussian import HeteroscedasticGaussian from .gamma import Gamma from .poisson import Poisson from .student_t import StudentT diff --git a/GPy/likelihoods/gaussian.py b/GPy/likelihoods/gaussian.py index 7b001e17..ef4b26b1 100644 --- a/GPy/likelihoods/gaussian.py +++ b/GPy/likelihoods/gaussian.py @@ -326,7 +326,7 @@ class Gaussian(Likelihood): dF_dtheta = -0.5/lik_var + 0.5*(np.square(Y) + np.square(m) + v - 2*m*Y)/(lik_var**2) return F, dF_dmu, dF_dv, dF_dtheta.reshape(1, Y.shape[0], Y.shape[1]) -class Heteroscedastic_Gaussian(Gaussian): +class HeteroscedasticGaussian(Gaussian): def __init__(self, Y_metadata, gp_link=None, variance=1., name='het_Gauss'): if gp_link is None: gp_link = link_functions.Identity() @@ -335,7 +335,7 @@ class Heteroscedastic_Gaussian(Gaussian): print("Warning, Exact inference is not implemeted for non-identity link functions,\ if you are not already, ensure Laplace inference_method is used") - super(Heteroscedastic_Gaussian, self).__init__(gp_link, np.ones(Y_metadata['output_index'].shape[0])*variance, name) + super(HeteroscedasticGaussian, self).__init__(gp_link, np.ones(Y_metadata['output_index'].shape[0])*variance, name) def exact_inference_gradients(self, dL_dKdiag,Y_metadata=None): return dL_dKdiag[Y_metadata['output_index']][:,0] @@ -351,4 +351,4 @@ class Heteroscedastic_Gaussian(Gaussian): var += np.atleast_3d(np.eye(var.shape[0])*self.variance) else: var += self.variance - return mu, var \ No newline at end of file + return mu, var From 21f6b92475b05c7caee3e32389c63b655790f25d Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 2 Sep 2015 13:32:06 +0100 Subject: [PATCH 3/4] Change in _diag_ufunc with @mzwiessele --- GPy/util/diag.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GPy/util/diag.py b/GPy/util/diag.py index e7c332e2..9a3343f0 100644 --- a/GPy/util/diag.py +++ b/GPy/util/diag.py @@ -46,6 +46,8 @@ def offdiag_view(A, offset=0): return as_strided(Af[(1+offset):], shape=(A.shape[0]-1, A.shape[1]), strides=(A.strides[0] + A.itemsize, A.strides[1])) def _diag_ufunc(A,b,offset,func): + b = np.squeeze(b) + assert b.ndim <= 1, "only implemented for one dimensional arrays" dA = view(A, offset); func(dA,b,dA) return A From 4bec78704b4fd37cd51578f9c846010f90cd67c2 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 2 Sep 2015 13:32:39 +0100 Subject: [PATCH 4/4] Note added to the docs --- GPy/models/gp_heteroscedastic_regression.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/GPy/models/gp_heteroscedastic_regression.py b/GPy/models/gp_heteroscedastic_regression.py index 2fe3b788..63c6352a 100644 --- a/GPy/models/gp_heteroscedastic_regression.py +++ b/GPy/models/gp_heteroscedastic_regression.py @@ -16,6 +16,8 @@ class GPHeteroscedasticRegression(GP): :param X: input observations :param Y: observed values :param kernel: a GPy kernel, defaults to rbf + + NB: This model does not make inference on the noise outside the training set """ def __init__(self, X, Y, kernel=None, Y_metadata=None):