예제 #1
0
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])
예제 #2
0
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
예제 #3
0
 def trigger_opt(self):
     _, trigs = self._sample_points()
     ker = self.trigger_provider(trigs, None)
     return kernels.ReflectedKernel(ker, 0)
예제 #4
0
 def trigger_opt(self):
     ker = self.trigger_provider(*self.data_for_trigger_opt())
     return kernels.ReflectedKernel(ker, 0)
예제 #5
0
 def ker_opt(self):
     ker = self.kernel_provider(*self.data_for_ker_opt())
     return kernels.ReflectedKernel(ker, 0)