JuliaGaussianProcesses / JuliaGaussianProcesses/KernelFunctions.jl
Second derivative of Matern in zero is wrong
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 275
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
julia> using KernelFunctions: MaternKernel
julia> k = MaternKernel(ν=5)
Matern Kernel (ν = 5, metric = Distances.Euclidean(0.0))
julia> import ForwardDiff as FD
julia> kx(x,y) = FD.derivative(t -> k(x+t, y), 0)
kx (generic function with 1 method)
julia> dk(x,y) = FD.derivative(t -> kx(x, y+t), 0)
dk (generic function with 1 method)
julia> dk(0,0)
0.0
This is wrong, because for a centered GP $Z$ with covariance function $k$
dk(x,y) = \partial_x \partial_y k(x,y) = \partial_x \partial_y \mathbb{E}[Z(x),Z(y)] = \mathbb{E}[\partial_x Z(x) \partial_y Z(y)] = \text{Cov}(Z'(x), Z'(y))
And $\text{Cov}(Z'(0), Z'(0)) >0$.
$\nu=5$ should be plenty of space for numerical errors since this implies the GP is 5 times differentiable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided ForwardDiff example for MaternKernel(ν=5), then locate the MaternKernel implementation and inspect how derivatives at zero are evaluated. Confirm the derivative at x=y=0 against the expected positive covariance of the derivative process; the issue is done when this case returns the correct nonzero value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100