import matplotlib.pyplot as plt import numpy as np from old_version_gp import GaussianProcess from GP.covariance_functions import SquaredExponential, ExpScaledSquaredExponential from GP.plotting import plot_performance_hyper_parameter data_params = np.array([1.0, 0.25, 0.05]) data_covariance_obj = SquaredExponential(data_params) gp = GaussianProcess(data_covariance_obj, lambda x: 0, 'class') num = 30 test_density = 50 dim = 2 seed = 21 iterations_1 = 500 iterations_2 = 150 plot_iterations_1 = 490 plot_iterations_2 = 140 first_algorithm_label = 'Exp-Scaled SE (Exact Gradient)' second_algorithm_label = 'SE (Exact Gradient)' # third_algorithm_label = 'Half-log-scaled SE' np.random.seed(seed) x_tr = np.random.rand(dim, num) if dim == 2: x_1 = np.linspace(0, 1, test_density) x_2 = np.linspace(0, 1, test_density) x_1, x_2 = np.meshgrid(x_1, x_2) x_test = np.array(list(zip(x_1.reshape(-1).tolist(), x_2.reshape(-1).tolist()))) x_test = x_test.T else:
import matplotlib.pyplot as plt import numpy as np from old_version_gp import GaussianProcess from GP.covariance_functions import SquaredExponential, ExpScaledSquaredExponential from GP.plotting import plot_performance_hyper_parameter data_params = np.array([1.0, 0.25, 0.05]) data_covariance_obj = SquaredExponential(data_params) gp = GaussianProcess(data_covariance_obj, lambda x: 0, 'class') num = 30 test_density = 50 dim = 2 seed = 21 iterations_1 = 500 iterations_2 = 150 plot_iterations_1 = 490 plot_iterations_2 = 140 first_algorithm_label = 'Exp-Scaled SE (Exact Gradient)' second_algorithm_label = 'SE (Exact Gradient)' # third_algorithm_label = 'Half-log-scaled SE' np.random.seed(seed) x_tr = np.random.rand(dim, num) if dim == 2: x_1 = np.linspace(0, 1, test_density) x_2 = np.linspace(0, 1, test_density) x_1, x_2 = np.meshgrid(x_1, x_2) x_test = np.array( list(zip(x_1.reshape(-1).tolist(), x_2.reshape(-1).tolist())))
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))