def qKq_lebesgue(num_samples: int, qrbf: QuadratureRBFLebesgueMeasure):
    bounds = qrbf.integral_bounds._bounds
    samples = _sample_uniform(num_samples, bounds)
    qKx = qrbf.qK(samples)
    differences = np.array([x[1] - x[0] for x in bounds])
    volume = np.prod(differences)
    return np.mean(qKx) * volume
def qK_lebesgue(num_samples: int, qrbf: QuadratureRBFLebesgueMeasure, x2: np.ndarray):
    bounds = qrbf.integral_bounds._bounds
    samples = _sample_uniform(num_samples, bounds)
    Kx = qrbf.K(samples, x2)
    differences = np.array([x[1] - x[0] for x in bounds])
    volume = np.prod(differences)
    return np.mean(Kx, axis=0) * volume
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)
Exemple #4
0
def vanilla_bq():
    X = np.array([[-1, 1], [0, 0], [-2, 0.1]])
    Y = np.array([[1], [2], [3]])
    D = X.shape[1]
    integral_bounds = [(-1, 2), (-3, 3)]

    gpy_model = GPy.models.GPRegression(X=X,
                                        Y=Y,
                                        kernel=GPy.kern.RBF(input_dim=D))
    qrbf = QuadratureRBFLebesgueMeasure(RBFGPy(gpy_model.kern),
                                        integral_bounds=integral_bounds)
    model = BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_model)
    vanilla_bq = VanillaBayesianQuadrature(base_gp=model, X=X, Y=Y)
    return vanilla_bq
def qrbf_lebesgue_finite():
    x1 = np.array([[-1, 1], [0, 0], [-2, 0.1]])
    x2 = np.array([[-1, 1], [0, 0], [-2, 0.1], [-3, 3]])
    M1 = x1.shape[0]
    M2 = x2.shape[0]
    D = x1.shape[1]

    # integral bounds
    bounds = [(-1, 2), (-3, 3)]

    gpy_kernel = GPy.kern.RBF(input_dim=D)
    emukit_rbf = RBFGPy(gpy_kernel)
    emukit_qrbf = QuadratureRBFLebesgueMeasure(emukit_rbf,
                                               integral_bounds=bounds)
    return emukit_qrbf, x1, x2, M1, M2, D
    # MEASURE_INTBOUNDS = 'Lebesgue-finite'
    # MEASURE_INTBOUNDS = 'GaussIso-infinite'
    # MEASURE_INTBOUNDS = 'Uniform-infinite'
    MEASURE_INTBOUNDS = "Uniform-finite"
    # === CHOOSE MEASURE ABOVE ======

    x1 = np.array([[-1, 1], [0, 0], [-2, 0.1]])
    x2 = np.array([[-1, 1], [0, 0], [-2, 0.1], [-3, 3]])
    D = x1.shape[1]

    gpy_kernel = GPy.kern.RBF(input_dim=D)
    emukit_rbf = RBFGPy(gpy_kernel)

    if MEASURE_INTBOUNDS == "Lebesgue-finite":
        emukit_qrbf = QuadratureRBFLebesgueMeasure(emukit_rbf,
                                                   integral_bounds=[(-1, 2),
                                                                    (-3, 3)])
    elif MEASURE_INTBOUNDS == "GaussIso-infinite":
        measure = IsotropicGaussianMeasure(mean=np.arange(D), variance=2.0)
        emukit_qrbf = QuadratureRBFIsoGaussMeasure(rbf_kernel=emukit_rbf,
                                                   measure=measure)
    elif MEASURE_INTBOUNDS == "Uniform-infinite":
        measure = UniformMeasure(bounds=[(0, 2), (-4, 3)])
        emukit_qrbf = QuadratureRBFUniformMeasure(emukit_rbf,
                                                  integral_bounds=None,
                                                  measure=measure)
    elif MEASURE_INTBOUNDS == "Uniform-finite":
        measure = UniformMeasure(bounds=[(1, 2), (-4, 2)])
        emukit_qrbf = QuadratureRBFUniformMeasure(emukit_rbf,
                                                  integral_bounds=[(-1, 2),
                                                                   (-3, 3)],
Exemple #7
0
def base_gp_wrong_kernel(gpy_model):
    integral_bounds = [(-1, 2), (-3, 3)]
    qrbf = QuadratureRBFLebesgueMeasure(RBFGPy(gpy_model.kern),
                                        integral_bounds=integral_bounds)
    return BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_model)
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