https://github.com/juliagaussianprocesses/scalarkernelfunctions.jl
Kernel functions optimized for 1d input
https://github.com/juliagaussianprocesses/scalarkernelfunctions.jl
Last synced: 5 months ago
JSON representation
Kernel functions optimized for 1d input
- Host: GitHub
- URL: https://github.com/juliagaussianprocesses/scalarkernelfunctions.jl
- Owner: JuliaGaussianProcesses
- License: mit
- Created: 2024-02-20T20:22:57.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-01T14:09:39.000Z (over 2 years ago)
- Last Synced: 2025-06-25T07:06:09.705Z (about 1 year ago)
- Language: Julia
- Size: 27.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ScalarKernelFunctions.jl
[](https://www.repostatus.org/#wip)
[](https://github.com/JuliaGaussianProcesses/ScalarKernelFunctions.jl/actions/workflows/CI.yml)
[](https://codecov.io/gh/JuliaGaussianProcesses/ScalarKernelFunctions.jl/tree/master)
This package implements kernel functions that are optimized for one-dimensional input and
that are GPU-compatible by default.
## Usage
This package expands the KernelFunctions.jl package (which is automatically loaded and
reexported) by a new abstract type `ScalarKernel`.
Its subtypes include a couple of base kernels with the `Scalar` prefix.
On 1-dimensional inputs, they give exactly the same output as their KernelFunctions.jl
counterparts, e.g.:
```julia
using ScalarKernelFunctions
k1 = ScalarSEKernel() # from this package
k2 = SEKernel() # from KernelFunctions.jl
x = rand(100)
kernelmatrix(k1, x) ≈ kernelmatrix(k2, x) # true
```
When combining subtypes of `ScalarKernel` using `+`, `with_lengthscale`, another subtype of
`ScalarKernel` will be produced, which means that specialized implementations will be used
for the composite kernel as well.
Mixing specialized and "normal" kernels will also work, but will no longer use the
specialized implementation.
Specializing on 1d input allows to achieve lower allocation counts and faster evaluation,
especially combined with AD packages such as Zygote or Enzyme. Parameter fields are also
scalar, which saves allocations with repeated construction of the kernel, e.g. when kernel
parameters are being optimized.
### GPU-compatibility by default
The kernels in this package are implemented using broadcast, which allows them to work on
the GPU by default. We also export a `gpu` function, which converts any kernel to use
`Float32` parameters (where needed), and calling `kernelmatrix` will preserve `Float32` to
be most efficient on GPUs. For example, this is how we use a kernel on `CuArray`s:
```julia
using CUDA
x = CUDA.rand(100)
k = ScalarPeriodicKernel() |> gpu # ScalarPeriodicKernel{Float32}(1.0f0)
kernelmatrix(k, x) # returns 100×100 CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}
```
Omitting the `gpu` conversion will of course also work, but will be quite a bit slower.
## Supported kernels
### Base kernels
- [x] `ScalarSEKernel`
- [x] `ScalarLinearKernel`
- [x] `ScalarPeriodicKernel`
- [x] `ScalarMatern12Kernel` === `ScalarExponentialKernel`
- [x] `ScalarMatern32Kernel`
- [x] `ScalarMatern52Kernel`
- [x] `ScalarMaternKernel`
### Composite kernels
- [x] `ScalarKernelSum`, when doing `k1 + k2`, where `k1` and `k2` are `ScalarKernel`s
- [ ] `ScalarKernelProduct`
- [x] `ScalarTransformedKernel`, when doing `k ∘ t`, where `k` is a `ScalarKernel` and `t` is a `Transform`
- [x] `ScalarScaledKernel`, when doing `a * k`, where `k` is a `ScalarKernel` and `a` is a `Real`
### Transforms
- [x] `ScalarScaleTransform`