def test_bounded_bq_raises_exception(base_gp_wrong_kernel): # 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)
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)
def bounded_bq_upper(base_gp): bound = np.max( base_gp.Y) + 0.5 # make sure bound is larger than the Y values bounded_bq = BoundedBayesianQuadrature(base_gp=base_gp, X=base_gp.X, Y=base_gp.Y, upper_bound=bound) return bounded_bq, bound
def bounded_bq_lower(base_gp): bound = np.min( base_gp.Y) - 0.5 # make sure bound is lower than the Y values bounded_bq = BoundedBayesianQuadrature(base_gp=base_gp, X=base_gp.X, Y=base_gp.Y, lower_bound=bound) return bounded_bq, bound
def integral_mean_from_measure_samples(num_samples: int, model: BoundedBayesianQuadrature): samples = model.measure.get_samples(num_samples=num_samples) mean_at_samples, _ = model.predict(samples) return np.mean(mean_at_samples)
kernel=GPy.kern.RBF(input_dim=D)) # the measure measure = IsotropicGaussianMeasure(mean=np.array([0.1, 1.8]), variance=0.8) # the emukit base GP qrbf = QuadratureRBFIsoGaussMeasure(RBFGPy(gpy_model.kern), measure=measure) base_gp = BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_model) # the emukit bounded BQ model if METHOD == "Bounded BQ lower": bound = np.min(base_gp.Y) - 0.5 model = BoundedBayesianQuadrature(base_gp=base_gp, X=X, Y=Y, bound=bound, is_lower_bounded=True) elif METHOD == "Bounded BQ upper": bound = np.max(base_gp.Y) + 0.5 model = BoundedBayesianQuadrature(base_gp=base_gp, X=X, Y=Y, bound=bound, is_lower_bounded=False) elif METHOD == "WSABI-l adapt": model = WSABIL(base_gp=base_gp, X=base_gp.X, Y=base_gp.Y, adapt_alpha=True)
def get_bounded_bq_upper(): base_gp, dat = get_base_gp() return BoundedBayesianQuadrature(base_gp=base_gp, X=dat.X, Y=dat.Y, upper_bound=dat.bound_upper)