예제 #1
0
def test_vanilla_bq_shapes():
    X = np.array([[-1, 1], [0, 0], [-2, 0.1]])
    Y = np.array([[1], [2], [3]])
    x = np.array([[-1, 1], [0, 0], [-2, 0.1], [-3, 4]])
    D = X.shape[1]

    # integral bounds
    lb = -3
    ub = 3

    gpy_model = GPy.models.GPRegression(X=X,
                                        Y=Y,
                                        kernel=GPy.kern.RBF(input_dim=D))
    emukit_qrbf = QuadratureRBF(RBFGPy(gpy_model.kern),
                                integral_bounds=D * [(lb, ub)])
    emukit_model = BaseGaussianProcessGPy(kern=emukit_qrbf,
                                          gpy_model=gpy_model)
    vanilla_bq = VanillaBayesianQuadrature(base_gp=emukit_model)

    # integrate
    res = vanilla_bq.integrate()
    assert len(res) == 2
    assert isinstance(res[0], float)
    assert isinstance(res[1], float)

    # transformations
    assert vanilla_bq.transform(Y).shape == Y.shape
    assert vanilla_bq.inverse_transform(Y).shape == Y.shape

    # predictions base
    res = vanilla_bq.predict_base(x)
    assert len(res) == 4
    for i in range(4):
        assert res[i].shape == (x.shape[0], 1)

    # predictions base full covariance
    res = vanilla_bq.predict_base_with_full_covariance(x)
    assert len(res) == 4
    assert res[0].shape == (x.shape[0], 1)
    assert res[1].shape == (x.shape[0], x.shape[0])
    assert res[2].shape == (x.shape[0], 1)
    assert res[3].shape == (x.shape[0], x.shape[0])

    # predictions
    res = vanilla_bq.predict(x)
    assert len(res) == 2
    assert res[0].shape == (x.shape[0], 1)
    assert res[1].shape == (x.shape[0], 1)

    # predictions full covariance
    res = vanilla_bq.predict_with_full_covariance(x)
    assert len(res) == 2
    assert res[0].shape == (x.shape[0], 1)
    assert res[1].shape == (x.shape[0], x.shape[0])
 def _wrap_emukit(self, gpy_gp: GPy.core.GP):
     """
     Wrap GPy GP around Emukit interface to enable subsequent quadrature
     :param gpy_gp:
     :return:
     """
     # gpy_gp.optimize()
     rbf = RBFGPy(gpy_gp.kern)
     qrbf = QuadratureRBF(rbf, integral_bounds=[(-4, 8)] * self.dimensions)
     model = BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_gp)
     method = VanillaBayesianQuadrature(base_gp=model)
     return method
예제 #3
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 = D * [(-3, 3)]

    gpy_model = GPy.models.GPRegression(X=X,
                                        Y=Y,
                                        kernel=GPy.kern.RBF(input_dim=D))
    qrbf = QuadratureRBF(RBFGPy(gpy_model.kern),
                         integral_bounds=integral_bounds)
    model = BaseGaussianProcessGPy(kern=qrbf, gpy_model=gpy_model)
    vanilla_bq = VanillaBayesianQuadrature(base_gp=model)
    return vanilla_bq
예제 #4
0
def test_rbf_qkernel_shapes():
    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
    lb = -3
    ub = 3

    gpy_kernel = GPy.kern.RBF(input_dim=D)
    emukit_rbf = RBFGPy(gpy_kernel)
    emukit_qrbf = QuadratureRBF(emukit_rbf, integral_bounds=D * [(lb, ub)])

    # kernel shapes
    assert emukit_qrbf.K(x1, x2).shape == (M1, M2)
    assert emukit_qrbf.qK(x2).shape == (1, M2)
    assert emukit_qrbf.Kq(x1).shape == (M1, 1)
    assert isinstance(emukit_qrbf.qKq(), float)

    # gradient shapes
    assert emukit_qrbf.dKq_dx(x1).shape == (M1, D)
    assert emukit_qrbf.dqK_dx(x2).shape == (D, M2)
def test_rbf_qkernel_shapes():
    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
    lb = -3
    ub = 3

    gpy_kernel = GPy.kern.RBF(input_dim=D)
    emukit_rbf = RBFGPy(gpy_kernel)
    emukit_qrbf = QuadratureRBF(emukit_rbf, integral_bounds=D * [(lb, ub)])

    # kernel shapes
    assert emukit_qrbf.K(x1, x2).shape == (M1, M2)
    assert emukit_qrbf.qK(x2).shape == (1, M2)
    assert emukit_qrbf.Kq(x1).shape == (M1, 1)
    assert isinstance(emukit_qrbf.qKq(), float)

    # gradient shapes
    assert emukit_qrbf.dKq_dx(x1).shape == (M1, D)
    assert emukit_qrbf.dqK_dx(x2).shape == (D, M2)