Skip to content

Commit

Permalink
Fix kernel function documentation (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnzl-777 authored Nov 22, 2022
1 parent 3b77626 commit 9334b4e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
10 changes: 10 additions & 0 deletions docs/src/waveform.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,14 @@ sinusoidal
append
smooth
smooth(kernel, Xi::Vector, Yi::Vector, kernel_radius::Real)
Kernels.biweight
Kernels.cosine
Kernels.gaussian
Kernels.logistic
Kernels.parabolic
Kernels.sigmoid
Kernels.triangle
Kernels.tricube
Kernels.triweight
Kernels.uniform
```
108 changes: 106 additions & 2 deletions lib/BloqadeWaveforms/src/smooth.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,125 @@ export gaussian, triangle, uniform, parabolic, biweight, triweight, tricube, cos
# kernels
# https://en.wikipedia.org/wiki/Kernel_(statistics)#Kernel_functions_in_common_use
_in_radius(t, value) = abs(t) 1 ? value : zero(t)
"""
gaussian(t)
Gaussian kernel function for smoothing waveforms via [`smooth`](@ref).
The function is defined as:
```math
f(t) = \\frac{1}{\\sqrt{2π}}e^{-\\frac{1}{2}|t|^2}
```
"""
gaussian(t) = exp(-abs2(t) / 2) / sqrt(2π)
"""
triangle(t)
Triangle kernel function for smoothing waveforms via [`smooth`](@ref).
The function is defined as:
```math
f(t) = 1 - |t|
```
where ``|t| ≤ 1``. Otherwise, ``f(t) = 0``
"""
triangle(t) = _in_radius(t, 1 - abs(t))

"""
uniform(t::T) where {T}
Uniform kernel function for smoothing waveforms via [`smooth`](@ref)
The function returns ``1`` for ``|t| ≤ 1``. Otherwise, it returns ``0``.
"""
function uniform(t::T) where {T}
# we calculate the normalize factor
# in smooth, no need to div by m
return T(abs(t) 1)
end

"""
parabolic(t)
Parabolic kernel function for smoothing waveforms via [`smooth`](@ref)
The function is defined as:
```math
f(t) = \\frac{3}{4}(1 - |t|^2)
```
when ``|t| ≤ 1``. Otherwise, ``f(t) = 0``.
"""
parabolic(t) = _in_radius(t, 3 / 4 * (1 - abs2(t)))
"""
biweight(t)
Biweight kernel function for smoothing waveforms via [`smooth`](@ref)
The function is defined as:
```math
f(t) = \\frac{15}{16}(1 - |t|^2)^2
```
when ``|t| ≤ 1``. Otherwise, ``f(t) = 0``.
"""
biweight(t) = _in_radius(t, 15 / 16 * (1 - abs2(t))^2)
"""
triweight(t)
Biweight kernel function for smoothing waveforms via [`smooth`](@ref)
The function is defined as:
```math
f(t) = \\frac{35}{32}(1 - |t|^2)^3
```
when ``|t| ≤ 1``. Otherwise, ``f(t) = 0``.
"""
triweight(t) = _in_radius(t, 35 / 32 * (1 - abs2(t))^3)
"""
tricube(t)
Tricube kernel function for smoothing waveforms via [`smooth`](@ref)
The function is defined as:
```math
f(t) = \\frac{70}{81}(1 - |t|^3)^3
```
when ``|t| ≤ 1``. Otherwise, ``f(t) = 0``.
"""
tricube(t) = _in_radius(t, 70 / 81 * (1 - abs(t)^3)^3)
"""
cosine(t)
Cosine kernel function for smoothing waveforms via [`smooth`](@ref)
The function is defined as:
```math
f(t) = \\frac{π}{4}\\cos\\left(\\frac{π}{2}t\\right)
```
when ``|t| ≤ 1``. Otherwise, ``f(t) = 0``.
"""
cosine(t) = _in_radius(t, π / 4 * cos/ 2 * t))
# TODO: check numerical stability
"""
logistic(t)
Logistic kernel function for smoothing waveforms via [`smooth`](@ref)
The function is defined as:
```math
f(t) = \\frac{1}{e^{t} + 2 + e^{-t}}
```
"""
logistic(t) = 1 / (exp(t) + 2 + exp(-t))
"""
simgoid(t)
Sigmoid kernel funciton for smoothing waveforms via [`smooth`](@ref)
The function is defined as:
```math
f(t) = \\frac{2}{\\pi (e^{t} + e^{-t})}
```
"""
sigmoid(t) = 2 /* (exp(t) + exp(-t)))

end
Expand Down Expand Up @@ -135,8 +238,9 @@ $(
!startswith(x, '_') &&
!startswith(x, '#') &&
!isequal(x, "Kernels") &&
!isequal(x, "eval")
end |> xs->map(x->string("[`", x, "`](@ref)"), xs), "; "
!isequal(x, "eval") &&
!isequal(x, "include")
end |> xs->map(x->string("[`Kernels.", x, "`](@ref)"), xs), "; "
)
)
Expand Down

0 comments on commit 9334b4e

Please sign in to comment.