Ejemplo n.º 1
0
def test_lebesgue_measure_raises():
    # upper bound smaller than lower bound
    wrong_bounds = [(-1, 1), (0, -2)]
    with pytest.raises(ValueError):
        LebesgueMeasure.from_bounds(bounds=wrong_bounds)

    # empty domain
    wrong_bounds = []
    with pytest.raises(ValueError):
        LebesgueMeasure.from_bounds(bounds=wrong_bounds)
Ejemplo n.º 2
0
def test_bounded_bq_raises(gpy_model):
    gpy_model, _ = gpy_model
    measure = LebesgueMeasure.from_bounds(gpy_model.X.shape[1] * [(0, 1)],
                                          normalized=False)
    qrbf = QuadratureRBFLebesgueMeasure(RBFGPy(gpy_model.kern),
                                        measure=measure)
    base_gp_wrong_kernel = BaseGaussianProcessGPy(kern=qrbf,
                                                  gpy_model=gpy_model)

    # wrong kernel embedding
    with pytest.raises(ValueError):
        BoundedBayesianQuadrature(
            base_gp=base_gp_wrong_kernel,
            X=base_gp_wrong_kernel.X,
            Y=base_gp_wrong_kernel.Y,
            lower_bound=np.min(base_gp_wrong_kernel.Y) - 0.5,
        )

    # both upper and lower bound are given
    with pytest.raises(ValueError):
        BoundedBayesianQuadrature(
            base_gp=base_gp_wrong_kernel,
            X=base_gp_wrong_kernel.X,
            Y=base_gp_wrong_kernel.Y,
            lower_bound=np.min(base_gp_wrong_kernel.Y) - 0.5,
            upper_bound=np.min(base_gp_wrong_kernel.Y) - 0.5,
        )

    # no bound is given
    with pytest.raises(ValueError):
        BoundedBayesianQuadrature(base_gp=base_gp_wrong_kernel,
                                  X=base_gp_wrong_kernel.X,
                                  Y=base_gp_wrong_kernel.Y)
Ejemplo n.º 3
0
def model_lebesgue_normalized(gpy_model):
    measure = LebesgueMeasure.from_bounds(bounds=gpy_model.X.shape[1] *
                                          [(-1, 2)],
                                          normalized=True)
    qrbf = QuadratureRBFLebesgueMeasure(RBFGPy(gpy_model.kern), measure)
    basegp = BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_model)
    return VanillaBayesianQuadrature(base_gp=basegp,
                                     X=gpy_model.X,
                                     Y=gpy_model.Y)
Ejemplo n.º 4
0
def test_brownian_qkernel_raises():

    # measure has wrong dimensionality
    wrong_bounds = [(1, 2), (1, 2)]
    measure = LebesgueMeasure.from_bounds(bounds=wrong_bounds)
    with pytest.raises(ValueError):
        QuadratureBrownianLebesgueMeasure(BrownianGPy(GPy.kern.Brownian()),
                                          measure)

    # bounds are negative
    wrong_bounds = [(-1, 2)]
    measure = LebesgueMeasure.from_bounds(bounds=wrong_bounds)
    with pytest.raises(ValueError):
        QuadratureBrownianLebesgueMeasure(BrownianGPy(GPy.kern.Brownian()),
                                          measure)

    # bounds are smaller thn offset (product kernel)
    offset = -2
    wrong_bounds = [(offset - 1, offset + 1), (offset + 1, offset + 2)]
    measure = LebesgueMeasure.from_bounds(bounds=wrong_bounds)
    with pytest.raises(ValueError):
        QuadratureProductBrownianLebesgueMeasure(
            ProductBrownianGPy(input_dim=2, offset=offset), measure)
Ejemplo n.º 5
0
def test_create_emukit_model_from_gpy_model_raises_warns():
    input_dim = 2
    gpy_kernel = GPy.kern.RBF(input_dim=input_dim)
    gpy_model = GPy.models.GPRegression(kernel=gpy_kernel,
                                        X=np.ones([3, input_dim]),
                                        Y=np.ones([3, 1]))

    bounds = input_dim * [(0, 1)]
    measure = LebesgueMeasure.from_bounds(bounds=bounds)

    # Neither measure nor bounds given
    with pytest.raises(ValueError):
        create_emukit_model_from_gpy_model(gpy_model=gpy_model)

    # both measure and bounds are given. Bounds will be ignored.
    with pytest.warns(UserWarning):
        create_emukit_model_from_gpy_model(gpy_model=gpy_model,
                                           integral_bounds=bounds,
                                           measure=measure)
