mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-07-02 16:01:03 +02:00
Basic framework for serializing GPy models
This commit is contained in:
parent
d529da3e6c
commit
e572bfb746
26 changed files with 828 additions and 64 deletions
|
|
@ -29,6 +29,11 @@ class Bernoulli(Likelihood):
|
|||
if isinstance(gp_link , (link_functions.Heaviside, link_functions.Probit)):
|
||||
self.log_concave = True
|
||||
|
||||
def to_dict(self):
|
||||
input_dict = super(Bernoulli, self)._to_dict()
|
||||
input_dict["class"] = "GPy.likelihoods.Bernoulli"
|
||||
return input_dict
|
||||
|
||||
def _preprocess_values(self, Y):
|
||||
"""
|
||||
Check if the values of the observations correspond to the values
|
||||
|
|
|
|||
|
|
@ -46,6 +46,13 @@ class Gaussian(Likelihood):
|
|||
if isinstance(gp_link, link_functions.Identity):
|
||||
self.log_concave = True
|
||||
|
||||
def to_dict(self):
|
||||
input_dict = super(Gaussian, self)._to_dict()
|
||||
input_dict["class"] = "GPy.likelihoods.Gaussian"
|
||||
input_dict["variance"] = self.variance.values.tolist()
|
||||
return input_dict
|
||||
|
||||
|
||||
def betaY(self,Y,Y_metadata=None):
|
||||
#TODO: ~Ricardo this does not live here
|
||||
raise RuntimeError("Please notify the GPy developers, this should not happen")
|
||||
|
|
|
|||
|
|
@ -44,6 +44,37 @@ class Likelihood(Parameterized):
|
|||
self.gp_link = gp_link
|
||||
self.log_concave = False
|
||||
self.not_block_really = False
|
||||
self.name = name
|
||||
|
||||
def to_dict(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def _to_dict(self):
|
||||
input_dict = {}
|
||||
input_dict["name"] = self.name
|
||||
input_dict["gp_link_dict"] = self.gp_link.to_dict()
|
||||
return input_dict
|
||||
|
||||
@staticmethod
|
||||
def from_dict(input_dict):
|
||||
import copy
|
||||
input_dict = copy.deepcopy(input_dict)
|
||||
likelihood_class = input_dict.pop('class')
|
||||
input_dict["name"] = str(input_dict["name"])
|
||||
name = input_dict.pop('name')
|
||||
import GPy
|
||||
likelihood_class = eval(likelihood_class)
|
||||
return likelihood_class._from_dict(likelihood_class, input_dict)
|
||||
|
||||
@staticmethod
|
||||
def _from_dict(likelihood_class, input_dict):
|
||||
import copy
|
||||
input_dict = copy.deepcopy(input_dict)
|
||||
gp_link_dict = input_dict.pop('gp_link_dict')
|
||||
import GPy
|
||||
gp_link = GPy.likelihoods.link_functions.GPTransformation.from_dict(gp_link_dict)
|
||||
input_dict["gp_link"] = gp_link
|
||||
return likelihood_class(**input_dict)
|
||||
|
||||
def request_num_latent_functions(self, Y):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -43,6 +43,25 @@ class GPTransformation(object):
|
|||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def to_dict(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def _to_dict(self):
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def from_dict(input_dict):
|
||||
import copy
|
||||
input_dict = copy.deepcopy(input_dict)
|
||||
link_class = input_dict.pop('class')
|
||||
import GPy
|
||||
link_class = eval(link_class)
|
||||
return link_class._from_dict(link_class, input_dict)
|
||||
|
||||
@staticmethod
|
||||
def _from_dict(link_class, input_dict):
|
||||
return link_class(**input_dict)
|
||||
|
||||
class Identity(GPTransformation):
|
||||
"""
|
||||
.. math::
|
||||
|
|
@ -62,6 +81,10 @@ class Identity(GPTransformation):
|
|||
def d3transf_df3(self,f):
|
||||
return np.zeros_like(f)
|
||||
|
||||
def to_dict(self):
|
||||
input_dict = super(Identity, self)._to_dict()
|
||||
input_dict["class"] = "GPy.likelihoods.link_functions.Identity"
|
||||
return input_dict
|
||||
|
||||
class Probit(GPTransformation):
|
||||
"""
|
||||
|
|
@ -82,6 +105,11 @@ class Probit(GPTransformation):
|
|||
def d3transf_df3(self,f):
|
||||
return (safe_square(f)-1.)*std_norm_pdf(f)
|
||||
|
||||
def to_dict(self):
|
||||
input_dict = super(Probit, self)._to_dict()
|
||||
input_dict["class"] = "GPy.likelihoods.link_functions.Probit"
|
||||
return input_dict
|
||||
|
||||
|
||||
class Cloglog(GPTransformation):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue