|
1 | | -using Distributions |
2 | | - |
3 | | -export GaussianKernel, BoxKernel, RotationalKernel, evaluate |
4 | | - |
5 | | -""" |
6 | | - abstract type Kernel |
7 | | -
|
8 | | -Kernels serve as the backbone of broadening and convolution operations. |
9 | | -All kernels have a common interface: |
10 | | -
|
11 | | - evaluate(::Kernel; maxwidth=8, length=100) |
12 | | -
|
13 | | -which provides the evaluated PDF of the kernel. Note that the user should not |
14 | | -have to provide the evaluated points, so each kernel should have a way of |
15 | | -automatically choosing its range. For instance, a Gaussian kernel may choose to |
16 | | -automatically evaluate 1000 points from -8σ to 8σ. |
17 | | -""" |
18 | | -abstract type Kernel end |
19 | | - |
20 | | -evaluate(k::Kernel; maxwidth = 8, length = 101) = k.(_bounds(k, maxwidth, length)) |
21 | | - |
22 | | -## Implementation Note |
23 | | -# For each new kernel, implement a _pdf function and _bounds function as below |
24 | | -# which serves as the functional form of your kernel this way, we can limit the |
25 | | -# amount of redefinitions of evaluate. |
26 | | - |
27 | | -""" |
28 | | - GaussianKernel(σ::Number) <: Kernel |
29 | | -
|
30 | | -This is a simple Gaussian kernel which is evaluated as a normal distribution with variance σ^2 and a pdf of |
31 | | -
|
32 | | -```math |
33 | | -p(x) = \\frac{1}{σ\\sqrt{2π}} exp\\left(-\\frac{x^2}{2σ^2}\\right) |
34 | | -``` |
35 | | -
|
36 | | -The default evaluation width is ± 4σ. |
37 | | -""" |
38 | | -struct GaussianKernel <: Kernel |
39 | | - σ::Number |
40 | | -end |
41 | | -(k::GaussianKernel)(x) = Normal(0, k.σ).pdf(x) |
42 | | -_bounds(k::GaussianKernel, width, n) = range(-width / 2 * k.σ, width / 2 * k.σ, length = n) |
43 | | - |
44 | | -""" |
45 | | - BoxKernel(width::Number) <: Kernel |
46 | | -
|
47 | | -This is a simple Box (top-hat) kernel with a pdf of |
48 | | -
|
49 | | -```math |
50 | | -p(x) = \\begin{cases} |
51 | | - 1/width & \\abs{x} < width/2 \\ |
52 | | - 0 & \\ |
53 | | -\\end{cases} |
54 | | -``` |
55 | | -
|
56 | | -The default evaluation width is `± 4*width` |
57 | | -""" |
58 | | -struct BoxKernel <: Kernel |
59 | | - width::Number |
60 | | -end |
61 | | -(k::BoxKernel)(x) = Uniform(-k.width / 2, k.width / 2).pdf(x) |
62 | | -_bounds(k::BoxKernel, width, n) = range(-width / 2 * k.width, width / 2 * k.width, length = n) |
63 | | - |
64 | | -struct RotationalKernel{T <: Number} <: Kernel |
65 | | - dv::T |
66 | | - vsini::T |
67 | | -end |
68 | | - |
69 | | -RotationalKernel(dv, vsini) = RotationalKernel(promote(dv, vsini)...) |
| 1 | +#using Distributions |
| 2 | +# |
| 3 | +#export GaussianKernel, BoxKernel, RotationalKernel, evaluate |
| 4 | +# |
| 5 | +#""" |
| 6 | +# abstract type Kernel |
| 7 | +# |
| 8 | +#Kernels serve as the backbone of broadening and convolution operations. |
| 9 | +#All kernels have a common interface: |
| 10 | +# |
| 11 | +# evaluate(::Kernel; maxwidth=8, length=100) |
| 12 | +# |
| 13 | +#which provides the evaluated PDF of the kernel. Note that the user should not |
| 14 | +#have to provide the evaluated points, so each kernel should have a way of |
| 15 | +#automatically choosing its range. For instance, a Gaussian kernel may choose to |
| 16 | +#automatically evaluate 1000 points from -8σ to 8σ. |
| 17 | +#""" |
| 18 | +#abstract type Kernel end |
| 19 | +# |
| 20 | +#evaluate(k::Kernel; maxwidth = 8, length = 101) = k.(_bounds(k, maxwidth, length)) |
| 21 | +# |
| 22 | +### Implementation Note |
| 23 | +## For each new kernel, implement a _pdf function and _bounds function as below |
| 24 | +## which serves as the functional form of your kernel this way, we can limit the |
| 25 | +## amount of redefinitions of evaluate. |
| 26 | +# |
| 27 | +#""" |
| 28 | +# GaussianKernel(σ::Number) <: Kernel |
| 29 | +# |
| 30 | +#This is a simple Gaussian kernel which is evaluated as a normal distribution with variance σ^2 and a pdf of |
| 31 | +# |
| 32 | +#```math |
| 33 | +#p(x) = \\frac{1}{σ\\sqrt{2π}} exp\\left(-\\frac{x^2}{2σ^2}\\right) |
| 34 | +#``` |
| 35 | +# |
| 36 | +#The default evaluation width is ± 4σ. |
| 37 | +#""" |
| 38 | +#struct GaussianKernel <: Kernel |
| 39 | +# σ::Number |
| 40 | +#end |
| 41 | +#(k::GaussianKernel)(x) = Normal(0, k.σ).pdf(x) |
| 42 | +#_bounds(k::GaussianKernel, width, n) = range(-width / 2 * k.σ, width / 2 * k.σ, length = n) |
| 43 | +# |
| 44 | +#""" |
| 45 | +# BoxKernel(width::Number) <: Kernel |
| 46 | +# |
| 47 | +#This is a simple Box (top-hat) kernel with a pdf of |
| 48 | +# |
| 49 | +#```math |
| 50 | +#p(x) = \\begin{cases} |
| 51 | +# 1/width & \\abs{x} < width/2 \\ |
| 52 | +# 0 & \\ |
| 53 | +#\\end{cases} |
| 54 | +#``` |
| 55 | +# |
| 56 | +#The default evaluation width is `± 4*width` |
| 57 | +#""" |
| 58 | +#struct BoxKernel <: Kernel |
| 59 | +# width::Number |
| 60 | +#end |
| 61 | +#(k::BoxKernel)(x) = Uniform(-k.width / 2, k.width / 2).pdf(x) |
| 62 | +#_bounds(k::BoxKernel, width, n) = range(-width / 2 * k.width, width / 2 * k.width, length = n) |
| 63 | +# |
| 64 | +#struct RotationalKernel{T <: Number} <: Kernel |
| 65 | +# dv::T |
| 66 | +# vsini::T |
| 67 | +#end |
| 68 | +# |
| 69 | +#RotationalKernel(dv, vsini) = RotationalKernel(promote(dv, vsini)...) |
0 commit comments