示例#1
0
from kernel_exp_family.estimators.estimator_oop import EstimatorBase
try:
    from kernel_exp_family.estimators.parameter_search_bo import BayesOptSearch
except ImportError:
    print("Could not import BayesOptSearch.")
from kernel_exp_family.kernels.kernels import gaussian_kernel, \
    gaussian_kernel_grad, theano_available
from kernel_exp_family.tools.assertions import assert_array_shape
from kernel_exp_family.tools.log import Log
import numpy as np

if theano_available:
    from kernel_exp_family.kernels.kernels import gaussian_kernel_hessian_theano, \
        gaussian_kernel_third_order_derivative_tensor_theano

logger = Log.get_logger()


def compute_b(X, Y, K_XY, sigma):
    assert X.shape[1] == Y.shape[1]
    assert K_XY.shape[0] == X.shape[0]
    assert K_XY.shape[1] == Y.shape[0]

    NX = len(X)
    D = X.shape[1]

    b = np.zeros(NX)
    K1 = np.sum(K_XY, 1)
    for l in np.arange(D):
        x_l = X[:, l]
        y_l = Y[:, l]
from pybo import inits, recommenders, solvers, policies
import reggie
from reggie.means._core import Mean

from kernel_exp_family.tools.log import Log
import matplotlib.pyplot as plt
import numpy as np


logger = Log.get_logger()

class GPMean(Mean):
    """
    Allows prescribing a posterior GP mean as the prior mean for
    another GP.
    
    Taken from dev-branch of reggie
    """
    def __init__(self, gp):
        super(GPMean, self).__init__()
        self._gp = gp.copy()

    def __info__(self):
        info = []
        info.append(('gp', self._gp))
        return info

    def get_mean(self, X):
        mu, _ = self._gp.predict(X)
        return mu