mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-30 14:35:15 +02:00
Serialization: Add docstrings
This commit is contained in:
parent
7b2af57aee
commit
11aa6ea27b
24 changed files with 393 additions and 69 deletions
|
|
@ -46,20 +46,32 @@ class GPTransformation(object):
|
|||
def to_dict(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def _to_dict(self):
|
||||
def _save_to_input_dict(self):
|
||||
return {}
|
||||
|
||||
@staticmethod
|
||||
def from_dict(input_dict):
|
||||
"""
|
||||
Instantiate an object of a derived class using the information
|
||||
in input_dict (built by the to_dict method of the derived class).
|
||||
More specifically, after reading the derived class from input_dict,
|
||||
it calls the method _build_from_input_dict of the derived class.
|
||||
Note: This method should not be overrided in the derived class. In case
|
||||
it is needed, please override _build_from_input_dict instate.
|
||||
|
||||
:param dict input_dict: Dictionary with all the information needed to
|
||||
instantiate the object.
|
||||
"""
|
||||
|
||||
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)
|
||||
return link_class._build_from_input_dict(link_class, input_dict)
|
||||
|
||||
@staticmethod
|
||||
def _from_dict(link_class, input_dict):
|
||||
def _build_from_input_dict(link_class, input_dict):
|
||||
return link_class(**input_dict)
|
||||
|
||||
class Identity(GPTransformation):
|
||||
|
|
@ -82,7 +94,15 @@ class Identity(GPTransformation):
|
|||
return np.zeros_like(f)
|
||||
|
||||
def to_dict(self):
|
||||
input_dict = super(Identity, self)._to_dict()
|
||||
"""
|
||||
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(Identity, self)._save_to_input_dict()
|
||||
input_dict["class"] = "GPy.likelihoods.link_functions.Identity"
|
||||
return input_dict
|
||||
|
||||
|
|
@ -106,7 +126,15 @@ class Probit(GPTransformation):
|
|||
return (safe_square(f)-1.)*std_norm_pdf(f)
|
||||
|
||||
def to_dict(self):
|
||||
input_dict = super(Probit, self)._to_dict()
|
||||
"""
|
||||
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(Probit, self)._save_to_input_dict()
|
||||
input_dict["class"] = "GPy.likelihoods.link_functions.Probit"
|
||||
return input_dict
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue