@@ -10,12 +10,14 @@ processes are hence v times mean-square differentiable. The kernel function is:
10
10
where `r` is the Mahalanobis distance mahalanobis(x,y) with `maha` as the metric.
11
11
12
12
"""
13
- struct PiecewisePolynomialKernel{V, A<: AbstractMatrix{<:Real} } <: BaseKernel
13
+ struct PiecewisePolynomialKernel{V, A<: AbstractMatrix{<:Real} } <: SimpleKernel
14
14
maha:: A
15
+ j:: Int64
15
16
function PiecewisePolynomialKernel {V} (maha:: AbstractMatrix{<:Real} ) where V
16
17
V in (0 , 1 , 2 , 3 ) || error (" Invalid paramter v=$(V) . Should be 0, 1, 2 or 3." )
17
18
LinearAlgebra. checksquare (maha)
18
- return new {V,typeof(maha)} (maha)
19
+ j = div (size (maha, 1 ), 2 ) + V + 1
20
+ return new {V,typeof(maha)} (maha, j)
19
21
end
20
22
end
21
23
@@ -33,75 +35,7 @@ function _piecewisepolynomial(κ::PiecewisePolynomialKernel{V}, r, j) where V
33
35
return max (1 - r, 0 )^ (j + V) * _f (κ, r, j)
34
36
end
35
37
36
- function kappa (
37
- κ:: PiecewisePolynomialKernel{V} ,
38
- x:: AbstractVector{<:Real} ,
39
- y:: AbstractVector{<:Real} ,
40
- ) where {V}
41
- r = evaluate (metric (κ), x, y)
42
- j = div (size (x, 2 ), 1 ) + V + 1
43
- return _piecewisepolynomial (κ, r, j)
44
- end
45
-
46
- function kernelmatrix (
47
- κ:: PiecewisePolynomialKernel{V} ,
48
- X:: AbstractMatrix ;
49
- obsdim:: Int = defaultobs
50
- ) where {V}
51
- j = div (size (X, feature_dim (obsdim)), 2 ) + V + 1
52
- return map (r-> _piecewisepolynomial (κ, r, j), pairwise (metric (κ), X; dims= obsdim))
53
- end
54
-
55
- function kernelmatrix (
56
- κ:: PiecewisePolynomialKernel{V} ,
57
- X:: AbstractMatrix ,
58
- Y:: AbstractMatrix ;
59
- obsdim:: Int = defaultobs
60
- ) where {V}
61
- j = div (size (X, feature_dim (obsdim)), 2 ) + V + 1
62
- return map (r-> _piecewisepolynomial (κ, r, j), pairwise (metric (κ), X, Y; dims= obsdim))
63
- end
64
-
65
-
66
- function _kernelmatrix (κ:: PiecewisePolynomialKernel{V} , X, Y, obsdim) where {V}
67
- j = div (size (X, feature_dim (obsdim)), 2 ) + V + 1
68
- return map (r-> _piecewisepolynomial (κ, r, j), pairwise (metric (κ), X, Y; dims= obsdim))
69
- end
70
-
71
- function kernelmatrix! (
72
- K:: AbstractMatrix ,
73
- κ:: PiecewisePolynomialKernel{V} ,
74
- X:: AbstractMatrix ;
75
- obsdim:: Int = defaultobs
76
- ) where {V}
77
- @assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
78
- if ! check_dims (K, X, X, feature_dim (obsdim), obsdim)
79
- throw (DimensionMismatch (
80
- " Dimensions of the target array K $(size (K)) are not consistent with X " *
81
- " $(size (X)) " ,
82
- ))
83
- end
84
- j = div (size (X, feature_dim (obsdim)), 2 ) + V + 1
85
- return map! (r-> _piecewisepolynomial (κ,r,j), K, pairwise (metric (κ), X; dims= obsdim))
86
- end
87
-
88
- function kernelmatrix! (
89
- K:: AbstractMatrix ,
90
- κ:: PiecewisePolynomialKernel{V} ,
91
- X:: AbstractMatrix ,
92
- Y:: AbstractMatrix ;
93
- obsdim:: Int = defaultobs,
94
- ) where {V}
95
- @assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
96
- if ! check_dims (K, X, Y, feature_dim (obsdim), obsdim)
97
- throw (DimensionMismatch (
98
- " Dimensions $(size (K)) of the target array K are not consistent with X " *
99
- " ($(size (X)) ) and Y ($(size (Y)) )" ,
100
- ))
101
- end
102
- j = div (size (X, feature_dim (obsdim)), 2 ) + V + 1
103
- return map! (r-> _piecewisepolynomial (κ,r,j), K, pairwise (metric (κ), X, Y; dims= obsdim))
104
- end
38
+ kappa (κ:: PiecewisePolynomialKernel , d:: Real ) = _piecewisepolynomial (κ, r, κ. j)
105
39
106
40
metric (κ:: PiecewisePolynomialKernel ) = Mahalanobis (κ. maha)
107
41
0 commit comments