Skip to content

Commit fbc01f5

Browse files
committed
Test for invertibility of positive definite link output
1 parent 84ed002 commit fbc01f5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/test_links/test_links.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ def test_quantile_ordering(quantiles, unordered):
5353

5454

5555
def test_positive_definite(positive_definite, batch_size, num_variables):
56-
psd = positive_definite
57-
input_shape = psd.compute_input_shape((batch_size, num_variables, num_variables))
58-
print(input_shape)
59-
random_preactivation = keras.random.normal(input_shape, seed=12)
60-
output = psd(random_preactivation)
56+
input_shape = positive_definite.compute_input_shape((batch_size, num_variables, num_variables))
6157

58+
# Too strongly negative values lead to numerical instabilities -> reduce scale
59+
random_preactivation = keras.random.normal(input_shape) * 0.1
60+
output = positive_definite(random_preactivation)
61+
62+
# Check if output is invertible
63+
np.linalg.inv(output)
64+
65+
# Calculated eigenvalues to test for positive definiteness
6266
output = keras.ops.convert_to_numpy(output)
6367
eigenvalues = np.linalg.eig(output).eigenvalues
6468

0 commit comments

Comments
 (0)