Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding setXY and normalizer to GPCoregionalizedRegression #859

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 63 additions & 10 deletions GPy/models/gp_coregionalized_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from .. import likelihoods
from .. import kern
from .. import util
from paramz import ObsAr


class GPCoregionalizedRegression(GP):
"""
Expand All @@ -28,19 +30,70 @@ class GPCoregionalizedRegression(GP):
:param kernel_name: name of the kernel
:type kernel_name: string
"""
def __init__(self, X_list, Y_list, kernel=None, likelihoods_list=None, name='GPCR',W_rank=1,kernel_name='coreg'):

#Input and Output
X,Y,self.output_index = util.multioutput.build_XY(X_list,Y_list)
def __init__(
self,
X_list,
Y_list,
kernel=None,
normalizer=None,
likelihoods_list=None,
name="GPCR",
W_rank=1,
kernel_name="coreg",
):

# Input and Output
X, Y, self.output_index = util.multioutput.build_XY(X_list, Y_list)
Ny = len(Y_list)

#Kernel
# Kernel
if kernel is None:
kernel = kern.RBF(X.shape[1]-1)

kernel = util.multioutput.ICM(input_dim=X.shape[1]-1, num_outputs=Ny, kernel=kernel, W_rank=W_rank,name=kernel_name)
kernel = kern.RBF(X.shape[1] - 1)

kernel = util.multioutput.ICM(
input_dim=X.shape[1] - 1,
num_outputs=Ny,
kernel=kernel,
W_rank=W_rank,
name=kernel_name,
)

# Likelihood
likelihood = util.multioutput.build_likelihood(
Y_list, self.output_index, likelihoods_list
)

super(GPCoregionalizedRegression, self).__init__(
X,
Y,
kernel,
likelihood,
Y_metadata={"output_index": self.output_index},
normalizer=normalizer,
)

def set_XY(self, X=None, Y=None):
if isinstance(X, list):
X, _, self.output_index = util.multioutput.build_XY(X, None)
if isinstance(Y, list):
_, Y, self.output_index = util.multioutput.build_XY(Y, Y)

self.update_model(False)
if Y is not None:
if self.normalizer is not None:
self.normalizer.scale_by(Y)
self.Y_normalized = ObsAr(self.normalizer.normalize(Y))
self.Y = Y
else:
self.Y = ObsAr(Y)
self.Y_normalized = self.Y
if X is not None:
self.X = ObsAr(X)

#Likelihood
likelihood = util.multioutput.build_likelihood(Y_list,self.output_index,likelihoods_list)
self.Y_metadata = {
"output_index": self.output_index,
"trials": np.ones(self.output_index.shape),
}

super(GPCoregionalizedRegression, self).__init__(X,Y,kernel,likelihood, Y_metadata={'output_index':self.output_index})
self.update_model(True)