def test_gauss_measure_invalid_mean_raises(): mean_wrong_shape = np.ones([3, 1]) with pytest.raises(ValueError): GaussianMeasure(mean=mean_wrong_shape, variance=1.0) mean_wrong_type = 0.0 with pytest.raises(TypeError): GaussianMeasure(mean=mean_wrong_type, variance=1.0)
class DataGaussMeasure: D = 2 mean = np.array([0, 0.8]) variance = np.array([0.2, 1.4]) measure = GaussianMeasure(mean=mean, variance=variance) dat_bounds = [(m - 2 * np.sqrt(v), m + 2 * np.sqrt(v)) for m, v in zip(mean, variance)] reasonable_box_bounds = [(m - 10 * np.sqrt(v), m + 10 * np.sqrt(v)) for m, v in zip(mean, variance)]
class DataGaussIsoMeasure: D = 2 mean = np.array([0, 0.8]) variance = 0.6 measure = GaussianMeasure(mean=mean, variance=variance) dat_bounds = [(m - 2 * np.sqrt(0.6), m + 2 * np.sqrt(0.6)) for m in mean] reasonable_box_bounds = [(m - 10 * np.sqrt(0.6), m + 10 * np.sqrt(0.6)) for m in mean]
def model_gaussian(gpy_model): X, Y = gpy_model.X, gpy_model.Y measure = GaussianMeasure(mean=np.arange(gpy_model.X.shape[1]), variance=np.linspace(0.2, 1.5, X.shape[1])) qrbf = QuadratureRBFGaussianMeasure(RBFGPy(gpy_model.kern), measure=measure) basegp = BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_model) return VanillaBayesianQuadrature(base_gp=basegp, X=gpy_model.X, Y=gpy_model.Y)
def base_gp_data(): X = np.array([[-1, 1], [0, 0], [-2, 0.1]]) Y = np.array([[1], [2], [3]]) gpy_model = GPy.models.GPRegression( X=X, Y=Y, kernel=GPy.kern.RBF(input_dim=X.shape[1])) measure = GaussianMeasure(mean=np.array([0.1, 1.8]), variance=0.8) qrbf = QuadratureRBFGaussianMeasure(RBFGPy(gpy_model.kern), measure=measure) base_gp = BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_model) return base_gp, X, Y
def test_gauss_measure_invalid_variance_raises(wrong_input): mean, var_wrong_value = wrong_input with pytest.raises(ValueError): GaussianMeasure(mean=mean, variance=var_wrong_value)
def get_gaussian_qrbf(): dat = DataGaussianSpread() measure = GaussianMeasure(mean=dat.measure_mean, variance=dat.measure_var) qkern = QuadratureRBFGaussianMeasure(EmukitRBF().kern, measure=measure) return qkern, dat
def get_base_gp(): gpy_model, dat = get_gpy_model() measure = GaussianMeasure(mean=dat.measure_mean, variance=dat.measure_var) qrbf = QuadratureRBFGaussianMeasure(RBFGPy(gpy_model.kern), measure=measure) return BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_model), dat
def measure_gaussian(n_dim: int): return GaussianMeasure(mean=np.ones(n_dim), variance=1.0)