def test_transforming(): k = TEST_CASES[6][0] def vscaling_fn(x): return x.sum(dim=1) def iwarping_fn(x): return x**2 owarping_coef = [2, 0, 1, 3, 0] K = k(X, Z) K_iwarp = k(iwarping_fn(X), iwarping_fn(Z)) K_owarp = 2 + K**2 + 3 * K**3 K_vscale = vscaling_fn(X).unsqueeze(1) * K * vscaling_fn(Z).unsqueeze(0) assert_equal(K_iwarp.data, Warping(k, iwarping_fn=iwarping_fn)(X, Z).data) assert_equal(K_owarp.data, Warping(k, owarping_coef=owarping_coef)(X, Z).data) assert_equal(K_vscale.data, VerticalScaling(k, vscaling_fn=vscaling_fn)(X, Z).data) assert_equal(K.exp().data, Exponent(k)(X, Z).data) # test get_subkernel k1 = Sum(Warping(k, iwarping_fn=iwarping_fn), TEST_CASES[7][0]) assert k1.get_subkernel(k.name) is k
def __init__(self, input_dim, feature_dim=None, mean_fn=None, embed_fn=None): super(DMEGP, self).__init__() # store params self.input_dim = input_dim self.feature_dim = feature_dim # define mean function and embedding function self.mean_fn = mean_fn self.embed_fn = embed_fn # define kernel function if embed_fn == None: feature_dim = input_dim kernel = RBF(feature_dim, lengthscale=torch.ones(feature_dim)) else: kernel = RBF(feature_dim, lengthscale=torch.ones(feature_dim)) kernel = Warping(kernel, iwarping_fn=self.embed_fn) if mean_fn != None: self.mean_fn = Warping_mean(self.mean_fn, self.embed_fn) # define gaussian process regression model self.gp_model = GPRegression( X=torch.ones(1, feature_dim), # dummy y=None, kernel=kernel, mean_function=self.mean_fn)
def define_new_GP(self): # define kernel function if self.embed_fn == None: feature_dim = self.input_dim kernel = RBF(feature_dim, lengthscale=torch.ones(feature_dim)) else: feature_dim = self.feature_dim embed_fn = copy.deepcopy(self.embed_fn) kernel = RBF(feature_dim, lengthscale=torch.ones(feature_dim)) kernel = Warping(kernel, iwarping_fn=embed_fn) if self.mean_fn != None: mean_fn = copy.deepcopy(self.mean_fn) # define gaussian process regression model gp_model = GPRegression( X=torch.ones(1, feature_dim), # dummy y=None, kernel=kernel, mean_function=mean_fn) return gp_model