x_test = np.random.rand(dim, test_density**2)

print("Generating Data")

y_tr, y_test = gp.generate_data(x_tr, x_test, seed=seed)

print("Data generated")

# First method
model_params = np.array([np.log(2.2), np.log(1.73), np.log(0.2)])
model_covariance_obj = ExpScaledSquaredExponential(model_params)

# model_params = np.array([2.2, 1.73, 0.2])
# model_covariance_obj = SquaredExponential(model_params)
first_gp = GaussianProcess(model_covariance_obj, lambda x: 0, 'class')
w_a_list, time_a_list = first_gp.find_hyper_parameters(x_tr, y_tr, max_iter=iterations_1, alternate=True)
w_a_list = [np.exp(w) for w in w_a_list]

w_a_opt = w_a_list[-1]
w_a_list = w_a_list[:plot_iterations_1]
time_a_list = time_a_list[:plot_iterations_1]

# Second method
model_params = np.array([2.2, 1.73, 0.2])
model_covariance_obj = SquaredExponential(model_params)
second_gp = GaussianProcess(model_covariance_obj, lambda x: 0, 'class')
w_list, time_list = second_gp.find_hyper_parameters(x_tr, y_tr, max_iter=iterations_2, alternate=True)
# w_opt = second_gp.covariance_obj.get_params()
w_opt = w_list[-1]
w_list = w_list[:plot_iterations_2]
time_list = time_list[:plot_iterations_2]
print("Generating Data")

y_tr, y_test = gp.generate_data(x_tr, x_test, seed=seed)

print("Data generated")

# First method
model_params = np.array([np.log(2.2), np.log(1.73), np.log(0.2)])
model_covariance_obj = ExpScaledSquaredExponential(model_params)

# model_params = np.array([2.2, 1.73, 0.2])
# model_covariance_obj = SquaredExponential(model_params)
first_gp = GaussianProcess(model_covariance_obj, lambda x: 0, 'class')
w_a_list, time_a_list = first_gp.find_hyper_parameters(x_tr,
                                                       y_tr,
                                                       max_iter=iterations_1,
                                                       alternate=True)
w_a_list = [np.exp(w) for w in w_a_list]

w_a_opt = w_a_list[-1]
w_a_list = w_a_list[:plot_iterations_1]
time_a_list = time_a_list[:plot_iterations_1]

# Second method
model_params = np.array([2.2, 1.73, 0.2])
model_covariance_obj = SquaredExponential(model_params)
second_gp = GaussianProcess(model_covariance_obj, lambda x: 0, 'class')
w_list, time_list = second_gp.find_hyper_parameters(x_tr,
                                                    y_tr,
                                                    max_iter=iterations_2,
                                                    alternate=True)
Exemple #3
0
mu, sigma1 = 0, 10

x_tr, y_tr = load_svmlight_file('Data/Classification/australian.txt')
x_tr = x_tr.T
x_tr = x_tr.toarray()
# y_g = y_g.toarray()
data_name = 'Australian'

x_tr = (x_tr + 1) / 2
y_tr = y_tr.reshape((y_tr.size, 1))
x_test = x_tr[:, int(x_tr.shape[1] * 0.8):]
y_test = y_tr[int(x_tr.shape[1] * 0.8):, :]
y_tr = y_tr[:int(x_tr.shape[1] * 0.8), :]
x_tr = x_tr[:, :int(x_tr.shape[1] * 0.8)]

print("Number of data points: ", x_tr.shape[1])
print("Number of test points: ", x_test.shape[1])
print("Number of features: ", x_tr.shape[0])
# #Generating the starting point
# np.random.seed(random_seed_w0)
# w0 = np.random.rand(3)

model_params = np.array([10., 0.7, 3.])
model_covariance_obj = SquaredExponential(model_params)
new_gp = GaussianProcess(model_covariance_obj, lambda x: 0, 'class')
new_gp.find_hyper_parameters(x_tr, y_tr, max_iter=100)
print(new_gp.covariance_obj.get_params())
predicted_y_test = new_gp.predict(x_test, x_tr, y_tr)

print("Mistakes: ", np.sum(predicted_y_test != y_test))
mu, sigma1 = 0, 10

x_tr, y_tr = load_svmlight_file('Data/Classification/australian.txt')
x_tr = x_tr.T
x_tr = x_tr.toarray()
# y_g = y_g.toarray()
data_name = 'Australian'

x_tr = (x_tr + 1) / 2
y_tr = y_tr.reshape((y_tr.size, 1))
x_test = x_tr[:, int(x_tr.shape[1] * 0.8):]
y_test = y_tr[int(x_tr.shape[1] * 0.8):, :]
y_tr = y_tr[:int(x_tr.shape[1] * 0.8), :]
x_tr = x_tr[:, : int(x_tr.shape[1] * 0.8)]

print("Number of data points: ", x_tr.shape[1])
print("Number of test points: ", x_test.shape[1])
print("Number of features: ", x_tr.shape[0])
# #Generating the starting point
# np.random.seed(random_seed_w0)
# w0 = np.random.rand(3)

model_params = np.array([10.,  0.7,  3.])
model_covariance_obj = SquaredExponential(model_params)
new_gp = GaussianProcess(model_covariance_obj, lambda x: 0, 'class')
new_gp.find_hyper_parameters(x_tr, y_tr, max_iter=100)
print(new_gp.covariance_obj.get_params())
predicted_y_test = new_gp.predict(x_test, x_tr, y_tr)

print("Mistakes: ", np.sum(predicted_y_test != y_test))