Skip to content

Commit

Permalink
new MCMC finalized and in tests, new update routine to only recalcula…
Browse files Browse the repository at this point in the history
…te new covaiance matrix entries for normal GP and gp2Scale
  • Loading branch information
MarcusMNoack committed Feb 15, 2024
1 parent c7e0f0b commit 88293ea
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 229 deletions.
5 changes: 3 additions & 2 deletions fvgp/fvgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ def update_gp_data(
y_data,
output_positions = None,
noise_variances = None,
overwrite = False
):

"""
Expand Down Expand Up @@ -357,9 +358,9 @@ def update_gp_data(
#####transform to index set###########
######################################
x_data, y_data, noise_variances = self._transform_index_set(x_data,y_data,noise_variances, self.output_positions)
super().update_gp_data(self.x_data, self.y_data, noise_variances)
super().update_gp_data(self.x_data, self.y_data, noise_variances, overwrite=overwrite)

################################################################################################
################################################################################################
def _compute_standard_output_positions(self, point_number):
value_pos = np.zeros((point_number, self.output_num, self.output_dim))
for j in range(self.output_num):
Expand Down
15 changes: 6 additions & 9 deletions fvgp/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,15 @@ def __init__(

if not callable(gp_kernel_function):
warnings.warn("You have chosen to activate gp2SCale. A powerful tool! \n \
But you have not supplied a kernel that is compactly supported. \n I will use an anisotropic Wendland kernel for now.",
But you have not supplied a kernel that is compactly supported. \n \
I will use an anisotropic Wendland kernel for now.",
stacklevel=2)
if compute_device == "cpu":
gp_kernel_function = wendland_anisotropic_gp2Scale_cpu
elif compute_device == "gpu":
gp_kernel_function = wendland_anisotropic_gp2Scale_gpu

self.gp2Scale_obj = gp2S(x_data, batch_size=gp2Scale_batch_size,
self.gp2Scale_obj = gp2S(batch_size=gp2Scale_batch_size,
gp_kernel_function=gp_kernel_function,
covariance_dask_client=gp2Scale_dask_client,
info=info)
Expand Down Expand Up @@ -455,7 +456,7 @@ def update_gp_data(
if np.ndim(x_new) == 1: x_data = x_new.reshape(-1, 1)
if self.input_space_dim != len(x_new[0]): raise ValueError(
"The input space dimension is not in agreement with the provided x_data.")
if np.ndim(y_new) == 2: y_data = y_new[:, 0]
if np.ndim(y_new) == 2: y_new = y_new[:, 0]

#update class instance x_data, and y_data, and set noise
if overwrite:
Expand All @@ -469,10 +470,6 @@ def update_gp_data(
self.y_data = np.append(self.y_data, y_new)
if noise_variances is not None: noise_variances = np.append(np.diag(self.V), noise_variances)
self.point_number = len(self.x_data)
###########################################
#####gp2Scale##############################
###########################################
if self.gp2Scale: self.gp2Scale_obj.update(x_new, covariance_dask_client=self.gp2Scale_dask_client)
##########################################
#######prepare noise covariances##########
##########################################
Expand Down Expand Up @@ -1169,7 +1166,7 @@ def _compute_GPpriorV(self, x_data, y_data, hyperparameters, calc_inv=False):
try_sparse_LU = False
if self.gp2Scale:
st = time.time()
K = self.gp2Scale_obj.compute_covariance(hyperparameters, self.gp2Scale_dask_client)
K = self.gp2Scale_obj.compute_covariance(x_data, hyperparameters, self.gp2Scale_dask_client)
#K = self.gp2Scale_obj.update_covariance(hyperparameters, self.gp2Scale_dask_client)
Ksparsity = float(K.nnz) / float(len(x_data) ** 2)
if len(x_data) < 50000 and Ksparsity < 0.0001: try_sparse_LU = True
Expand Down Expand Up @@ -1204,7 +1201,7 @@ def _update_GPpriorV(self, x_data, x_new, y_data, y_new, hyperparameters, calc_i
try_sparse_LU = False
if self.gp2Scale:
st = time.time()
K = self.gp2Scale_obj.update_covariance(hyperparameters, self.gp2Scale_dask_client, self.K)
K = self.gp2Scale_obj.update_covariance(x_new, hyperparameters, self.gp2Scale_dask_client, self.K)
Ksparsity = float(K.nnz) / float(len(x_data) ** 2)
if len(x_data) < 50000 and Ksparsity < 0.0001: try_sparse_LU = True
if self.info: print("Transferring the covariance matrix to host done after ", time.time() - st,
Expand Down

0 comments on commit 88293ea

Please sign in to comment.