From 7a9b6ad1131fd2ae5bf62104f6f2b209b82ee121 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 12 Mar 2013 16:50:12 +0000 Subject: [PATCH] The warnings are now handeled properly in the periodic kernels --- GPy/kern/periodic_Matern32.py | 4 ++++ GPy/kern/periodic_Matern52.py | 9 +++++++++ GPy/kern/periodic_exponential.py | 10 +++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/GPy/kern/periodic_Matern32.py b/GPy/kern/periodic_Matern32.py index 662c1506..95684a02 100644 --- a/GPy/kern/periodic_Matern32.py +++ b/GPy/kern/periodic_Matern32.py @@ -1,3 +1,7 @@ +# Copyright (c) 2012, GPy authors (see AUTHORS.txt). +# Licensed under the BSD 3-clause license (see LICENSE.txt) + + from kernpart import kernpart import numpy as np from GPy.util.linalg import mdot, pdinv diff --git a/GPy/kern/periodic_Matern52.py b/GPy/kern/periodic_Matern52.py index c533961f..07cb11ea 100644 --- a/GPy/kern/periodic_Matern52.py +++ b/GPy/kern/periodic_Matern52.py @@ -1,6 +1,11 @@ +# Copyright (c) 2012, GPy authors (see AUTHORS.txt). +# Licensed under the BSD 3-clause license (see LICENSE.txt) + + from kernpart import kernpart import numpy as np from GPy.util.linalg import mdot, pdinv +from GPy.util.decorators import silence_errors class periodic_Matern52(kernpart): """ @@ -40,6 +45,7 @@ class periodic_Matern52(kernpart): return alpha*np.cos(omega*x+phase) return f + @silence_errors def _cos_factorization(self,alpha,omega,phase): r1 = np.sum(alpha*np.cos(phase),axis=1)[:,None] r2 = np.sum(alpha*np.sin(phase),axis=1)[:,None] @@ -57,6 +63,7 @@ class periodic_Matern52(kernpart): def _get_params(self): """return the value of the parameters.""" return np.hstack((self.variance,self.lengthscale,self.period)) + def _set_params(self,x): """set the value of the parameters.""" assert x.size==3 @@ -105,6 +112,7 @@ class periodic_Matern52(kernpart): FX = self._cos(self.basis_alpha[None,:],self.basis_omega[None,:],self.basis_phi[None,:])(X) np.add(target,np.diag(mdot(FX,self.Gi,FX.T)),target) + @silence_errors def dK_dtheta(self,dL_dK,X,X2,target): """derivative of the covariance matrix with respect to the parameters (shape is NxMxNparam)""" if X2 is None: X2 = X @@ -184,6 +192,7 @@ class periodic_Matern52(kernpart): #np.add(target[:,:,2],dK_dper, target[:,:,2]) target[2] += np.sum(dK_dper*dL_dK) + @silence_errors def dKdiag_dtheta(self,dL_dKdiag,X,target): """derivative of the diagonal of the covariance matrix with respect to the parameters""" FX = self._cos(self.basis_alpha[None,:],self.basis_omega[None,:],self.basis_phi[None,:])(X) diff --git a/GPy/kern/periodic_exponential.py b/GPy/kern/periodic_exponential.py index b966bbef..0018a8f9 100644 --- a/GPy/kern/periodic_exponential.py +++ b/GPy/kern/periodic_exponential.py @@ -1,6 +1,11 @@ +# Copyright (c) 2012, GPy authors (see AUTHORS.txt). +# Licensed under the BSD 3-clause license (see LICENSE.txt) + + from kernpart import kernpart import numpy as np from GPy.util.linalg import mdot, pdinv +from GPy.util.decorators import silence_errors class periodic_exponential(kernpart): """ @@ -40,6 +45,7 @@ class periodic_exponential(kernpart): return alpha*np.cos(omega*x+phase) return f + @silence_errors def _cos_factorization(self,alpha,omega,phase): r1 = np.sum(alpha*np.cos(phase),axis=1)[:,None] r2 = np.sum(alpha*np.sin(phase),axis=1)[:,None] @@ -57,6 +63,7 @@ class periodic_exponential(kernpart): def _get_params(self): """return the value of the parameters.""" return np.hstack((self.variance,self.lengthscale,self.period)) + def _set_params(self,x): """set the value of the parameters.""" assert x.size==3 @@ -101,6 +108,7 @@ class periodic_exponential(kernpart): FX = self._cos(self.basis_alpha[None,:],self.basis_omega[None,:],self.basis_phi[None,:])(X) np.add(target,np.diag(mdot(FX,self.Gi,FX.T)),target) + @silence_errors def dK_dtheta(self,dL_dK,X,X2,target): """derivative of the covariance matrix with respect to the parameters (shape is NxMxNparam)""" if X2 is None: X2 = X @@ -166,6 +174,7 @@ class periodic_exponential(kernpart): target[1] += np.sum(dK_dlen*dL_dK) target[2] += np.sum(dK_dper*dL_dK) + @silence_errors def dKdiag_dtheta(self,dL_dKdiag,X,target): """derivative of the diagonal of the covariance matrix with respect to the parameters""" FX = self._cos(self.basis_alpha[None,:],self.basis_omega[None,:],self.basis_phi[None,:])(X) @@ -225,4 +234,3 @@ class periodic_exponential(kernpart): target[0] += np.sum(np.diag(dK_dvar)*dL_dKdiag) target[1] += np.sum(np.diag(dK_dlen)*dL_dKdiag) target[2] += np.sum(np.diag(dK_dper)*dL_dKdiag) -