Skip to content

Commit 38e285c

Browse files
committed
Docs for new kernels
1 parent 0654f2f commit 38e285c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ makedocs(
1212
"Transform"=>"transform.md",
1313
"Metrics"=>"metrics.md",
1414
"Theory"=>"theory.md",
15+
"Custom Kernels"=>"create_kernel.md"
1516
"API"=>"api.md"]
1617
)
1718

docs/src/create_kernel.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Creating your own kernel
2+
3+
KernelFunctions.jl contains the most popular kernels already but you might want to make your own!
4+
5+
Here is for example how one can define the Squared Exponential Kernel again :
6+
7+
```julia
8+
struct MyKernel <: Kernel end
9+
10+
KernelFunctions.kappa(::MyKernel, d2::Real) = exp(-d2)
11+
KernelFunctions.metric(::MyKernel) = SqEuclidean()
12+
```
13+
14+
For a "Base" kernel, where the kernel function is simply a function applied on some metric between two vectors of real, you only need to:
15+
- Define your struct inheriting from `Kernel`.
16+
- Define a `kappa` function.
17+
- Define the metric used `SqEuclidean`, `DotProduct` etc. Note that the term "metric" is here overabused.
18+
- Optional : Define any parameter of your kernel as `trainable` by Flux.jl if you want to perform optimization on the parameters. We recommend wrapping all parameters in arrays to allow them to be mutable.
19+
20+
Once these functions are defined, you can use all the wrapping functions of KernelFuntions.jl

0 commit comments

Comments
 (0)