diff --git a/GPy/kern/_src/coregionalize.py b/GPy/kern/_src/coregionalize.py index 69fc27ef..0d99ce21 100644 --- a/GPy/kern/_src/coregionalize.py +++ b/GPy/kern/_src/coregionalize.py @@ -5,6 +5,7 @@ from kern import Kern import numpy as np from scipy import weave from ...core.parameterization import Param +from ...core.parameterization.transformations import Logexp class Coregionalize(Kern): """ @@ -20,7 +21,7 @@ class Coregionalize(Kern): k_2(x, y)=\mathbf{B} k(x, y) it is obtained as the tensor product between a covariance function - k(x,y) and B. + k(x, y) and B. :param output_dim: number of outputs to coregionalize :type output_dim: int @@ -29,7 +30,7 @@ class Coregionalize(Kern): :param W: a low rank matrix that determines the correlations between the different outputs, together with kappa it forms the coregionalization matrix B :type W: numpy array of dimensionality (num_outpus, W_columns) :param kappa: a vector which allows the outputs to behave independently - :type kappa: numpy array of dimensionality (output_dim,) + :type kappa: numpy array of dimensionality (output_dim, ) .. note: see coregionalization examples in GPy.examples.regression for some usage. """ @@ -37,18 +38,18 @@ class Coregionalize(Kern): super(Coregionalize, self).__init__(input_dim=1, name=name) self.output_dim = output_dim self.rank = rank - if self.rank>output_dim-1: + if self.rank>output_dim: print("Warning: Unusual choice of rank, it should normally be less than the output_dim.") if W is None: - W = 0.5*np.random.randn(self.output_dim,self.rank)/np.sqrt(self.rank) + W = 0.5*np.random.randn(self.output_dim, self.rank)/np.sqrt(self.rank) else: - assert W.shape==(self.output_dim,self.rank) - self.W = Param('W',W) + assert W.shape==(self.output_dim, self.rank) + self.W = Param('W', W) if kappa is None: kappa = 0.5*np.ones(self.output_dim) else: - assert kappa.shape==(self.output_dim,) - self.kappa = Param('kappa', kappa) + assert kappa.shape==(self.output_dim, ) + self.kappa = Param('kappa', kappa, Logexp()) self.add_parameters(self.W, self.kappa) self.parameters_changed() @@ -56,54 +57,58 @@ class Coregionalize(Kern): def parameters_changed(self): self.B = np.dot(self.W, self.W.T) + np.diag(self.kappa) - def K(self,index,index2,target): - index = np.asarray(index,dtype=np.int) + def K(self, X, X2=None): + index = np.asarray(X, dtype=np.int) #here's the old code (numpy) #if index2 is None: #index2 = index #else: - #index2 = np.asarray(index2,dtype=np.int) + #index2 = np.asarray(index2, dtype=np.int) #false_target = target.copy() - #ii,jj = np.meshgrid(index,index2) - #ii,jj = ii.T, jj.T - #false_target += self.B[ii,jj] + #ii, jj = np.meshgrid(index, index2) + #ii, jj = ii.T, jj.T + #false_target += self.B[ii, jj] - if index2 is None: + + if X2 is None: + target = np.empty((X.shape[0], X.shape[0]), dtype=np.float64) code=""" for(int i=0;i