mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-15 06:52:39 +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
|
|
@ -4,6 +4,7 @@
|
|||
from ..core import GP
|
||||
from .. import likelihoods
|
||||
from .. import kern
|
||||
import numpy as np
|
||||
from ..inference.latent_function_inference.expectation_propagation import EP
|
||||
|
||||
class GPClassification(GP):
|
||||
|
|
@ -27,3 +28,23 @@ class GPClassification(GP):
|
|||
likelihood = likelihoods.Bernoulli()
|
||||
|
||||
GP.__init__(self, X=X, Y=Y, kernel=kernel, likelihood=likelihood, inference_method=EP(), mean_function=mean_function, name='gp_classification')
|
||||
|
||||
@staticmethod
|
||||
def from_gp(gp):
|
||||
from copy import deepcopy
|
||||
gp = deepcopy(gp)
|
||||
GPClassification(gp.X, gp.Y, gp.kern, gp.likelihood, gp.inference_method, gp.mean_function, name='gp_classification')
|
||||
|
||||
def to_dict(self, save_data=True):
|
||||
model_dict = super(GPClassification,self).to_dict(save_data)
|
||||
model_dict["class"] = "GPy.models.GPClassification"
|
||||
return model_dict
|
||||
|
||||
@staticmethod
|
||||
def from_dict(input_dict, data=None):
|
||||
import GPy
|
||||
m = GPy.core.model.Model.from_dict(input_dict, data)
|
||||
return GPClassification.from_gp(m)
|
||||
|
||||
def save_model(self, output_filename, compress=True, save_data=True):
|
||||
self._save_model(output_filename, compress=True, save_data=True)
|
||||
|
|
|
|||
|
|
@ -35,3 +35,23 @@ class GPRegression(GP):
|
|||
|
||||
super(GPRegression, self).__init__(X, Y, kernel, likelihood, name='GP regression', Y_metadata=Y_metadata, normalizer=normalizer, mean_function=mean_function)
|
||||
|
||||
@staticmethod
|
||||
def from_gp(gp):
|
||||
from copy import deepcopy
|
||||
gp = deepcopy(gp)
|
||||
return GPRegression(gp.X, gp.Y, gp.kern, gp.Y_metadata, gp.normalizer, gp.likelihood.variance.values, gp.mean_function)
|
||||
|
||||
def to_dict(self, save_data=True):
|
||||
model_dict = super(GPRegression,self).to_dict(save_data)
|
||||
model_dict["class"] = "GPy.models.GPRegression"
|
||||
return model_dict
|
||||
|
||||
@staticmethod
|
||||
def _from_dict(input_dict, data=None):
|
||||
import GPy
|
||||
input_dict["class"] = "GPy.core.GP"
|
||||
m = GPy.core.GP.from_dict(input_dict, data)
|
||||
return GPRegression.from_gp(m)
|
||||
|
||||
def save_model(self, output_filename, compress=True, save_data=True):
|
||||
self._save_model(output_filename, compress=True, save_data=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue