Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexing error makes many fingerprint kernel implementations incorrect #74

Open
AustinT opened this issue Jan 12, 2025 · 3 comments
Open

Comments

@AustinT
Copy link
Collaborator

AustinT commented Jan 12, 2025

In a variety of different fingerprint kernels, x1 and x2 are compared with something like

x1[-1] <something> x2[-1]

which only compares the last element in the kernel matrix, and does not do a pairwise comparison. This causes many kernels to not implement the function claimed in their docstring. Specifically, I think the following kernels are wrong:

Here is a minimal example showing the problem:

import torch
from gauche.kernels.fingerprint_kernels.rand_kernel import batch_rand_sim

t = torch.as_tensor([[1, 1, 0., 0.], [1., 0., 1., 0.]])
print(batch_rand_sim(t, t)[0, 1])
print(batch_rand_sim(t[:1], t[1:]))

Output:

tensor(0.7500, dtype=torch.float64)
tensor([[0.5000]], dtype=torch.float64)

What this shows: if I compute a whole kernel matrix and take element [0, -1], it gives a different result than directly computing element [0, -1]. This is because d is computed just using the last element in each batch, rather than computed separately for each pair.

I think this was not caught in the tests because they just tested 1xD matrices. I suspect that a lot of the "batch" similarities also don't work for batches of matrices.

If you can't fix this promptly, I suggest taking these methods out of Gauche and re-releasing. You can add corrected methods back in later.

@AustinT
Copy link
Collaborator Author

AustinT commented Jan 12, 2025

I think this was also introduced in #60

@Ryan-Rhys
Copy link
Collaborator

Thanks for the super detailed example! Will try to get a fix in within the next week! Will add you as a PR reviewer if that's OK?

@AustinT
Copy link
Collaborator Author

AustinT commented Jan 19, 2025

Thanks for the super detailed example! Will try to get a fix in within the next week! Will add you as a PR reviewer if that's OK?

Yes, happy to be a reviewer 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants