fix: incorrect q=2 coefficient in PiecewisePolynomialKernel#2756
Merged
gpleiss merged 2 commits intoJul 10, 2026
Merged
Conversation
The q=2 branch of _get_cov used (j + 4*j + 3) instead of (j**2 + 4*j + 3), yielding 5j+3 in place of j^2+4j+3 and producing materially wrong covariance values for the default smoothness setting. Fix the coefficient to match Rasmussen & Williams Eq. 4.21 (and the kernel's own docstring and test reference). Add a q=2 numeric test with closely-spaced inputs so the polynomial term is actually exercised (existing tests only used q=0 with out-of-support distances, masking the bug).
gpleiss
approved these changes
Jul 10, 2026
gpleiss
enabled auto-merge (squash)
July 10, 2026 17:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's broken
PiecewisePolynomialKernel(q=2)(q=2 is the default) returns incorrect covariance values. The q=2 covariance polynomial uses the coefficient(j + 4*j + 3)/3=(5j+3)/3, but it should be(j**2 + 4*j + 3)/3.Why it happens
In
_get_cov, the q=2 branch dropped the square on thejterm:(j + 4 * j + 3)instead of(j**2 + 4 * j + 3). This contradicts the kernel's own docstring, Rasmussen & Williams Eq. 4.21, and the q=3 branch in the same function (which correctly usesj**2). Existing tests only exercised q=0 with point pairs whose distances fall outside the compact support, so(1 - r)_+ = 0zeroed the polynomial and the bug went undetected.Fix
Restore the square:
(j**2 + 4 * j + 3) / 3.0.Test
Added
test_computes_piecewise_polynomial_kernel_q2with closely-spaced inputs (r < 1, inside the support), comparing kernel output against the R&W closed form. Fails on the old coefficient (norm diff ~0.105), passes after.