Ejemplo n.º 6
0
def test_base_gp_gpy_raises(gpy_prodbrownian):
    incompatible_offset = -3

    n_dim = 2
    dat = data(n_dim=n_dim)
    kern = ProductBrownianGPy(variance=1.0,
                              input_dim=n_dim,
                              offset=incompatible_offset)
    measure = LebesgueMeasure.from_bounds(bounds=n_dim * [(0, 1)])
    qkern = QuadratureProductBrownianLebesgueMeasure(brownian_kernel=kern,
                                                     measure=measure)

    # this GPy model and hence the emukit base_gp wrapper are not compatible with the kernel wrapper
    # for offsets other than zero.
    gpy_model = GPy.models.GPRegression(kernel=kern.gpy_brownian,
                                        X=dat[0],
                                        Y=dat[1])

    with pytest.raises(ValueError):
        BaseGaussianProcessGPy(kern=qkern, gpy_model=gpy_model)
Ejemplo n.º 7
0
def loop():
    init_size = 5
    x_init = np.random.rand(init_size, 2)
    y_init = np.random.rand(init_size, 1)
    bounds = [(-1, 1), (0, 1)]

    gpy_model = GPy.models.GPRegression(X=x_init,
                                        Y=y_init,
                                        kernel=GPy.kern.RBF(
                                            input_dim=x_init.shape[1],
                                            lengthscale=1.0,
                                            variance=1.0))
    emukit_measure = LebesgueMeasure.from_bounds(bounds, normalized=False)
    emukit_qrbf = QuadratureRBFLebesgueMeasure(RBFGPy(gpy_model.kern),
                                               measure=emukit_measure)
    emukit_model = BaseGaussianProcessGPy(kern=emukit_qrbf,
                                          gpy_model=gpy_model)
    emukit_method = VanillaBayesianQuadrature(base_gp=emukit_model,
                                              X=x_init,
                                              Y=y_init)
    emukit_loop = VanillaBayesianQuadratureLoop(model=emukit_method)
    return emukit_loop, init_size, x_init, y_init
Ejemplo n.º 8
0
class DataLebesgueNormalizedMeasure:
    D = 2
    bounds = [(-1, 2), (0, 1)]
    volume = 3
    measure = LebesgueMeasure(domain=BoxDomain(bounds=bounds), normalized=True)
    dat_bounds = bounds
Ejemplo n.º 9
0
def get_lebesgue_normalized_qprodbrownian():
    dat = DataBoxPositiveDomain()
    measure = LebesgueMeasure.from_bounds(bounds=dat.bounds, normalized=True)
    qkern = QuadratureProductBrownianLebesgueMeasure(
        EmukitProductBrownian().kern, measure=measure)
    return qkern, dat
Ejemplo n.º 10
0
def get_lebesgue_normalized_qmatern52():
    dat = DataBox()
    measure = LebesgueMeasure.from_bounds(bounds=dat.bounds, normalized=True)
    qkern = QuadratureProductMatern52LebesgueMeasure(
        EmukitProductMatern52().kern, measure=measure)
    return qkern, dat
Ejemplo n.º 11
0
def get_lebesgue_normalized_qrbf():
    dat = DataBox()
    measure = LebesgueMeasure.from_bounds(bounds=dat.bounds, normalized=True)
    qkern = QuadratureRBFLebesgueMeasure(EmukitRBF().kern, measure=measure)
    return qkern, dat
Ejemplo n.º 12
0
def get_lebesgue_qbrownian():
    dat = DataIntervalPositiveDomain()
    measure = LebesgueMeasure.from_bounds(bounds=dat.bounds, normalized=False)
    qkern = QuadratureBrownianLebesgueMeasure(EmukitBrownian().kern,
                                              measure=measure)
    return qkern, dat
Ejemplo n.º 13
0
def measure_lebesgue(n_dim: int):
    return LebesgueMeasure.from_bounds(bounds=n_dim * [(0, 1)])