Skip to content

Commit 21d29de

Browse files
committed
Yannick's comments
1 parent 2d267c5 commit 21d29de

3 files changed

Lines changed: 40 additions & 54 deletions

File tree

qstack/regression/cross_validate_results.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ def cv_results(X, y,
7979
np.save(f"{preffix}_{n_rep}-lc-runs.npy", lc_runs)
8080
if save_pred:
8181
np_pred = np.array(predictions_n)
82-
# Can not take means !!! Test-set varies with run !
83-
# pred_mean = np.concatenate([np_pred.mean(axis=0),np_pred.std(axis=0)[1].reshape((1,-1))], axis=0)
8482
pred_mean = np.concatenate([*np_pred.reshape((n_rep, 2, -1))], axis=0)
8583
np.savetxt(f"{preffix}_{n_rep}-predictions.txt", pred_mean.T)
8684
return lc

tests/test_kernels.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55

66

77
def test_local_kernels():
8-
# np.random.seed(666)
9-
# X = np.random.rand(2,4)
10-
# Y = np.random.rand(2,4)
11-
# K_G_good = np.zeros((len(X),len(Y)))
12-
# K_L_good = np.zeros((len(X),len(Y)))
13-
# for i, x in enumerate(X):
14-
# for j, y in enumerate(Y):
15-
# K_G_good[i,j] = np.dot(x-y, x-y)
16-
# K_L_good[i,j] = np.sum(abs(x-y))
17-
# np.exp(-K_G_good/2, out=K_G_good)
18-
# np.exp(-K_L_good/2, out=K_L_good)
19-
# K_dot_good = np.dot(X, Y.T)
20-
# K_cos_good = K_dot_good / np.outer(np.linalg.norm(X, axis=1), np.linalg.norm(Y, axis=1))
8+
"""Test data is generated using:
9+
```
10+
np.random.seed(666)
11+
X = np.random.rand(2,4)
12+
Y = np.random.rand(2,4)
13+
K_G_good = np.zeros((len(X),len(Y)))
14+
K_L_good = np.zeros((len(X),len(Y)))
15+
for i, x in enumerate(X):
16+
for j, y in enumerate(Y):
17+
K_G_good[i,j] = np.dot(x-y, x-y)
18+
K_L_good[i,j] = np.sum(abs(x-y))
19+
np.exp(-K_G_good/2, out=K_G_good)
20+
np.exp(-K_L_good/2, out=K_L_good)
21+
K_dot_good = np.dot(X, Y.T)
22+
K_cos_good = K_dot_good / np.outer(np.linalg.norm(X, axis=1), np.linalg.norm(Y, axis=1))
23+
```
24+
"""
2125

2226
X = np.array([[0.70043712, 0.84418664, 0.67651434, 0.72785806], [0.95145796, 0.0127032 , 0.4135877 , 0.04881279]])
2327
Y = np.array([[0.09992856, 0.50806631, 0.20024754, 0.74415417], [0.192892 , 0.70084475, 0.29322811, 0.77447945]])

tests/test_spahm_a.py

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
PATH = os.path.dirname(os.path.realpath(__file__))
99

1010

11-
def underlying_test(true_data_relpath, X):
11+
def underlying_test(true_data_relpath, X, trim=False, only_z=None):
1212
X_true = np.load(PATH+true_data_relpath, allow_pickle=True)
13-
assert (X.shape == X_true.shape)
14-
for a, a_true in zip(X, X_true, strict=True):
15-
assert (a[0] == a_true[0]) # atom type
16-
assert (np.linalg.norm(a[1]-a_true[1]) < 1e-08) # atom representations
13+
if only_z is not None:
14+
X_true = X_true[np.isin(X_true[:,0], only_z)]
15+
assert X.shape == X_true.shape
16+
for (q, v), (q_true, v_true) in zip(X, X_true, strict=True):
17+
assert q == q_true
18+
if trim is True:
19+
v = np.trim_zeros(v) # short-version vectors should be trimmed
20+
assert np.allclose(v, v_true)
1721

1822

1923
def test_water():
@@ -26,8 +30,6 @@ def test_water():
2630

2731
def test_water_alternate():
2832
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'minao', charge=0, spin=None)
29-
# X = atom.get_repr(mol, ["H", "O"], None, dm=None,
30-
# guess='LB', model='lowdin-long-x', auxbasis='ccpvdzjkfit')
3133
X = atom.get_repr("atom", [mol], [PATH], 'LB', spin=[None], auxbasis='ccpvdzjkfit', with_symbols=True)
3234
underlying_test('/data/SPAHM_a_H2O/X_H2O.npy', X)
3335

@@ -37,8 +39,7 @@ def test_water_lowdinshortx():
3739
X = atom.get_repr("atom", [mol], [PATH+'/data/H2O.xyz'], 'LB',
3840
elements=["H", "O"], spin=None, with_symbols=True,
3941
model='lowdin-short-x', auxbasis='ccpvdzjkfit')
40-
X = np.array([(z,np.trim_zeros(v)) for z,v in X], dtype=object) # trimming is necessary to get the short-version vector !
41-
underlying_test('/data/SPAHM_a_H2O/X_H2O_lowdin-short-x.npy', X)
42+
underlying_test('/data/SPAHM_a_H2O/X_H2O_lowdin-short-x.npy', X, trim=True)
4243

4344

4445
def test_water_lowdinlong():
@@ -54,75 +55,58 @@ def test_water_lowdinshort():
5455
X = atom.get_repr("atom", [mol], [PATH+'/data/H2O.xyz'], 'LB',
5556
elements=["H", "O"], spin=None, with_symbols=True,
5657
model='lowdin-short', auxbasis='ccpvdzjkfit')
57-
X = np.array([(z,np.trim_zeros(v)) for z,v in X], dtype=object) # trimming is necessary to get the short-version vector !
58-
underlying_test('/data/SPAHM_a_H2O/X_H2O_lowdin-short.npy', X)
58+
underlying_test('/data/SPAHM_a_H2O/X_H2O_lowdin-short.npy', X, trim=True)
5959

6060

6161
def test_water_mr21():
6262
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'minao', charge=0, spin=None)
6363
X = atom.get_repr("atom", [mol], [PATH+'/data/H2O.xyz'], 'LB',
6464
elements=["H", "O"], spin=None, with_symbols=True,
6565
model='MR2021', auxbasis='ccpvdzjkfit')
66-
X = np.array([(z,np.trim_zeros(v)) for z,v in X], dtype=object) # trimming is necessary to get the short-version vector !
67-
underlying_test('/data/SPAHM_a_H2O/X_H2O_MR2021.npy', X)
66+
underlying_test('/data/SPAHM_a_H2O/X_H2O_MR2021.npy', X, trim=True)
6867

6968

7069
def test_water_SAD_guess_open_shell():
71-
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'sto3g', charge=1, spin=1) # test breaks when effective open-shell caluclation is needed
70+
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'sto3g', charge=1, spin=1)
7271
Xsad = atom.get_repr("atom", [mol], [PATH+'/data/H2O.xyz'], 'sad',
7372
elements=["H", "O"], spin=[1], with_symbols=True,
7473
xc='hf', model='sad-diff', auxbasis='ccpvdzjkfit')
7574
underlying_test('/data/SPAHM_a_H2O/X_H2O-RC_SAD.npy', Xsad)
7675

7776

7877
def test_water_SAD_guess_close_shell():
79-
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'sto3g', charge=0, spin=0) # test breaks when effective open-shell caluclation is needed
78+
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'sto3g', charge=0, spin=0)
8079
Xsad = atom.get_repr("atom", [mol], [PATH+'/data/H2O.xyz'], 'sad',
8180
elements=["H", "O"], spin=None, with_symbols=True,
8281
xc='hf', model='sad-diff', auxbasis='ccpvdzjkfit')
8382
underlying_test('/data/SPAHM_a_H2O/X_H2O_SAD.npy', Xsad)
8483

