Exemple #1
0
def test_independent_reparametrization_sampler_sample_is_repeatable() -> None:
    sampler = IndependentReparametrizationSampler(100, _dim_two_gp())
    xs = tf.random.uniform([100, 1, 2],
                           minval=-10.0,
                           maxval=10.0,
                           dtype=tf.float64)
    npt.assert_allclose(sampler.sample(xs), sampler.sample(xs))
Exemple #2
0
def test_independent_reparametrization_sampler_sample_raises_for_invalid_at_shape(
    shape: ShapeLike, ) -> None:
    sampler = IndependentReparametrizationSampler(1,
                                                  QuadraticMeanAndRBFKernel())

    with pytest.raises(TF_DEBUGGING_ERROR_TYPES):
        sampler.sample(tf.zeros(shape))
Exemple #3
0
def test_independent_reparametrization_sampler_sample_is_continuous() -> None:
    sampler = IndependentReparametrizationSampler(100, _dim_two_gp())
    xs = tf.random.uniform([100, 1, 2],
                           minval=-10.0,
                           maxval=10.0,
                           dtype=tf.float64)
    npt.assert_array_less(
        tf.abs(sampler.sample(xs + 1e-20) - sampler.sample(xs)), 1e-20)
Exemple #4
0
def test_independent_reparametrization_sampler_samples_approximate_expected_distribution() -> None:
    sample_size = 1000
    x = tf.random.uniform([100, 1, 2], minval=-10.0, maxval=10.0, dtype=tf.float64)

    model = _dim_two_gp()
    samples = IndependentReparametrizationSampler(sample_size, model).sample(x)  # [N, S, 1, L]

    assert samples.shape == [len(x), sample_size, 1, 2]

    mean, var = model.predict(tf.squeeze(x, -2))  # [N, L], [N, L]
    _assert_kolmogorov_smirnov_95(
        tf.linalg.matrix_transpose(tf.squeeze(samples, -2)),
        tfp.distributions.Normal(mean[..., None], tf.sqrt(var[..., None])),
    )
Exemple #5
0
def test_independent_reparametrization_sampler_samples_are_distinct_for_new_instances(
) -> None:
    sampler1 = IndependentReparametrizationSampler(100, _dim_two_gp())
    sampler2 = IndependentReparametrizationSampler(100, _dim_two_gp())
    xs = tf.random.uniform([100, 1, 2],
                           minval=-10.0,
                           maxval=10.0,
                           dtype=tf.float64)
    npt.assert_array_less(1e-9,
                          tf.abs(sampler2.sample(xs) - sampler1.sample(xs)))
Exemple #6
0
def test_independent_reparametrization_sampler_raises_for_invalid_sample_size(
    sample_size: int, ) -> None:
    with pytest.raises(TF_DEBUGGING_ERROR_TYPES):
        IndependentReparametrizationSampler(sample_size,
                                            QuadraticMeanAndRBFKernel())