Feature functions
KernelSpectralDensities.AbstractRFF
— TypeAbstractRFF
Abstract type defining a random Fourier feature function.
KernelSpectralDensities.ShiftedRFF
— TypeShiftedRFF([rng::AbstractRNG], S::SpectralDensity, l::Int)
Random Fourier feature function with a random shift, projecting an input x
into l
dimensionional feature space.
Definition
This feature function is defined as
\[ \sqrt{2 / l} \cos(2 π ((w^T x) + b))\]
where w
sampled from the spectral density S, b
is uniformly sampled from [0, 2π]
and l
is the number of sampled frequencies.
Examples
julia> k = SqExponentialKernel();
julia> S = SpectralDensity(k, 1);
julia> rff = ShiftedRFF(S, 2);
julia> rff(1.);
KernelSpectralDensities.DoubleRFF
— TypeDoubleRFF([rng::AbstractRNG], S::SpectralDensity, l::Int)
Random Fourier feature function with cos and sin terms, projecting an input x
into l
dimensionional feature space.
Definition
This feature function is defined as
\[ \sqrt{1 / l} [\cos(2 π w' x), \sin(2 π w' x)]\]
where w
sampled from the spectral density S, with a total of l/2
sampled frequencies. The output will be the result of [cos(...w_1), cos(...w_2), ..., cos(...w_l/2), sin(...w_1), sin(...w_2), ..., sin(...w_l/2)]
.
Examples
julia> k = SqExponentialKernel();
julia> S = SpectralDensity(k, 1);
julia> rff = DoubleRFF(S, 2);
julia> rff(1.);
KernelSpectralDensities.ApproximateGPSample
— TypeApproximateGPSample(rff::AbstractRFF)
An approximate sample from the GP prior defined by the kernel that corresponds to the spectral density S
that the RFF rff
is based on.
Definition
Using the a vector of l
random fourier features r(x)
, we can define the Bayesian linear model
\[ g_s(x) = w' r(x)\]
where w_i ~ N(0, 1), i = 1,...,l
. Each draw of w
results in a different function sample from the GP prior.
Examples
julia> k = SqExponentialKernel();
julia> S = SpectralDensity(k, 1);
julia> rff = DoubleRFF(S, 2);
julia> ap = ApproximateGPSample(rff);
julia> ap(1.);