|
| 1 | +""" |
| 2 | + spectral_mixture_kernel( |
| 3 | + h::Kernel=SqExponentialKernel(), |
| 4 | + αs::AbstractVector{<:Real}, |
| 5 | + γs::AbstractMatrix{<:Real}, |
| 6 | + ωs::AbstractMatrix{<:Real}, |
| 7 | + ) |
| 8 | +
|
| 9 | +where αs are the weights of dimension (A, ), γs is the covariance matrix of |
| 10 | +dimension (D, A) and ωs are the mean vectors and is of dimension (D, A). |
| 11 | +Here, D is input dimension and A is the number of spectral components. |
| 12 | +
|
| 13 | +`h` is the kernel, which defaults to [`SqExponentialKernel`](@ref) if not specified. |
| 14 | +
|
| 15 | +Generalised Spectral Mixture kernel function. This family of functions is dense |
| 16 | +in the family of stationary real-valued kernels with respect to the pointwise convergence.[1] |
| 17 | +
|
| 18 | +```math |
| 19 | + κ(x, y) = αs' (h(-(γs' * t)^2) .* cos(π * ωs' * t), t = x - y |
| 20 | +``` |
| 21 | +
|
| 22 | +# References: |
| 23 | + [1] Generalized Spectral Kernels, by Yves-Laurent Kom Samo and Stephen J. Roberts |
| 24 | + [2] SM: Gaussian Process Kernels for Pattern Discovery and Extrapolation, |
| 25 | + ICML, 2013, by Andrew Gordon Wilson and Ryan Prescott Adams, |
| 26 | + [3] Covariance kernels for fast automatic pattern discovery and extrapolation |
| 27 | + with Gaussian processes, Andrew Gordon Wilson, PhD Thesis, January 2014. |
| 28 | + http://www.cs.cmu.edu/~andrewgw/andrewgwthesis.pdf |
| 29 | + [4] http://www.cs.cmu.edu/~andrewgw/pattern/. |
| 30 | +
|
| 31 | +""" |
| 32 | +function spectral_mixture_kernel( |
| 33 | + h::Kernel, |
| 34 | + αs::AbstractVector{<:Real}, |
| 35 | + γs::AbstractMatrix{<:Real}, |
| 36 | + ωs::AbstractMatrix{<:Real}, |
| 37 | +) |
| 38 | + if !(size(αs, 1) == size(γs, 2) == size(ωs, 2)) |
| 39 | + throw(DimensionMismatch("The dimensions of αs, γs, ans ωs do not match")) |
| 40 | + end |
| 41 | + if size(γs) != size(ωs) |
| 42 | + throw(DimensionMismatch("The dimensions of γs ans ωs do not match")) |
| 43 | + end |
| 44 | + |
| 45 | + return sum(zip(αs, eachcol(γs), eachcol(ωs))) do (α, γ, ω) |
| 46 | + a = TransformedKernel(h, LinearTransform(γ')) |
| 47 | + b = TransformedKernel(CosineKernel(), LinearTransform(ω')) |
| 48 | + return α * a * b |
| 49 | + end |
| 50 | +end |
| 51 | + |
| 52 | +function spectral_mixture_kernel( |
| 53 | + αs::AbstractVector{<:Real}, |
| 54 | + γs::AbstractMatrix{<:Real}, |
| 55 | + ωs::AbstractMatrix{<:Real} |
| 56 | +) |
| 57 | + spectral_mixture_kernel(SqExponentialKernel(), αs, γs, ωs) |
| 58 | +end |
| 59 | + |
| 60 | +""" |
| 61 | + spectral_mixture_product_kernel( |
| 62 | + h::Kernel=SqExponentialKernel(), |
| 63 | + αs::AbstractMatrix{<:Real}, |
| 64 | + γs::AbstractMatrix{<:Real}, |
| 65 | + ωs::AbstractMatrix{<:Real}, |
| 66 | + ) |
| 67 | +
|
| 68 | +where αs are the weights of dimension (D, A), γs is the covariance matrix of |
| 69 | +dimension (D, A) and ωs are the mean vectors and is of dimension (D, A). |
| 70 | +Here, D is input dimension and A is the number of spectral components. |
| 71 | +
|
| 72 | +Spectral Mixture Product Kernel. With enough components A, the SMP kernel |
| 73 | +can model any product kernel to arbitrary precision, and is flexible even |
| 74 | +with a small number of components [1] |
| 75 | +
|
| 76 | +
|
| 77 | +`h` is the kernel, which defaults to [`SqExponentialKernel`](@ref) if not specified. |
| 78 | +
|
| 79 | +```math |
| 80 | + κ(x, y) = Πᵢ₌₁ᴷ Σ(αsᵢᵀ .* (h(-(γsᵢᵀ * tᵢ)²) .* cos(ωsᵢᵀ * tᵢ))), tᵢ = xᵢ - yᵢ |
| 81 | +``` |
| 82 | +
|
| 83 | +# References: |
| 84 | + [1] GPatt: Fast Multidimensional Pattern Extrapolation with GPs, |
| 85 | + arXiv 1310.5288, 2013, by Andrew Gordon Wilson, Elad Gilboa, |
| 86 | + Arye Nehorai and John P. Cunningham |
| 87 | +""" |
| 88 | +function spectral_mixture_product_kernel( |
| 89 | + h::Kernel, |
| 90 | + αs::AbstractMatrix{<:Real}, |
| 91 | + γs::AbstractMatrix{<:Real}, |
| 92 | + ωs::AbstractMatrix{<:Real}, |
| 93 | +) |
| 94 | + if !(size(αs) == size(γs) == size(ωs)) |
| 95 | + throw(DimensionMismatch("The dimensions of αs, γs, ans ωs do not match")) |
| 96 | + end |
| 97 | + return TensorProduct(spectral_mixture_kernel(h, α, reshape(γ, 1, :), reshape(ω, 1, :)) |
| 98 | + for (α, γ, ω) in zip(eachrow(αs), eachrow(γs), eachrow(ωs))) |
| 99 | +end |
| 100 | + |
| 101 | +function spectral_mixture_product_kernel( |
| 102 | + αs::AbstractMatrix{<:Real}, |
| 103 | + γs::AbstractMatrix{<:Real}, |
| 104 | + ωs::AbstractMatrix{<:Real} |
| 105 | +) |
| 106 | + spectral_mixture_product_kernel(SqExponentialKernel(), αs, γs, ωs) |
| 107 | +end |
| 108 | + |
0 commit comments