Skip to content

Commit 443cc35

Browse files
committed
include lengthscale comment (closes #212)
1 parent b4d8edc commit 443cc35

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

docs/src/transform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ You can also create a pipeline of `Transform` via `TransformChain`. For example,
66

77
A transformation `t` can be applied to a matrix or a vector `v` via `KernelFunctions.apply(t, v)`.
88

9-
Check the list on the [API page](@ref Transforms).
9+
Check the full list of provided transforms on the [API page](@ref Transforms).

docs/src/userguide.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ For example, a square exponential kernel is created by
77
```julia
88
k = SqExponentialKernel()
99
```
10-
Instead of having lengthscale(s) for each kernel we use [`Transform`](@ref) objects which act on the inputs before passing them to the kernel.
11-
For example, to premultiply the input by 2.0 (equivalent to a lengthscale of 0.5) we can use the following options:
10+
11+
!!! tip "How do I set the lengthscale?"
12+
Instead of having lengthscale(s) for each kernel we use [`Transform`](@ref) objects which act on the inputs before passing them to the kernel. Note that the transforms such as [`ScaleTransform`](@ref) and [`ARDTransform`](@ref) _multiply_ the input by a scale factor, which corresponds to the _inverse_ of the lengthscale.
13+
For example, a lengthscale of 0.5 is equivalent to premultiplying the input by 2.0, and you can create the corresponding kernel as follows:
1214
```julia
13-
k = transform(SqExponentialKernel(), ScaleTransform(2.0)) # returns a TransformedKernel
14-
k = TransformedKernel(SqExponentialKernel(), ScaleTransform(2.0))
15+
k = transform(SqExponentialKernel(), 2.0)
16+
k = TransformedKernel(SqExponentialKernel(), ScaleTransform(2.0)) # equivalent explicit construction
1517
```
16-
Check the [`Transform`](@ref) page to see all available transforms.
18+
Check the [Input Transforms](@ref) page for more details. The API documentation contains an [overview of all available transforms](@ref Transforms).
1719

1820
To premultiply the kernel by a variance, you can use `*` or create a `ScaledKernel`:
1921
```julia
20-
k = 3.0*SqExponentialKernel()
21-
k = ScaledKernel(SqExponentialKernel(), 3.0)
22+
k = 3.0 * SqExponentialKernel()
23+
k = ScaledKernel(SqExponentialKernel(), 3.0) # equivalent explicit constructions
2224
```
2325

2426
## Using a kernel function
2527

26-
To compute the kernel function on two vectors you can call
28+
To evaluate the kernel function on two vectors you simply call the kernel object:
2729
```julia
2830
k = SqExponentialKernel()
2931
x1 = rand(3)
@@ -76,12 +78,19 @@ For example:
7678

7779
## Kernel parameters
7880

79-
What if you want to differentiate through the kernel parameters? Even in a highly nested structure such as:
81+
What if you want to differentiate through the kernel parameters? This is easy even in a highly nested structure such as:
8082
```julia
81-
k = transform(0.5*SqExponentialKernel()*MaternKernel() + 0.2*(transform(LinearKernel(), 2.0) + PolynomialKernel()), [0.1, 0.5])
83+
k = transform(
84+
0.5 * SqExponentialKernel() * Matern12Kernel()
85+
+ 0.2 * (transform(LinearKernel(), 2.0) + PolynomialKernel()),
86+
[0.1, 0.5])
8287
```
83-
One can get the array of parameters to optimize via `params` from `Flux.jl`:
88+
One can access the named tuple of trainable parameters via `Functors.functor` from `Functors.jl`.
89+
This means that in practice you can implicitly optimize the kernel parameters by calling:
8490
```julia
85-
using Flux
86-
params(k)
91+
using Flux
92+
kernelparams = Flux.params(k)
93+
Flux.gradient(kernelparams) do
94+
# ... some loss function on the kernel ....
95+
end
8796
```

0 commit comments

Comments
 (0)