Skip to content

Second derivative of Matern in zero is wrong #517

@FelixBenning

Description

@FelixBenning
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions