Skip to content

Commit 591b979

Browse files
authored
Update docstrings and check that constant is non-negative (#230)
1 parent 36ff7e7 commit 591b979

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "KernelFunctions"
22
uuid = "ec8451be-7e33-11e9-00cf-bbf324bd1392"
3-
version = "0.8.13"
3+
version = "0.8.14"
44

55
[deps]
66
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

docs/src/kernels.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The [`ConstantKernel`](@ref) is defined as
1717
k(x,x';c) = c,
1818
```
1919

20-
where $c \in \mathbb{R}$.
20+
where $c \geq 0$.
2121

2222
### White Kernel
2323

src/basekernels/constant.jl

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
"""
22
ZeroKernel()
33
4-
Create a kernel that always returns zero
5-
```
6-
κ(x,y) = 0.0
4+
Zero kernel.
5+
6+
# Definition
7+
8+
For inputs ``x, x'``, the zero kernel is defined as
9+
```math
10+
k(x, x') = 0.
711
```
8-
The output type depends on `x` and `y`
12+
The output type depends on ``x`` and ``x'``.
13+
14+
See also: [`ConstantKernel`](@ref)
915
"""
1016
struct ZeroKernel <: SimpleKernel end
1117

@@ -18,17 +24,21 @@ Base.show(io::IO, ::ZeroKernel) = print(io, "Zero Kernel")
1824
"""
1925
WhiteKernel()
2026
27+
White noise kernel.
28+
29+
# Definition
30+
31+
For inputs ``x, x'``, the white noise kernel is defined as
32+
```math
33+
k(x, x') = \\delta(x, x').
2134
```
22-
κ(x,y) = δ(x,y)
23-
```
24-
Kernel function working as an equivalent to add white noise. Can also be called via `EyeKernel()`
2535
"""
2636
struct WhiteKernel <: SimpleKernel end
2737

2838
"""
2939
EyeKernel()
3040
31-
See [`WhiteKernel`](@ref)
41+
Alias of [`WhiteKernel`](@ref).
3242
"""
3343
const EyeKernel = WhiteKernel
3444

@@ -39,17 +49,25 @@ metric(::WhiteKernel) = Delta()
3949
Base.show(io::IO, ::WhiteKernel) = print(io, "White Kernel")
4050

4151
"""
42-
ConstantKernel(; c=1.0)
52+
ConstantKernel(; c::Real=1.0)
4353
44-
Kernel function always returning a constant value `c`
45-
```
46-
κ(x,y) = c
54+
Kernel of constant value `c`.
55+
56+
# Definition
57+
58+
For inputs ``x, x'``, the kernel of constant value ``c \\geq 0`` is defined as
59+
```math
60+
k(x, x') = c.
4761
```
62+
63+
See also: [`ZeroKernel`](@ref)
4864
"""
4965
struct ConstantKernel{Tc<:Real} <: SimpleKernel
5066
c::Vector{Tc}
51-
function ConstantKernel(; c::T=1.0) where {T<:Real}
52-
return new{T}([c])
67+
68+
function ConstantKernel(; c::Real=1.0)
69+
@check_args(ConstantKernel, c, c >= zero(c), "c ≥ 0")
70+
return new{typeof(c)}([c])
5371
end
5472
end
5573

0 commit comments

Comments
 (0)