JuliaGaussianProcesses / KernelFunctions.jl

Julia package for kernel functions for machine learning
https://juliagaussianprocesses.github.io/KernelFunctions.jl/stable/
MIT License
267 stars 32 forks source link

Preserve Float type for Periodic Kernel #560

Closed molet closed 1 month ago

molet commented 1 month ago

Summary Tiny change to preserve float type of inputs and parameters. For most of the kernels, if the inputs and parameters have Float32 type, then the output has also Float32:

julia> v1 = 0.9f0; v2 = 0.7f0;
julia> SqExponentialKernel()(v1, v2)
0.9801987f0
julia> GammaRationalKernel(alpha=2.0f0, gamma=1.0f0)(v1, v2)
0.82644624f0

However, currently, PeriodicKernel doesn't support this:

julia> PeriodicKernel(r=[1.0f0])(v1, v2)
0.8413515018155655

The simple change of exp(-0.5d) to exp(-d / 2) in its kappa function fixes it:

julia> PeriodicKernel(r=[1.0f0])(v1, v2)
0.8413515f0
molet commented 1 month ago

Certainly, it's been added.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 16.29%. Comparing base (c38b366) to head (8686dd1).

Files Patch % Lines
src/basekernels/periodic.jl 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #560 +/- ## =========================================== + Coverage 0.42% 16.29% +15.87% =========================================== Files 52 52 Lines 1423 1430 +7 =========================================== + Hits 6 233 +227 + Misses 1417 1197 -220 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

willtebbutt commented 1 month ago

The changes that you've made do not appear to have anything to do with the test failures, so I'm going to merge.