Wrapper models
Wrapper models are a type of "meta-model" that can be used to change the behaviour of other models. Their constructors commonly take a model as an argument, and change the way this model is called.
The following wrapper models are available
SpectralFitting.AbstractModelWrapper
SpectralFitting.AsConvolution
SpectralFitting.AutoCache
SpectralFitting.ParameterPatch
SpectralFitting.ParameterPatch
— TypeParameterPatch(model; patch::Function)
An AbstractModelWrapper
that can be used to manipulate the parameters of the model it wraps. For example
model = PowerLaw() + PowerLaw()
function patcher!(p)
# any arbitrary function may be defined here
p.a1.K = 3 * p.a2.K + sqrt(p.a2.a)
end
patched_model = ParameterPatch(model; patch = patcher!)
# set the patched parameter as frozen so it is not fitted
# failing to do so may ruin a fit
patched_model.a1.K.frozen = true
When the model is invoked, it will call the patch
function to manipulate the parameters as desired.
SpectralFitting.apply_patch!
— Functionapply_patch!(model::ParameterPatch)
Apply a patch to the model (i.e. use the patch!
function to update the model parameters).
SpectralFitting.AsConvolution
— TypeAsConvolution(model; domain = collect(range(0, 2, 100)))
Turn an additive model into a convolutional model.
Example
convolution_model = AsConvolution(GaussianLine())
The above model will now convolve the GaussianLine
model onto whatever it is applied to.
The domain
keyword can be used to pass the domain on which to evaluate the wrapped model before convolution. The domain is such that x = 1
corresponds to no domain shift in the convolution (e.g., if the domain is energy, this would be the rest energy of a line).
SpectralFitting.AutoCache
— TypeAutoCache
Used to automatically create a cache of another model, to avoid re-evaluating the model if the next parameters are close to the previous parameters. The intended use is for fitting expensive models which.
Example
model = PhotoelectricAbsorption() * AutoCache(PowerLaw())
In the above model, the PowerLaw
component will be augmented with the caching behaviour.
SpectralFitting.AbstractModelWrapper
— Typeabstract type AbstractModelWrapper{M,T,K} <: AbstractSpectralModel{T,K} end
Used to implement wrapper models that take existing models as their argument and modify their behaviour.