mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-18 13:55:14 +02:00
Return deserialized models with actual type instead of base type
This commit is contained in:
parent
06441f583f
commit
eca5806518
5 changed files with 54 additions and 40 deletions
|
|
@ -16,18 +16,27 @@ class GPClassification(GP):
|
|||
:param X: input observations
|
||||
:param Y: observed values, can be None if likelihood is not None
|
||||
:param kernel: a GPy kernel, defaults to rbf
|
||||
:param likelihood: a GPy likelihood, defaults to Bernoulli
|
||||
:param inference_method: Latent function inference to use, defaults to EP
|
||||
:type inference_method: :class:`GPy.inference.latent_function_inference.LatentFunctionInference`
|
||||
|
||||
.. Note:: Multiple independent outputs are allowed using columns of Y
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, X, Y, kernel=None,Y_metadata=None, mean_function=None):
|
||||
def __init__(self, X, Y, kernel=None,Y_metadata=None, mean_function=None, inference_method=None,
|
||||
likelihood=None, normalizer=False):
|
||||
if kernel is None:
|
||||
kernel = kern.RBF(X.shape[1])
|
||||
|
||||
likelihood = likelihoods.Bernoulli()
|
||||
if likelihood is None:
|
||||
likelihood = likelihoods.Bernoulli()
|
||||
|
||||
GP.__init__(self, X=X, Y=Y, kernel=kernel, likelihood=likelihood, inference_method=EP(), mean_function=mean_function, name='gp_classification')
|
||||
if inference_method is None:
|
||||
inference_method = EP()
|
||||
|
||||
GP.__init__(self, X=X, Y=Y, kernel=kernel, likelihood=likelihood, inference_method=inference_method,
|
||||
mean_function=mean_function, name='gp_classification', normalizer=normalizer)
|
||||
|
||||
@staticmethod
|
||||
def from_gp(gp):
|
||||
|
|
@ -48,3 +57,9 @@ class GPClassification(GP):
|
|||
|
||||
def save_model(self, output_filename, compress=True, save_data=True):
|
||||
self._save_model(output_filename, compress=True, save_data=True)
|
||||
|
||||
@staticmethod
|
||||
def _build_from_input_dict(input_dict, data=None):
|
||||
input_dict = GPClassification._format_input_dict(input_dict, data)
|
||||
input_dict.pop('name', None) # Name parameter not required by GPClassification
|
||||
return GPClassification(**input_dict)
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ class SparseGPClassification(SparseGP):
|
|||
|
||||
:param X: input observations
|
||||
:param Y: observed values
|
||||
:param likelihood: a GPy likelihood, defaults to Binomial with probit link_function
|
||||
:param likelihood: a GPy likelihood, defaults to Bernoulli
|
||||
:param kernel: a GPy kernel, defaults to rbf+white
|
||||
:param inference_method: Latent function inference to use, defaults to EPDTC
|
||||
:type inference_method: :class:`GPy.inference.latent_function_inference.LatentFunctionInference`
|
||||
:param normalize_X: whether to normalize the input data before computing (predictions will be in original scales)
|
||||
:type normalize_X: False|True
|
||||
:param normalize_Y: whether to normalize the input data before computing (predictions will be in original scales)
|
||||
|
|
@ -27,11 +29,13 @@ class SparseGPClassification(SparseGP):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, X, Y=None, likelihood=None, kernel=None, Z=None, num_inducing=10, Y_metadata=None):
|
||||
def __init__(self, X, Y=None, likelihood=None, kernel=None, Z=None, num_inducing=10, Y_metadata=None,
|
||||
mean_function=None, inference_method=None, normalizer=False):
|
||||
if kernel is None:
|
||||
kernel = kern.RBF(X.shape[1])
|
||||
|
||||
likelihood = likelihoods.Bernoulli()
|
||||
if likelihood is None:
|
||||
likelihood = likelihoods.Bernoulli()
|
||||
|
||||
if Z is None:
|
||||
i = np.random.permutation(X.shape[0])[:num_inducing]
|
||||
|
|
@ -39,7 +43,11 @@ class SparseGPClassification(SparseGP):
|
|||
else:
|
||||
assert Z.shape[1] == X.shape[1]
|
||||
|
||||
SparseGP.__init__(self, X, Y, Z, kernel, likelihood, inference_method=EPDTC(), name='SparseGPClassification',Y_metadata=Y_metadata)
|
||||
if inference_method is None:
|
||||
inference_method = EPDTC()
|
||||
|
||||
SparseGP.__init__(self, X, Y, Z, kernel, likelihood, mean_function=mean_function, inference_method=inference_method,
|
||||
normalizer=normalizer, name='SparseGPClassification', Y_metadata=Y_metadata)
|
||||
|
||||
@staticmethod
|
||||
def from_sparse_gp(sparse_gp):
|
||||
|
|
@ -58,6 +66,12 @@ class SparseGPClassification(SparseGP):
|
|||
model_dict["class"] = "GPy.models.SparseGPClassification"
|
||||
return model_dict
|
||||
|
||||
@staticmethod
|
||||
def _build_from_input_dict(input_dict, data=None):
|
||||
input_dict = SparseGPClassification._format_input_dict(input_dict, data)
|
||||
input_dict.pop('name', None) # Name parameter not required by SparseGPClassification
|
||||
return SparseGPClassification(**input_dict)
|
||||
|
||||
@staticmethod
|
||||
def from_dict(input_dict, data=None):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue