Skip to content

Commit

Permalink
[Tests] Check if Gram matrices are semi-definite.
Browse files Browse the repository at this point in the history
  • Loading branch information
jajupmochi committed Jan 23, 2024
1 parent 3a655de commit ffdec3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions gklearn/kernels/treelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ def _kernel_do(self, canonkey1, canonkey2):
if len(keys) == 0: # There is nothing in common...
return 0

vector1 = np.array([canonkey1.get(key,0) for key in keys])
vector2 = np.array([canonkey2.get(key,0)for key in keys])
vector1 = np.array([canonkey1.get(key, 0) for key in keys])
vector2 = np.array([canonkey2.get(key, 0) for key in keys])

# vector1, vector2 = [], []
# keys1, keys2 = canonkey1, canonkey2
Expand Down
16 changes: 10 additions & 6 deletions gklearn/tests/test_graph_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def assert_semidefinite(gram_matrix):
"""Check if a matrix is positive semi-definite.
"""
eigvals = np.linalg.eigvals(gram_matrix)
assert np.all(eigvals >= 10e-9), "Gram matrix is not positive semi-definite."
assert np.all(
eigvals >= -1e-9
), "Gram matrix is not positive semi-definite."


##############################################################################
Expand Down Expand Up @@ -838,7 +840,9 @@ def compute(parallel=None):


# assert_equality(compute, parallel=[None, 'imap_unordered'])
assert_equality(compute, parallel=[None]) # @TODO: parallel returns different results.
assert_equality(
compute, parallel=[None]
) # @TODO: parallel returns different results.


if __name__ == "__main__":
Expand All @@ -854,10 +858,10 @@ def compute(parallel=None):
# test_RandomWalk('Acyclic', 'fp', None, None)
# test_RandomWalk('Acyclic', 'spectral', 'exp', 'imap_unordered')
# test_CommonWalk('Acyclic', 0.01, 'geo')
test_CommonWalk('Alkane_unlabeled', 0.01, 'geo')
# test_Marginalized('Acyclic', False)
# test_ShortestPath('Acyclic')
# test_PathUpToH('Acyclic', 'MinMax')
# test_CommonWalk('Alkane_unlabeled', 0.01, 'geo')
# test_Marginalized('Acyclic', False)
# test_ShortestPath('Acyclic')
test_PathUpToH('Alkane_unlabeled', 'tanimoto')
# test_Treelet('AIDS')
# test_SylvesterEquation('Acyclic')
# test_ConjugateGradient('Acyclic')
Expand Down

0 comments on commit ffdec3f

Please sign in to comment.