Closed stephen-huan closed 1 month ago
Hi @stephen-huan - thanks for adding this. Would you be able to include a unit test for this function please?
@thomaspinder I've added tests, sorry for the long delay!
@thomaspinder any progress on this PR?
I added consistency tests that are tangentially related to this PR: now kernel.gram(x)
is checked by kernel.cross_covariance(x, x)
, kernel.diagonal(x)
is checked by diagonal(kernel.gram(x))
, and kernel.cross_covariance(a, b)
is checked by kernel.gram(c)
where c
is vstack((a, b))
.
I also noticed a check of max(a - b) < tol
, when it should probably be max(abs(a - b)) < tol
.
Thanks @stephen-huan - nice to see this included in GPJax!
Type of changes
Checklist
poetry run pre-commit run --all-files --show-diff-on-failure
before committing.Description
AbstractKernel
has wrappers forcross_covariance
andgram
but not fordiagonal
, when all three are defined byAbstractKernelComputation
(diagonal
is actually concretely implemented byAbstractKernelComputation
).This PR adds
diagonal
toAbstractKernel
.Although the change is trivial, I believe it's important for the following reasons.
Currently, the way to get the diagonal of a kernel matrix efficiently would be code like
Other than being needlessly verbose, this obscures the fact that most of the
*Computation
classes (DiagonalKernelComputation
, etc.) could be used in place ofDenseKernelComputation
without changing the underlying implementation fromAbstractKernelComputation
. Instead, code likeis cleaner and would allow specific kernels to provide a more efficient, specialized implementation (for example, the Matern family has a unit diagonal no matter the input data).