@@ -6,6 +6,15 @@ In-place version of [`kernelmatrix`](@ref) where pre-allocated matrix `K` will b
6
6
"""
7
7
kernelmatrix!
8
8
9
+ # # Wrapper for vector of reals
10
+ function kernelmatrix! (
11
+ K:: AbstractMatrix ,
12
+ κ:: Kernel ,
13
+ X:: AbstractVector{<:Real}
14
+ )
15
+ kernelmatrix! (K, κ, reshape (X, 1 , :), obsdim = 2 )
16
+ end
17
+
9
18
function kernelmatrix! (
10
19
K:: AbstractMatrix ,
11
20
κ:: SimpleKernel ,
@@ -27,9 +36,9 @@ function kernelmatrix!(
27
36
)
28
37
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
29
38
if obsdim == 1
30
- @compat kernelmatrix! (K, κ, ColVecs (X))
39
+ kernelmatrix! (K, κ, ColVecs (X))
31
40
else
32
- @compat kernelmatrix! (K, κ, RowVecs (X ))
41
+ kernelmatrix! (K, κ, ColVecs (X ' ))
33
42
end
34
43
end
35
44
@@ -44,6 +53,16 @@ function kernelmatrix!(
44
53
map! (κ, K, X, X' )
45
54
end
46
55
56
+ # # Wrapper for vector of reals
57
+ function kernelmatrix! (
58
+ K:: AbstractMatrix ,
59
+ κ:: Kernel ,
60
+ X:: AbstractVector{<:Real} ,
61
+ Y:: AbstractVector{<:Real}
62
+ )
63
+ kernelmatrix! (K, κ, reshape (X, 1 , :), reshape (Y, 1 , :), obsdim = 2 )
64
+ end
65
+
47
66
function kernelmatrix! (
48
67
K:: AbstractMatrix ,
49
68
κ:: SimpleKernel ,
@@ -108,8 +127,6 @@ function kernelmatrix(κ::Kernel, X::AbstractVector, Y::AbstractVector)
108
127
κ .(X, Y' )
109
128
end
110
129
111
-
112
-
113
130
function kernelmatrix (κ:: SimpleKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
114
131
@assert obsdim ∈ [1 , 2 ] " obsdim should be 1 or 2 (see docs of `kernelmatrix`))"
115
132
K = map (x -> kappa (κ, x), pairwise (metric (κ), X, dims = obsdim))
@@ -124,6 +141,14 @@ function kernelmatrix(κ::Kernel, X::AbstractMatrix; obsdim::Int = defaultobs)
124
141
end
125
142
end
126
143
144
+ function kernelmatrix (
145
+ κ:: Kernel ,
146
+ X:: AbstractVector{<:Real} ,
147
+ Y:: AbstractMatrix{<:Real}
148
+ )
149
+ kernelmatrix (κ, reshape (X, 1 , :), reshape (Y, 1 , :), obsdim = 2 )
150
+ end
151
+
127
152
function kernelmatrix (
128
153
κ:: SimpleKernel ,
129
154
X:: AbstractMatrix ,
@@ -147,16 +172,18 @@ Calculate the diagonal matrix of `X` with respect to kernel `κ`
147
172
`obsdim = 1` means the matrix `X` has size #samples x #dimension
148
173
`obsdim = 2` means the matrix `X` has size #dimension x #samples
149
174
"""
175
+ kerneldiagmatrix
176
+
150
177
function kerneldiagmatrix (
151
178
κ:: Kernel ,
152
179
X:: AbstractMatrix ;
153
180
obsdim:: Int = defaultobs
154
181
)
155
182
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
156
183
if obsdim == 1
157
- @compat kerneldiagmatrix (κ, ColVecs (X)) # [@views _kernel(κ,X[i,:],X[i,:]) for i in 1:size(X,obsdim)]
184
+ kerneldiagmatrix (κ, ColVecs (X)) # [@views _kernel(κ,X[i,:],X[i,:]) for i in 1:size(X,obsdim)]
158
185
elseif obsdim == 2
159
- @compat kerneldiagmatrix (κ, RowVecs (X )) # [@views _kernel(κ,X[:,i],X[:,i]) for i in 1:size(X,obsdim)]
186
+ kerneldiagmatrix (κ, ColVecs (X ' )) # [@views _kernel(κ,X[:,i],X[:,i]) for i in 1:size(X,obsdim)]
160
187
end
161
188
end
162
189
0 commit comments