Commit c1e7ed44 authored by Malthe Kjær Bisbo's avatar Malthe Kjær Bisbo
Browse files

update

parent 24e0187e
No preview for this file type
No preview for this file type
...@@ -138,9 +138,9 @@ class GPR(): ...@@ -138,9 +138,9 @@ class GPR():
def update_bias(self): def update_bias(self):
self.bias = np.mean(self.memory.energies - self.memory.prior_values) self.bias = np.mean(self.memory.energies - self.memory.prior_values)
def train(self, atoms_list=None): def train(self, atoms_list=None, add_data=True):
if atoms_list is not None: if atoms_list is not None:
self.memory.save_data(atoms_list) self.memory.save_data(atoms_list, add_data)
self.update_bias() self.update_bias()
self.E, self.X, self.prior_values = self.memory.get_data() self.E, self.X, self.prior_values = self.memory.get_data()
...@@ -153,13 +153,13 @@ class GPR(): ...@@ -153,13 +153,13 @@ class GPR():
self.K_inv = cho_solve((L, True), np.eye(K.shape[0])) self.K_inv = cho_solve((L, True), np.eye(K.shape[0]))
self.K0 = self.kernel.kernel_value(self.X[0], self.X[0]) self.K0 = self.kernel.kernel_value(self.X[0], self.X[0])
def optimize_hyperparameters(self, atoms_list=None, comm=None): def optimize_hyperparameters(self, atoms_list=None, add_data=True, comm=None):
if self.n_restarts_optimizer == 0: if self.n_restarts_optimizer == 0:
self.train(atoms_list) self.train(atoms_list)
return return
if atoms_list is not None: if atoms_list is not None:
self.memory.save_data(atoms_list) self.memory.save_data(atoms_list, add_data)
self.update_bias() self.update_bias()
self.E, self.X, self.prior_values = self.memory.get_data() self.E, self.X, self.prior_values = self.memory.get_data()
......
...@@ -82,7 +82,7 @@ class kernel(ABC): ...@@ -82,7 +82,7 @@ class kernel(ABC):
class gauss_kernel(kernel): class gauss_kernel(kernel):
def __init__(self, amplitude=100.0, amplitude_bounds=(1e0, 1e5), def __init__(self, amplitude=100.0, amplitude_bounds=(1e0, 1e5),
length_scale=10.0, length_scale_bounds=(1e0, 1e3), length_scale=10.0, length_scale_bounds=(1e0, 1e3),
noise=1e-5, noise_bounds=(1e-5,1e-5), noise=1e-5, noise_bounds=None,
eta=1, eta_bounds=(0.1,10), eta=1, eta_bounds=(0.1,10),
Nsplit_eta=None): Nsplit_eta=None):
self.amplitude = amplitude self.amplitude = amplitude
...@@ -101,13 +101,13 @@ class gauss_kernel(kernel): ...@@ -101,13 +101,13 @@ class gauss_kernel(kernel):
self.amplitude_bounds = amplitude_bounds self.amplitude_bounds = amplitude_bounds
self.length_scale_bounds = length_scale_bounds self.length_scale_bounds = length_scale_bounds
self.noise_bounds = noise_bounds self.noise_bounds = (noise,noise)
if self.Nsplit_eta is None: if self.Nsplit_eta is None:
self.eta_bounds = (eta,eta) self.eta_bounds = (eta,eta)
else: else:
self.eta_bounds = eta_bounds self.eta_bounds = eta_bounds
self.theta_bounds = np.log(np.array([amplitude_bounds, length_scale_bounds, noise_bounds, self.eta_bounds])) self.theta_bounds = np.log(np.array([amplitude_bounds, length_scale_bounds, self.noise_bounds, self.eta_bounds]))
def __call__(self, X, eval_gradient=False): def __call__(self, X, eval_gradient=False):
if np.ndim(X) == 1: if np.ndim(X) == 1:
...@@ -253,8 +253,8 @@ class double_gauss_kernel(kernel): ...@@ -253,8 +253,8 @@ class double_gauss_kernel(kernel):
def __init__(self, amplitude=100., amplitude_bounds=(1e1,1e5), def __init__(self, amplitude=100., amplitude_bounds=(1e1,1e5),
length_scale1=10.0, length_scale1_bounds=(1e0, 1e3), length_scale1=10.0, length_scale1_bounds=(1e0, 1e3),
length_scale2=10.0, length_scale2_bounds=(1e0, 1e3), length_scale2=10.0, length_scale2_bounds=(1e0, 1e3),
weight=0.01, weight_bounds=(0.01,0.01), weight=0.01, weight_bounds=None,
noise=1e-5, noise_bounds=(1e-5,1e-5), noise=1e-5, noise_bounds=None,
eta=1, eta_bounds=(0.1,10), eta=1, eta_bounds=(0.1,10),
Nsplit_eta=None): Nsplit_eta=None):
self.amplitude = amplitude self.amplitude = amplitude
...@@ -268,14 +268,14 @@ class double_gauss_kernel(kernel): ...@@ -268,14 +268,14 @@ class double_gauss_kernel(kernel):
self.amplitude_bounds = amplitude_bounds self.amplitude_bounds = amplitude_bounds
self.length_scale1_bounds = length_scale1_bounds self.length_scale1_bounds = length_scale1_bounds
self.length_scale2_bounds = length_scale2_bounds self.length_scale2_bounds = length_scale2_bounds
self.weight_bounds = weight_bounds self.weight_bounds = (weight, weight)
self.noise_bounds = noise_bounds self.noise_bounds = (noise, noise)
if self.Nsplit_eta is None: if self.Nsplit_eta is None:
self.eta_bounds = (eta,eta) self.eta_bounds = (eta,eta)
else: else:
self.eta_bounds = eta_bounds self.eta_bounds = eta_bounds
self.theta_bounds = np.log(np.array([amplitude_bounds, length_scale1_bounds, length_scale2_bounds, weight_bounds, noise_bounds, self.eta_bounds])) self.theta_bounds = np.log(np.array([amplitude_bounds, length_scale1_bounds, length_scale2_bounds, self.weight_bounds, self.noise_bounds, self.eta_bounds]))
def __call__(self, X, eval_gradient=False): def __call__(self, X, eval_gradient=False):
K = self.kernel(X, with_noise=True) K = self.kernel(X, with_noise=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment