Merge pull request #722 from jopago/devel

Add to_dict methods to White and Brownian kernels
This commit is contained in:
Zhenwen Dai 2019-04-25 15:41:04 +01:00 committed by GitHub
commit 54c32d79d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -23,6 +23,17 @@ class Brownian(Kern):
self.variance = Param('variance', variance, Logexp())
self.link_parameters(self.variance)
def to_dict(self):
"""
Convert the object into a json serializable dictionary.
Note: It uses the private method _save_to_input_dict of the parent.
:return dict: json serializable dictionary containing the needed information to instantiate the object
"""
input_dict = super(RBF, self)._save_to_input_dict()
input_dict["class"] = "GPy.kern.Brownian"
return input_dict
def K(self,X,X2=None):
if X2 is None:

View file

@ -64,6 +64,11 @@ class White(Static):
def __init__(self, input_dim, variance=1., active_dims=None, name='white'):
super(White, self).__init__(input_dim, variance, active_dims, name)
def to_dict(self):
input_dict = super(White, self)._save_to_input_dict()
input_dict["class"] = "GPy.kern.White"
return input_dict
def K(self, X, X2=None):
if X2 is None:
return np.eye(X.shape[0])*self.variance
@ -102,6 +107,10 @@ class WhiteHeteroscedastic(Static):
super(Static, self).__init__(input_dim, active_dims, name)
self.variance = Param('variance', np.ones(num_data) * variance, Logexp())
self.link_parameters(self.variance)
def to_dict(self):
input_dict = super(WhiteHeteroscedastic, self)._save_to_input_dict()
input_dict["class"] = "GPy.kern.WhiteHeteroscedastic"
return input_dict
def Kdiag(self, X):
if X.shape[0] == self.variance.shape[0]: