Skip to content

Commit

Permalink
Merge pull request #50 from mir-group/mgp_test
Browse files Browse the repository at this point in the history
changed mff name #29 & tested update_L_alpha #23
  • Loading branch information
jonpvandermause authored Sep 15, 2019
2 parents 6d30332 + d23e2ed commit 9218eb6
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 892 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ __pycache__/
pwscf.save/
.cache/
.pytest_cache/
/flare/tests/otf_run.out
/flare/tests/test_outputs/*
/tests/test_mff/Al_md.out
/tests/test_mff/lmp_tmp/
/test/test_mff/
/test/mff/
/datasets/
/tests/test_lammps/*.npy
/tests/test_lammps/*.txt
/tests/ase_otf/*.alloy
/tests/ase_otf/kv3/
/tests/ase_otf/grid3*
/tests/ase_otf/AgI_fast/out/
/tests/ase_otf/
/flare/ase/
/tests/test_outputs/*
/tests/*.xyz
/docs/source/_build/html
Expand Down
38 changes: 0 additions & 38 deletions flare/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,41 +331,3 @@ def update_L_alpha(self):
self.alpha = alpha
self.ky_mat_inv = ky_mat_inv
self.l_mat_inv = l_mat_inv

def update_L_alpha_v1(self):
"""This function is used right after "update_db". It can update the l_mat_inv, k_mat_inv and alpha without computing the whole kernel matrix. The condition is the hyps should be frozen. See notes for derivation and calculation details."""
n = self.l_mat_inv.shape[0]
m = len(self.training_data) - n // 3 # number of data added
sigma_n = self.hyps[-1]

# update l_mat_inv => k_mat_inv
k_v = np.array([[] for i in range(n)])
V_mat = np.zeros((3 * m, 3 * m))

# calculate kernels for all added data
for i in range(m):
x_t = self.training_data[-1 - i]
k_vi = np.array([self.get_kernel_vector(x_t, d + 1)
for d in range(3)]).T # (n+3m) x 3
k_vi = k_vi[:n, :]
k_v = np.hstack([k_v, k_vi]) # n x 3m
for d1 in range(3):
for j in range(i, m):
y_t = self.training_data[-1 - j]
for d2 in range(3):
V_mat[3 * i + d1, 3 * j + d2] = \
self.kernel(x_t, y_t, d1 + 1, d2 + 1,
self.hyps, self.cutoffs)
V_mat[3 * j + d2, 3 * i + d1] = V_mat[
3 * i + d1, 3 * j + d2]
v = self.l_mat_inv @ k_v # n x 3m
V_mat += sigma_n ** 2 * np.eye(3 * m) - v.T @ v
r_n1 = np.linalg.inv(np.linalg.cholesky(V_mat)) # 3m x 3m
r = - self.l_mat_inv.T @ v @ r_n1.T # n x 3m
new_line1 = np.hstack([self.l_mat_inv, np.zeros((n, 3 * m))])
new_line2 = np.hstack([r.T, r_n1])
self.l_mat_inv = np.vstack([new_line1, new_line2])
self.ky_mat_inv = self.l_mat_inv.T @ self.l_mat_inv

# update alpha
self.alpha = self.ky_mat_inv @ self.training_labels_np
Empty file removed flare/mff/__init__.py
Empty file.
Binary file removed flare/mff/__init__.pyc
Binary file not shown.
Loading

0 comments on commit 9218eb6

Please sign in to comment.