Input Transforms
Overview
Transform
s are designed to change input data before passing it on to a kernel object.
It can be as standard as IdentityTransform
returning the same input, or multiplying the data by a scalar with ScaleTransform
or by a vector with ARDTransform
. There is a more general FunctionTransform
that uses a function and applies it to each input.
You can also create a pipeline of Transform
s via ChainTransform
, e.g.,
LowRankTransform(rand(10, 5)) ∘ ScaleTransform(2.0)
A transformation t
can be applied to a single input x
with t(x)
and to multiple inputs xs
with map(t, xs)
.
Kernels can be coupled with input transformations with transform
. It falls back to creating a TransformedKernel
but allows more optimized implementations for specific kernels and transformations.
List of Input Transforms
KernelFunctions.Transform
— TypeTransform
Abstract type defining a transformation of the input.
KernelFunctions.IdentityTransform
— TypeIdentityTransform()
Transformation that returns exactly the input.
KernelFunctions.ScaleTransform
— TypeScaleTransform(l::Real)
Transformation that multiplies the input elementwise with l
.
Examples
julia> l = rand(); t = ScaleTransform(l); X = rand(100, 10);
julia> map(t, ColVecs(X)) == ColVecs(l .* X)
true
KernelFunctions.ARDTransform
— TypeARDTransform(v::AbstractVector)
Transformation that multiplies the input elementwise by v
.
Examples
julia> v = rand(10); t = ARDTransform(v); X = rand(10, 100);
julia> map(t, ColVecs(X)) == ColVecs(v .* X)
true
KernelFunctions.ARDTransform
— MethodARDTransform(s::Real, dims::Integer)
Create an ARDTransform
with vector fill(s, dims)
.
KernelFunctions.LinearTransform
— TypeLinearTransform(A::AbstractMatrix)
Linear transformation of the input realised by the matrix A
.
The second dimension of A
must match the number of features of the target.
Examples
julia> A = rand(10, 5); t = LinearTransform(A); X = rand(5, 100);
julia> map(t, ColVecs(X)) == ColVecs(A * X)
true
KernelFunctions.FunctionTransform
— TypeFunctionTransform(f)
Transformation that applies function f
to the input.
Make sure that f
can act on an input. For instance, if the inputs are vectors, use f(x) = sin.(x)
instead of f = sin
.
Examples
julia> f(x) = sum(x); t = FunctionTransform(f); X = randn(100, 10);
julia> map(t, ColVecs(X)) == ColVecs(sum(X; dims=1))
true
KernelFunctions.SelectTransform
— TypeSelectTransform(dims)
Transformation that selects the dimensions dims
of the input.
Examples
julia> dims = [1, 3, 5, 6, 7]; t = SelectTransform(dims); X = rand(100, 10);
julia> map(t, ColVecs(X)) == ColVecs(X[dims, :])
true
KernelFunctions.ChainTransform
— TypeChainTransform(ts::AbstractVector{<:Transform})
Transformation that applies a chain of transformations ts
to the input.
The transformation first(ts)
is applied first.
Examples
julia> l = rand(); A = rand(3, 4); t1 = ScaleTransform(l); t2 = LinearTransform(A);
julia> X = rand(4, 10);
julia> map(ChainTransform([t1, t2]), ColVecs(X)) == ColVecs(A * (l .* X))
true
julia> map(t2 ∘ t1, ColVecs(X)) == ColVecs(A * (l .* X))
true
KernelFunctions.PeriodicTransform
— TypePeriodicTransform(f)
Transformation that maps the input elementwise onto the unit circle with frequency f
.
Samples from a GP with a kernel with this transformation applied to the inputs will produce samples with frequency f
.
Examples
julia> f = rand(); t = PeriodicTransform(f); x = rand();
julia> t(x) == [sinpi(2 * f * x), cospi(2 * f * x)]
true