Skip to content

Fix Matern Grads #478

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

Merged
merged 4 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Manifest.toml
coverage/
.DS_store
dev
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "KernelFunctions"
uuid = "ec8451be-7e33-11e9-00cf-bbf324bd1392"
version = "0.10.45"
version = "0.10.46"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
13 changes: 7 additions & 6 deletions src/basekernels/matern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ MaternKernel(; nu::Real=1.5, ν::Real=nu, metric=Euclidean()) = MaternKernel(ν,

@functor MaternKernel

@inline function kappa(k::MaternKernel, d::Real)
result = _matern(only(k.ν), d)
return ifelse(iszero(d), one(result), result)
end
@inline kappa(k::MaternKernel, d::Real) = _matern(only(k.ν), d)

function _matern(ν::Real, d::Real)
y = sqrt(2ν) * d
return exp((one(d) - ν) * logtwo - loggamma(ν) + ν * log(y) + log(besselk(ν, y)))
if iszero(d)
return one(d)
else
y = sqrt(2ν) * d
return exp((one(d) - ν) * logtwo - loggamma(ν) + ν * log(y) + log(besselk(ν, y)))
end
end

metric(k::MaternKernel) = k.metric
Expand Down