8584

8685
def test_water_single_element():
86+
only_z = ['O']
8787
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'minao', charge=0, spin=None)
8888
X = atom.get_repr("atom", [mol], [PATH+'/data/H2O.xyz'], 'LB',
8989
elements=["H", "O"], spin=None, with_symbols=True,
90-
model='lowdin-long-x', auxbasis='ccpvdzjkfit', only_z=['O']) # requesting reps for O-atom only
91-
X_true = np.load(PATH+'/data/SPAHM_a_H2O/X_H2O.npy', allow_pickle=True)
92-
# the next two lines deviate from the common template
93-
a = X[0]
94-
assert (X.shape == np.array(X_true[0], ndmin=2).shape)
95-
for a_true in X_true:
96-
if a[0] == a_true[0]: # atom type
97-
assert (np.linalg.norm(a[1]-a_true[1]) < 1e-08) # atom representations
90+
model='lowdin-long-x', auxbasis='ccpvdzjkfit', only_z=only_z)
91+
underlying_test('/data/SPAHM_a_H2O/X_H2O.npy', X, only_z=only_z)
9892

9993

10094
def test_water_single_element_short():
95+
only_z = ['O']
10196
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'minao', charge=0, spin=None)
10297
X = atom.get_repr("atom", [mol], [PATH+'/data/H2O.xyz'], 'LB',
10398
elements=["H", "O"], spin=None, with_symbols=True,
104-
model='lowdin-short', auxbasis='ccpvdzjkfit', only_z=['O'])
105-
X = np.array([(z,np.trim_zeros(v)) for z,v in X], dtype=object) # trimming is necessary to get the short-version vector !
106-
X_true = np.load(PATH+'/data/SPAHM_a_H2O/X_H2O_lowdin-short.npy', allow_pickle=True)
107-
a = X[0]
108-
assert (X.shape == np.array(X_true[0], ndmin=2).shape)
109-
for a_true in X_true:
110-
if a[0] == a_true[0]: # atom type
111-
assert (np.linalg.norm(a[1]-a_true[1]) < 1e-08) # atom representations
99+
model='lowdin-short', auxbasis='ccpvdzjkfit', only_z=only_z)
100+
underlying_test('/data/SPAHM_a_H2O/X_H2O_lowdin-short.npy', X, only_z=only_z)
112101

113102

114103
def test_water_single_element_SAD():
104+
only_z = ['O']
115105
mol = compound.xyz_to_mol(PATH+'/data/H2O.xyz', 'sto3g', charge=0, spin=0)
116106
X = atom.get_repr("atom", [mol], [PATH+'/data/H2O.xyz'], 'sad',
117107
elements=["H", "O"], spin=None, with_symbols=True,
118-
xc='hf', model='sad-diff', auxbasis='ccpvdzjkfit', only_z=['O'])
119-
X = np.array([(z,np.trim_zeros(v)) for z,v in X], dtype=object) # trimming is necessary to get the short-version vector !
120-
X_true = np.load(PATH+'/data/SPAHM_a_H2O/X_H2O_SAD.npy', allow_pickle=True)
121-
a = X[0]
122-
assert (X.shape == np.array(X_true[0], ndmin=2).shape)
123-
for a_true in X_true:
124-
if a[0] == a_true[0]: # atom type
125-
assert (np.linalg.norm(a[1]-a_true[1]) < 1e-08) # atom representations
108+
xc='hf', model='sad-diff', auxbasis='ccpvdzjkfit', only_z=only_z)
109+
underlying_test('/data/SPAHM_a_H2O/X_H2O_SAD.npy', X, only_z=only_z)
126110

127111

128112
if __name__ == '__main__':

0 commit comments

Comments
 (0)