Skip to content

Commit

Permalink
sparsity logged in gp2Scale
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusMNoack committed Sep 23, 2024
1 parent 03e28eb commit bdce992
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fvgp/gp_lin_alg.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def calculate_sparse_minres(KV, vec, info=False, x0=None, M=None):
if isinstance(x0, np.ndarray) and len(x0) < KV.shape[0]: x0 = np.append(x0, np.zeros(KV.shape[0] - len(x0)))
res = np.zeros(vec.shape)
for i in range(vec.shape[1]):
res[:, i], exit_code = minres(KV.tocsc(), vec[:, i], M=M, rtol=1e-8, x0=x0)
res[:, i], exit_code = minres(KV.tocsc(), vec[:, i], M=M, rtol=1e-5, x0=x0)
if exit_code == 1: warnings.warn("MINRES not successful")
if info: logger.info("MINRES compute time: {} seconds.",
time.time() - st)
Expand All @@ -116,7 +116,7 @@ def calculate_sparse_conj_grad(KV, vec, info=False, x0=None, M=None):
if isinstance(x0, np.ndarray) and len(x0) < KV.shape[0]: x0 = np.append(x0, np.zeros(KV.shape[0] - len(x0)))
res = np.zeros(vec.shape)
for i in range(vec.shape[1]):
res[:, i], exit_code = cg(KV.tocsc(), vec[:, i], M=M, rtol=1e-8, x0=x0)
res[:, i], exit_code = cg(KV.tocsc(), vec[:, i], M=M, rtol=1e-5, x0=x0)
if exit_code == 1: warnings.warn("CG not successful")
if info: logger.info("CG compute time: {} seconds.", time.time() - st)
return res
Expand Down
2 changes: 2 additions & 0 deletions fvgp/gp_prior.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def _compute_prior_covariance_gp2Scale(self, x_data, hyperparameters):

logger.debug(" gp2Scale covariance matrix result written after {} seconds.", time.time() - st)


# reshape the result set into COO components
data, i_s, j_s = map(np.hstack, zip(*results))
# mirror across diagonal
Expand All @@ -199,6 +200,7 @@ def _compute_prior_covariance_gp2Scale(self, x_data, hyperparameters):
np.hstack([j_s, i_s[diagonal_mask]])
K = sparse.coo_matrix((data, (i_s, j_s)), shape=(len(x_data), len(x_data)))
logger.debug(" gp2Scale covariance matrix assembled after {} seconds.", time.time() - st)
logger.debug(" gp2Scale covariance matrix sparsity = {}.", float(K.nnz) / float(K.shape[0] ** 2))
return K

def _update_prior_covariance_gp2Scale(self, x_old, x_new, hyperparameters):
Expand Down

0 comments on commit bdce992

Please sign in to comment.