99using KernelSpectralDensities
1010using AbstractGPs
1111using StatsBase
12- # using LinearAlgebra
13- using AbstractGPsMakie
1412using CairoMakie
13+ using DisplayAs # hide
1514
1615# ## Intro
17- # We use the AbstractGPs package to define a stationary GP prior,
18- # in other words, a GP that has not been conditioned on data yet.
16+ # In general, feature functions allow us to project an input into a higher-dimensional space,
17+ # which is useful for a variety of tasks.
18+ # For example, we can use them to approximate a kernel using the "kernel trick".
1919
20- ker = SqExponentialKernel()
21- S = SpectralDensity(ker, 1 )
22-
23- gp = GP(ker)
24-
25- # We can also plot this GP using AbstractGPsMakie.jl, but
26- # we don't see very much, since we have a simple GP with
27- # zero mean and a variance of 1.
28- f = plot(0 : 0.1 : 1 , gp; size= (600 , 400 ))
29- DisplayAs. PNG(f) # hide #md
30-
31- # ## Random Fourier Features
20+ # A special class of feature functions are "random Fourier features", derived from
21+ # the Fourier transform, which we saw in add link from other example.
3222# KernelSpectralDensities implements two types of random Fourier features,
3323# `ShiftedRFF` and `DoubleRFF`.
34- # A feature function projects its input into a higher-dimensional "features" space.,
3524
36- # ### ShiftedRFF
25+ # ## ShiftedRFF
3726# The `ShiftedRFF` feature function is somewhat more common, and has
3827# been used in papers such as [Efficiently sampling functions from Gaussian process posteriors](https://proceedings.mlr.press/v119/wilson20a.html).
3928#
@@ -61,7 +50,7 @@ axislegend(ax; position=:ct)
6150f
6251DisplayAs. PNG(f) # hide #md
6352
64- # ### DoubleRFF
53+ # ## DoubleRFF
6554# The `DoubleRFF` feature function is less common, but is theoretically
6655# equivalent to the `ShiftedRFF` feature function.
6756#
@@ -86,4 +75,6 @@ ax = Axis(f[1, 1]; xlabel="x", ylabel="rff(x)", title="Double RFF")
8675series!(ax, x, reduce(hcat, drff.(x)); labels= [" drff $i " for i in 1 : 4 ])
8776axislegend(ax; position= :ct)
8877f
89- DisplayAs. PNG(f) # hide #md
78+ DisplayAs. PNG(f) # hide #md
79+
80+ # ## Approximating a kernel
0 commit comments