@@ -6,27 +6,58 @@ using .Kronecker: Kronecker
6
6
export kernelkronmat
7
7
export kronecker_kernelmatrix
8
8
9
- function kernelkronmat (κ:: Kernel , X:: AbstractVector , dims:: Int )
10
- @assert iskroncompatible (κ) " The chosen kernel is not compatible for kroenecker matrices (see [`iskroncompatible`](@ref))"
11
- k = kernelmatrix (κ, X)
12
- return Kronecker. kronecker (k, dims)
9
+ @doc raw """
10
+ kernelkronmat(κ::Kernel, X::AbstractVector{<:Real}, dims::Int) -> KroneckerPower
11
+
12
+ Return a `KroneckerPower` matrix on the `D`-dimensional input grid constructed by ``\o times_{i=1}^D X``,
13
+ where `D` is given by `dims`.
14
+
15
+ !!! warning
16
+
17
+ Require `Kronecker.jl` and for `iskroncompatible(κ)` to return `true`.
18
+ """
19
+ function kernelkronmat (κ:: Kernel , X:: AbstractVector{<:Real} , dims:: Int )
20
+ checkkroncompatible (κ)
21
+ K = kernelmatrix (κ, X)
22
+ return Kronecker. kronecker (K, dims)
13
23
end
14
24
15
- function kernelkronmat (
16
- κ:: Kernel , X:: AbstractVector{<:AbstractVector} ; obsdim:: Int = defaultobs
17
- )
18
- @assert iskroncompatible (κ) " The chosen kernel is not compatible for Kronecker matrices"
25
+ @doc raw """
26
+
27
+ kernelkronmat(κ::Kernel, X::AbstractVector{<:AbstractVector}) -> KroneckerProduct
28
+
29
+ Returns a `KroneckerProduct` matrix on the grid built with the collection of vectors ``\{ X_i\} _{i=1}^D``: ``\o times_{i=1}^D X_i``.
30
+
31
+ !!! warning
32
+
33
+ Requires `Kronecker.jl` and for `iskroncompatible(κ)` to return `true`.
34
+ """
35
+ function kernelkronmat (κ:: Kernel , X:: AbstractVector{<:AbstractVector} )
36
+ checkkroncompatible (κ)
19
37
Ks = kernelmatrix .(κ, X)
20
- return K = reduce (Kronecker.:⊗ , Ks)
38
+ return reduce (Kronecker.:⊗ , Ks)
21
39
end
22
40
23
- """
24
- To be compatible with kroenecker constructions the kernel must satisfy
25
- the property : for x,x' ∈ ℜᴰ
26
- k(x,x') = ∏ᵢᴰ k(xᵢ,x'ᵢ)
41
+ @doc raw """
42
+ iskroncompatible(k::Kernel)
43
+
44
+ Determine whether kernel `k` is compatible with Kronecker constructions such as [`kernelkronmat`](@ref)
45
+
46
+ The function returns `false` by default. If `k` is compatible it must satisfy for all ``x, x' \i n \m athbb{R}^D`:
47
+ ```math
48
+ k(x, x') = \p rod_{i=1}^D k(x_i, x'_i).
49
+ ```
27
50
"""
28
51
@inline iskroncompatible (κ:: Kernel ) = false # Default return for kernels
29
52
53
+ function checkkroncompatible (κ:: Kernel )
54
+ return iskroncompatible (κ) || throw (
55
+ ArgumentError (
56
+ " The chosen kernel is not compatible for Kronecker matrices (see [`iskroncompatible`](@ref))" ,
57
+ ),
58
+ )
59
+ end
60
+
30
61
function _kernelmatrix_kroneckerjl_helper (
31
62
:: Type{<:MOInputIsotopicByFeatures} , Kfeatures, Koutputs
32
63
)
0 commit comments