Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions tests/evals/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_profile_correlation(self):
for i in range(n)
]])

self.assertTrue(np.allclose(
profile_correlation(x, y), r
))
np.testing.assert_allclose(
profile_correlation(x, y), r, rtol=1e-12, atol=1e-12
)
self.assertEqual(profile_correlation(x, y).shape, (1, n))

# Multi-d array
Expand All @@ -34,9 +34,9 @@ def test_profile_correlation(self):
]])
r = r.reshape(1, 4, 3, 2)

self.assertTrue(np.allclose(
profile_correlation(x, y), r
))
np.testing.assert_allclose(
profile_correlation(x, y), r, rtol=1e-12, atol=1e-12
)
self.assertEqual(profile_correlation(x, y).shape, (1, 4, 3, 2))

def test_pattern_correlation(self):
Expand All @@ -48,9 +48,9 @@ def test_pattern_correlation(self):
for i in range(10)
])

self.assertTrue(np.allclose(
pattern_correlation(x, y), r
))
np.testing.assert_allclose(
pattern_correlation(x, y), r, rtol=1e-12, atol=1e-12
)
self.assertEqual(pattern_correlation(x, y).shape, (10,))

# Multi-d array
Expand All @@ -63,26 +63,23 @@ def test_pattern_correlation(self):
for i in range(10)
])

self.assertTrue(np.allclose(
pattern_correlation(x, y), r
))
np.testing.assert_allclose(
pattern_correlation(x, y), r, rtol=1e-12, atol=1e-12
)
self.assertEqual(pattern_correlation(x, y).shape, (10,))

def test_2d(self):
with open('tests/data/testdata-2d.pkl.gz', 'rb') as f:
d = pickle.load(f)
self.assertTrue(np.allclose(
profile_correlation(d['x'], d['y']),
d['r_prof']
))
self.assertTrue(np.allclose(
pattern_correlation(d['x'], d['y']),
d['r_patt']
))
self.assertTrue(np.allclose(
pairwise_identification(d['x'], d['y']),
d['ident_acc']
))
np.testing.assert_allclose(
profile_correlation(d['x'], d['y']), d['r_prof'], rtol=1e-12, atol=1e-12
)
np.testing.assert_allclose(
pattern_correlation(d['x'], d['y']), d['r_patt'], rtol=1e-12, atol=1e-12
)
np.testing.assert_allclose(
pairwise_identification(d['x'], d['y']), d['ident_acc'], rtol=1e-12, atol=1e-12
)

def test_2d_nan(self):
with open('tests/data/testdata-2d-nan.pkl.gz', 'rb') as f:
Expand All @@ -91,14 +88,14 @@ def test_2d_nan(self):
# profile_correlation(d['x'], d['y']),
# d['r_prof']
# ))
self.assertTrue(np.allclose(
np.testing.assert_allclose(
pattern_correlation(d['x'], d['y'], remove_nan=True),
d['r_patt'],
))
self.assertTrue(np.allclose(
d['r_patt'], rtol=1e-12, atol=1e-12
)
np.testing.assert_allclose(
pairwise_identification(d['x'], d['y'], remove_nan=True),
d['ident_acc'],
))
d['ident_acc'], rtol=1e-12, atol=1e-12
)

if __name__ == '__main__':
unittest.main()
24 changes: 12 additions & 12 deletions tests/feature/test_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_normalize_feature_1d(self):
shift=feat_mean0, scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (channel-wise) + SD (all)
feat_valid = ((feat - feat_mean_ch) / feat_std_all) * feat_std0 + feat_mean0
Expand All @@ -35,7 +35,7 @@ def test_normalize_feature_1d(self):
shift=feat_mean0, scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (all) + SD (channel-wise)
feat_valid = ((feat - feat_mean_all) / feat_std_ch) * feat_std0 + feat_mean0
Expand All @@ -44,7 +44,7 @@ def test_normalize_feature_1d(self):
shift=feat_mean0, scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (all) + SD (all)
feat_valid = ((feat - feat_mean_all) / feat_std_all) * feat_std0 + feat_mean0
Expand All @@ -53,7 +53,7 @@ def test_normalize_feature_1d(self):
shift=feat_mean0, scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (channel-wise) + SD (channel-wise), self-mean shift
feat_valid = ((feat - feat_mean_ch) / feat_std_ch) * feat_std0 + feat_mean_ch
Expand All @@ -62,7 +62,7 @@ def test_normalize_feature_1d(self):
shift='self', scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (channel-wise) + SD (channel-wise), self-mean shift and self-SD scale
feat_valid = ((feat - feat_mean_ch) / feat_std_ch) * feat_std_ch + feat_mean_ch
Expand All @@ -71,7 +71,7 @@ def test_normalize_feature_1d(self):
shift='self', scale='self',
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

def test_normalize_feature_3d(self):
feat = np.random.rand(64, 16, 16)
Expand All @@ -94,7 +94,7 @@ def test_normalize_feature_3d(self):
shift=feat_mean0, scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (channel-wise) + SD (all)
feat_valid = ((feat - feat_mean_ch) / feat_std_all) * feat_std0 + feat_mean0
Expand All @@ -103,7 +103,7 @@ def test_normalize_feature_3d(self):
shift=feat_mean0, scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (all) + SD (channel-wise)
feat_valid = ((feat - feat_mean_all) / feat_std_ch) * feat_std0 + feat_mean0
Expand All @@ -112,7 +112,7 @@ def test_normalize_feature_3d(self):
shift=feat_mean0, scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (all) + SD (all)
feat_valid = ((feat - feat_mean_all) / feat_std_all) * feat_std0 + feat_mean0
Expand All @@ -121,7 +121,7 @@ def test_normalize_feature_3d(self):
shift=feat_mean0, scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (channel-wise) + SD (channel-wise), self-mean shift
feat_valid = ((feat - feat_mean_ch) / feat_std_ch) * feat_std0 + feat_mean_ch
Expand All @@ -130,7 +130,7 @@ def test_normalize_feature_3d(self):
shift='self', scale=feat_std0,
std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)

