mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-11 15:15:15 +02:00
[kernel] added structural tests for ind outputs kernel, but problem with gradients persist
This commit is contained in:
parent
0116b03f3c
commit
88789611c2
2 changed files with 24 additions and 11 deletions
|
|
@ -48,11 +48,11 @@ class Kern(Parameterized):
|
|||
|
||||
if active_dims is None:
|
||||
active_dims = np.arange(input_dim)
|
||||
|
||||
|
||||
self.active_dims = np.asarray(active_dims, np.int_)
|
||||
|
||||
|
||||
self._all_dims_active = np.atleast_1d(self.active_dims).astype(int)
|
||||
|
||||
|
||||
assert self.active_dims.size == self.input_dim, "input_dim={} does not match len(active_dim)={}".format(self.input_dim, self._all_dims_active.size)
|
||||
|
||||
self._sliced_X = 0
|
||||
|
|
@ -300,7 +300,7 @@ class Kern(Parameterized):
|
|||
return Prod([self, other], name)
|
||||
|
||||
def _check_input_dim(self, X):
|
||||
assert X.shape[1] == self.input_dim, "{} did not specify _all_dims_active and X has wrong shape: X_dim={}, whereas input_dim={}".format(self.name, X.shape[1], self.input_dim)
|
||||
assert X.shape[1] == self.input_dim, "{} did not specify active_dims and X has wrong shape: X_dim={}, whereas input_dim={}".format(self.name, X.shape[1], self.input_dim)
|
||||
|
||||
def _check_active_dims(self, X):
|
||||
assert X.shape[1] >= len(self._all_dims_active), "At least {} dimensional X needed, X.shape={!s}".format(len(self._all_dims_active), X.shape)
|
||||
|
|
@ -324,19 +324,17 @@ class CombinationKernel(Kern):
|
|||
"""
|
||||
assert all([isinstance(k, Kern) for k in kernels])
|
||||
extra_dims = np.asarray(extra_dims, dtype=int)
|
||||
|
||||
active_dims = reduce(np.union1d, (np.r_[x.active_dims] for x in kernels), np.array([], dtype=int))
|
||||
|
||||
|
||||
active_dims = reduce(np.union1d, (np.r_[x.active_dims] for x in kernels), extra_dims)
|
||||
|
||||
input_dim = active_dims.size
|
||||
if extra_dims is not None:
|
||||
input_dim += extra_dims.size
|
||||
|
||||
# initialize the kernel with the full input_dim
|
||||
super(CombinationKernel, self).__init__(input_dim, active_dims, name)
|
||||
|
||||
effective_input_dim = reduce(max, (k._all_dims_active.max() for k in kernels)) + 1
|
||||
self._all_dims_active = np.array(np.concatenate((np.arange(effective_input_dim), extra_dims if extra_dims is not None else [])), dtype=int)
|
||||
|
||||
|
||||
self.extra_dims = extra_dims
|
||||
self.link_parameters(*kernels)
|
||||
|
||||
|
|
@ -345,7 +343,7 @@ class CombinationKernel(Kern):
|
|||
return self.parameters
|
||||
|
||||
def _set_all_dims_ative(self):
|
||||
self._all_dims_active = np.atleast_1d(self.active_dims).astype(int)
|
||||
self._all_dims_active = np.atleast_1d(self.active_dims).astype(int)
|
||||
|
||||
def input_sensitivity(self, summarize=True):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import numpy as np
|
|||
import GPy
|
||||
from GPy.core.parameterization.param import Param
|
||||
from ..util.config import config
|
||||
from unittest.case import skip
|
||||
|
||||
verbose = 0
|
||||
|
||||
|
|
@ -396,6 +397,13 @@ class KernelTestsNonContinuous(unittest.TestCase):
|
|||
|
||||
#@unittest.expectedFailure
|
||||
def test_IndependentOutputs(self):
|
||||
k = [GPy.kern.RBF(1, active_dims=[1], name='rbf1'), GPy.kern.RBF(self.D, active_dims=range(self.D), name='rbf012'), GPy.kern.RBF(2, active_dims=[0,2], name='rbf02')]
|
||||
kern = GPy.kern.IndependentOutputs(k, -1, name='ind_split')
|
||||
np.testing.assert_array_equal(kern.active_dims, [-1,0,1,2])
|
||||
np.testing.assert_array_equal(kern._all_dims_active, [0,1,2,-1])
|
||||
|
||||
@skip('Gradients for independend outputs with different X do not work correctly')
|
||||
def testIndependendGradients(self):
|
||||
k = GPy.kern.RBF(self.D, active_dims=range(self.D))
|
||||
kern = GPy.kern.IndependentOutputs(k, -1, 'ind_single')
|
||||
self.assertTrue(check_kernel_gradient_functions(kern, X=self.X, X2=self.X2, verbose=verbose, fixed_X_dims=-1))
|
||||
|
|
@ -405,6 +413,13 @@ class KernelTestsNonContinuous(unittest.TestCase):
|
|||
|
||||
#@unittest.expectedFailure
|
||||
def test_Hierarchical(self):
|
||||
k = [GPy.kern.RBF(2, active_dims=[0,2], name='rbf1'), GPy.kern.RBF(2, active_dims=[0,2], name='rbf2')]
|
||||
kern = GPy.kern.IndependentOutputs(k, -1, name='ind_split')
|
||||
np.testing.assert_array_equal(kern.active_dims, [-1,0,2])
|
||||
np.testing.assert_array_equal(kern._all_dims_active, [0,1,2,-1])
|
||||
|
||||
@skip('Gradients for independend outputs with different X do not work correctly')
|
||||
def test_Hierarchical_gradients(self):
|
||||
k = [GPy.kern.RBF(2, active_dims=[0,2], name='rbf1'), GPy.kern.RBF(2, active_dims=[0,2], name='rbf2')]
|
||||
kern = GPy.kern.IndependentOutputs(k, -1, name='ind_split')
|
||||
self.assertTrue(check_kernel_gradient_functions(kern, X=self.X, X2=self.X2, verbose=verbose, fixed_X_dims=-1))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue