diff options
author | David Luevano Alvarado <55825613+luevano@users.noreply.github.com> | 2020-03-09 21:06:23 -0700 |
---|---|---|
committer | David Luevano Alvarado <55825613+luevano@users.noreply.github.com> | 2020-03-09 21:06:23 -0700 |
commit | 989a8a17e6aa6256e1501256f86ad3a330aae800 (patch) | |
tree | 85f41ea5528305e424c829a1cae82ebab85ed244 | |
parent | dc7cd2c1cd6a4906a9832298def0858d3b9a0706 (diff) |
CM O(n^2) to O(n(n/2+1))
-rw-r--r-- | ml_exp/representations.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/ml_exp/representations.py b/ml_exp/representations.py index be567d67a..761e263d4 100644 --- a/ml_exp/representations.py +++ b/ml_exp/representations.py @@ -56,14 +56,15 @@ size. Arrays are not of the right shape.') cm = np.zeros((size, size), dtype=np.float64) # Actual calculation of the coulomb matrix. - for i, xyz_i in enumerate(coords): - for j, xyz_j in enumerate(coords): - rv = xyz_i - xyz_j - r = np.linalg.norm(rv)/cr - if i == j: - cm[i, j] = (0.5*nc[i]**2.4) + for i in range(n): + for j in range(i, n): + if i==j: + cm[i, i] = 0.5*nc[i]**2.4 else: + rv = coords[i] - coords[j] + r = np.linalg.norm(rv)/cr cm[i, j] = nc[i]*nc[j]/r + cm[j, i] = cm[i, j] # Now the value will be returned. if as_eig: |