예제 #1
0
def sample(mean_func, cov_func, x):
    """returns a sample of a gaussian process for given mean and covariance at given points"""
    cov_mat = covariance_mat(cov_func, x, x)
    m_v = np.array([mean_func(column) for column in (x.T).tolist()])
    mean_vector = m_v.reshape((m_v.size,))
    y = np.random.multivariate_normal(mean_vector, cov_mat)
    return y
예제 #2
0
def sample(mean_func, cov_func, x):
    """returns a sample of a gaussian process for given mean and covariance at given points"""
    cov_mat = covariance_mat(cov_func, x, x)
    m_v = mean_func(x)
    mean_vector = m_v.reshape((m_v.size,))
    np.random.seed(data_params.data_seed)
    y = np.random.multivariate_normal(mean_vector, cov_mat)
    return y
예제 #3
0
d, n = x_g.shape
# print(x_g.shape)
m = np.vectorize(lambda x: 0)
covariance_obj = model_params.cov_obj
K = covariance_obj.covariance_function
ml = covariance_obj.oracle

print(x_g.shape, y_g.shape)
print(x_test.shape, y_test.shape)
clf = svm.SVC()
clf.fit(x_g.T, y_g.reshape((y_g.size,)))
svm_y_test = clf.predict(x_test.T)

#Fitting
sigma_l = model_params.noise_var
K_x = covariance_mat(K, x_g, x_g)
I = np.eye(K_x.shape[0])
anc_mat = np.linalg.inv(K_x + I * sigma_l**2)

def fun(w):
    loss, grad = ml(x_g, y_g, w)
    return loss

def oracle_fun(w):
    return ml(x_g, y_g, w)

def grad(w):
    loss, grad = ml(x_g, y_g, w)
    return grad