def test_eval(self): # # 1D # # Define Kernel function def k_fn(x,y,c = 2): return x*y + c k = Explicit(f=lambda x,y,c: x*y+c, parameters={'c':1}, n_variables=2, dim=1) # Construct kernel, specifying parameter c kernel = Kernel(k) # Evaluation points x = np.ones((11,1)) y = np.linspace(0,1,11)[:,None] # Check accuracy self.assertTrue(np.allclose(kernel.eval((x,y)), x*y+1)) # Define kernel with default parameters k.set_parameters({'c':2}) kernel = Kernel(k) # Check accuracy self.assertTrue(np.allclose(kernel.eval((x,y)), x*y+2))
def test_set_parameters(self): # Define explicit function rule = lambda x, a: a * x[:, 0] - x[:, 1] parms = [{'a': 1}, {'a': 2}] f = Explicit(rule, parameters=parms, dim=2) x = (1, 2) self.assertTrue(np.allclose(f.eval(x), np.array([-1, 0]))) # Modify parameter f.set_parameters({'a': 2}, pos=0) self.assertTrue(np.allclose(f.eval(x), np.array([0, 0])))