mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-04 17:22:39 +02:00
57 lines
2 KiB
Python
57 lines
2 KiB
Python
# Copyright (c) 2012 - 2014 the GPy Austhors (see AUTHORS.txt)
|
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
|
|
|
import numpy as np
|
|
from ..core import GP
|
|
from .. import likelihoods
|
|
from .. import kern
|
|
|
|
class GPRegression(GP):
|
|
"""
|
|
Gaussian Process model for regression
|
|
|
|
This is a thin wrapper around the models.GP class, with a set of sensible defaults
|
|
|
|
:param X: input observations
|
|
:param Y: observed values
|
|
:param kernel: a GPy kernel, defaults to rbf
|
|
:param Norm normalizer: [False]
|
|
:param noise_var: the noise variance for Gaussian likelhood, defaults to 1.
|
|
|
|
Normalize Y with the norm given.
|
|
If normalizer is False, no normalization will be done
|
|
If it is None, we use GaussianNorm(alization)
|
|
|
|
.. Note:: Multiple independent outputs are allowed using columns of Y
|
|
|
|
"""
|
|
|
|
def __init__(self, X, Y, kernel=None, Y_metadata=None, normalizer=None, noise_var=1., mean_function=None):
|
|
|
|
if kernel is None:
|
|
kernel = kern.RBF(X.shape[1])
|
|
|
|
likelihood = likelihoods.Gaussian(variance=noise_var)
|
|
|
|
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)
|