# Mean (channel-wise) + SD (channel-wise), self-mean shift and self-SD scale
feat_valid = ((feat - feat_mean_ch) / feat_std_ch) * feat_std_ch + feat_mean_ch
Expand All @@ -146,7 +146,7 @@ def test_normalize_feature_3d(self):
channel_wise_std=False,
scale=feat_std0, std_ddof=1)

np.testing.assert_array_equal(feat_test, feat_valid)
np.testing.assert_allclose(feat_test, feat_valid, rtol=1e-12, atol=1e-12)


if __name__ == '__main__':
Expand Down
8 changes: 4 additions & 4 deletions tests/preproc/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_average_sample(cls):
test_output_x, test_output_ind = interface.average_sample(
x, group, verbose=True)

np.testing.assert_array_equal(test_output_x, exp_output_x)
np.testing.assert_allclose(test_output_x, exp_output_x, rtol=1e-12, atol=1e-12)
np.testing.assert_array_equal(test_output_ind, exp_output_ind)

@classmethod
Expand All @@ -43,7 +43,7 @@ def test_detrend_sample_default(cls):

test_output = interface.detrend_sample(x, group, verbose=True)

np.testing.assert_array_equal(test_output, exp_output)
np.testing.assert_allclose(test_output, exp_output, rtol=1e-12, atol=1e-12)

@classmethod
def test_detrend_sample_nokeepmean(cls):
Expand All @@ -59,7 +59,7 @@ def test_detrend_sample_nokeepmean(cls):
test_output = interface.detrend_sample(
x, group, keep_mean=False, verbose=True)

np.testing.assert_array_equal(test_output, exp_output)
np.testing.assert_allclose(test_output, exp_output, rtol=1e-12, atol=1e-12)

@classmethod
def test_normalize_sample(cls):
Expand All @@ -77,7 +77,7 @@ def test_normalize_sample(cls):

test_output = interface.normalize_sample(x, group, verbose=True)

np.testing.assert_array_equal(test_output, exp_output)
np.testing.assert_allclose(test_output, exp_output, rtol=1e-12, atol=1e-12)

@classmethod
def test_shift_sample_singlegroup(cls):
Expand Down
5 changes: 3 additions & 2 deletions tests/recon/torch/modules/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_build_optimizer_factory(self):
latent_next,
latent_next_expected,
rtol=1e-6,
atol=1e-8,
err_msg="Optimizer does not update the latent variable correctly.",
)

Expand Down Expand Up @@ -92,10 +93,10 @@ def test_build_scheduler_factory(self):
loss.backward()
optimizer.step()
scheduler.step()
self.assertEqual(
self.assertAlmostEqual(
optimizer.param_groups[0]["lr"],
0.1 * 0.1,
"Scheduler does not update the learning rate correctly.",
msg="Scheduler does not update the learning rate correctly.",
)

# check if reference to the optimizer is kept during re-initialization
Expand Down
10 changes: 5 additions & 5 deletions tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_corrcoef_matrix_matrix_default(self):

test_output = bdst.corrcoef(x, y)

np.testing.assert_array_equal(test_output, exp_output)
np.testing.assert_allclose(test_output, exp_output, rtol=1e-12, atol=1e-12)

def test_corrcoef_matrix_matrix_varcol(self):
'''Test for corrcoef (matrix and matrix, var=col)'''
Expand All @@ -33,7 +33,7 @@ def test_corrcoef_matrix_matrix_varcol(self):

test_output = bdst.corrcoef(x, y, var='col')

np.testing.assert_array_equal(test_output, exp_output)
np.testing.assert_allclose(test_output, exp_output, rtol=1e-12, atol=1e-12)

def test_corrcoef_vector_vector(self):
'''Test for corrcoef (vector and vector)'''
Expand All @@ -45,7 +45,7 @@ def test_corrcoef_vector_vector(self):

test_output = bdst.corrcoef(x, y)

np.testing.assert_array_equal(test_output, exp_output)
np.testing.assert_allclose(test_output, exp_output, rtol=1e-12, atol=1e-12)

def test_corrcoef_hvector_hvector(self):
'''Test for corrcoef (horizontal vector and horizontal vector)'''
Expand All @@ -57,7 +57,7 @@ def test_corrcoef_hvector_hvector(self):

test_output = bdst.corrcoef(x, y)

np.testing.assert_array_equal(test_output, exp_output)
np.testing.assert_allclose(test_output, exp_output, rtol=1e-12, atol=1e-12)

def test_corrcoef_vvector_vvector(self):
'''Test for corrcoef (vertical vector and vertical vector)'''
Expand All @@ -69,7 +69,7 @@ def test_corrcoef_vvector_vvector(self):

test_output = bdst.corrcoef(x, y)

np.testing.assert_array_equal(test_output, exp_output)
np.testing.assert_allclose(test_output, exp_output, rtol=1e-12, atol=1e-12)

def test_corrcoef_matrix_vector_varrow(self):
'''Test for corrcoef (matrix and vector, var=row)'''
Expand Down
Loading