import tensorflow as tf

import gpflow.kernels as kernels

rng = np.random.RandomState(0)


class Datum:
    num_data = 100
    D = 100
    X = rng.rand(num_data, D) * 100


kernel_list = [
    kernels.Matern12(),
    kernels.Matern32(),
    kernels.Matern52(),
    kernels.Exponential(),
    kernels.Cosine()
]


@pytest.mark.parametrize('kernel', kernel_list)
def test_kernel_euclidean_distance(kernel):
    '''
    Tests output & gradients of kernels that are a function of the (scaled) euclidean distance
    of the points. We test on a high dimensional space, which can generate very small distances
    causing the scaled_square_dist to generate some negative values.
    '''
    K = kernel(Datum.X)
    assert not np.isnan(
def matern_kern():
    return kernels.Matern32(Data.D_in, variance=rng.rand())
Exemple #3
0
    "dirac_diag":
    DiagonalGaussian(Xmu, np.zeros((num_data, D_in))),
    "dirac_markov_gauss":
    MarkovGaussian(Xmu_markov, np.zeros((2, num_data + 1, D_in, D_in))),
    "markov_gauss":
    markov_gauss(),
}

_kerns = {
    "rbf":
    kernels.SquaredExponential(variance=rng.rand(),
                               lengthscales=rng.rand() + 1.0),
    "lin":
    kernels.Linear(variance=rng.rand()),
    "matern":
    kernels.Matern32(variance=rng.rand()),
    "rbf_act_dim_0":
    kernels.SquaredExponential(variance=rng.rand(),
                               lengthscales=rng.rand() + 1.0,
                               active_dims=[0]),
    "rbf_act_dim_1":
    kernels.SquaredExponential(variance=rng.rand(),
                               lengthscales=rng.rand() + 1.0,
                               active_dims=[1]),
    "lin_act_dim_0":
    kernels.Linear(variance=rng.rand(), active_dims=[0]),
    "lin_act_dim_1":
    kernels.Linear(variance=rng.rand(), active_dims=[1]),
    "rbf_lin_sum":
    kernels.Sum([
        kernels.SquaredExponential(variance=rng.rand(),