def test_ReflectedKernel(): kernel = lambda pt : np.abs(pt) testkernel = testmod.ReflectedKernel(kernel) assert( testkernel(5) == 10 ) np.testing.assert_allclose(testkernel([1,2,3]), [2,4,6]) # 2 (or 3 etc.) dim kernel only testkernel = testmod.ReflectedKernel(lambda pt : np.abs(pt[0])) np.testing.assert_allclose(testkernel([[1,2,3],[4,5,6]]), [2,4,6]) testkernel = testmod.ReflectedKernel(lambda pt : pt[0] * (pt[0]>=0)) np.testing.assert_allclose(testkernel([[1,2,3],[4,5,6]]), [1,2,3]) testkernel = testmod.ReflectedKernel(lambda pt : pt[0] * (pt[0]>=0), reflected_axis=1) np.testing.assert_allclose(testkernel([[1,2,3],[4,5,6]]), [2,4,6])
def compute_space_marginal(ker): """Return the kernel resulting from integrating out all but the first coordinate. Handles the case when a cutoff is applied, but does not apply the cutoff in the calculation! :param ker: Any of the kernels returned by the providers in this module. """ already_reflected_axis = None if isinstance(ker, kernels.ReflectedKernel): already_reflected_axis = ker.reflected_axis ker = ker.delegate if isinstance(ker, _WrapWithCutoff): ker = ker._ker k = kernels.marginalise_gaussian_kernel(ker, 0) if already_reflected_axis is not None and already_reflected_axis > 0: return kernels.ReflectedKernel(k, already_reflected_axis - 1) return k
def trigger_opt(self): _, trigs = self._sample_points() ker = self.trigger_provider(trigs, None) return kernels.ReflectedKernel(ker, 0)
def trigger_opt(self): ker = self.trigger_provider(*self.data_for_trigger_opt()) return kernels.ReflectedKernel(ker, 0)
def ker_opt(self): ker = self.kernel_provider(*self.data_for_ker_opt()) return kernels.ReflectedKernel(ker, 0)