Developer manual
This section is meant to give an idea of how to implement new algorithms in the framework of this package. Examples of all the following descriptions can be found in the original source code.
Deconvolution methods
You can create a new deconvolution method in two steps:
- create a subtype of
DeconvolutionMethod - implement the
deconvolvefunction for this subtype
struct MyNewMethod <: DeconvolutionMethod
...
end
function CherenkovDeconvolution.deconvolve(
m::MyNewMethod,
X_obs::Any,
X_trn::Any,
y_trn::AbstractVector{I}
) where {I<:Integer}
...
endTo create a discrete deconvolution method, which solves g = R * f, you can alternatively create a subtype of DiscreteMethod, for which the deconvolve function is allowed to look differently:
struct MyNewDiscreteMethod <: DiscreteMethod
...
end
function CherenkovDeconvolution.deconvolve(
m::MyNewDiscreteMethod,
R::Matrix{T_R},
g::Vector{T_g},
label_sanitizer::LabelSanitizer,
f_trn::Vector{T_f},
f_0::Union{Vector{T_f},Nothing}
) where {T_R<:Number,T_g<:Number,T_f<:Number}
...
endBinnings
Binning methods are created in a very similar fashion, but they require one extra step: a BinningDiscretizer must be derived from the binning and this discretizer must be used in an implementation of encode.
struct MyNewBinning <: Binning
...
end
struct MyNewDiscretizer{T} <: BinningDiscretizer{T}
...
end
function CherenkovDeconvolution.BinningDiscretizer(
b::MyNewBinning,
X_trn::Any,
y_trn::AbstractVector{I}
) where {I<:Integer}
...
return MyNewDiscretizer{T}(...)
end
function Discretizers.encode(d::MyNewDiscretizer{T}, X_obs::Any)
...
endStepsizes
Stepsize methods require an implementation of the value function. Optionally, they can also implement initialize_prefit! and initialize_deconvolve!.
struct MyNewStepsize <: Stepsize
...
end
function CherenkovDeconvolution.value(
s::MyNewStepsize,
k::Int,
p::Vector{Float64},
f::Vector{Float64},
a::Float64)
...
end
# optional
function CherenkovDeconvolution.initialize_prefit!(
s::MyNewStepsize,
X_trn::Any,
y_trn::AbstractVector{I}
) where {I<:Integer}
...
end
function CherenkovDeconvolution.initialize_deconvolve!(
s::MyNewStepsize,
X_obs::Any,
)
...
end