API Documentation
The API for the package
Standard functions
There is a range of predefined functions implemented as a struct that holds tuple of parameters
Parameters
The default parameter type is the NamedTuple
. It holds parameter values and names and can update their value. The additional type FlaggedNamedTuple
allows to group parameters to freed
and fixed
AlgebraPDF.FlaggedNamedTuple
— TypeFlaggedNamedTuple(t::NamedTuple) = FlaggedNamedTuple(t, ())
FlaggedNamedTuple(ps::FlaggedNamedTuple) = FlaggedNamedTuple(allpars(ps), whichfixed(ps))
FlaggedNamedTuple(; kw...) = FlaggedNamedTuple((; kw...))
immutable type that holds a NamedTuple of parameters and a tuple of symbols that indicates which parameters are fixed. The short alias for the FlaggedNamedTuple
is Ext
.
Examples
julia> ps = FlaggedNamedTuple((a=1,b=2,c=3), (:a, :b)) # a and b are fixed
FlaggedNamedTuple{(:a, :b, :c)}((a = 1, b = 2, c = 3), (:a, :b))
julia> freepars(ps)
(c = 3,)
julia> fixedpars(ps)
(a = 1, b = 2)
julia> Ext((a = 2.2,)).a
2.2
The package introduces two operations on parameter types, merge
and subtract
. The merge(nt1::NamedTuple, nt1::NamedTuple)
is defined in Base
.
AlgebraPDF.subtract
— Functionsubtract(t1::NamedTuple, t2::NamedTuple)
subtract(t1::NamedTuple, s::Symbol)
subtract(t1::NamedTuple, ss::AbstractVector{Symbol})
subtract(t1::NamedTuple, ss::Tuple{Vararg{Symbol}})
Remove parameters from the NamedTuple that are given by the second argument. It can be a single symbol, a vector of symbols or a tuple of symbols.
Examples
julia> subtract((a=1,b=2,d=1,c=2), (d=1,))
(a = 1, b = 2, c = 2)
julia> subtract((a=1,b=2,d=1,c=2), :d)
(a = 1, b = 2, c = 2)
julia> subtract((a=1,b=2,d=1,c=2), [:d, :a])
(b = 2, c = 2)
julia> subtract((a=1,b=2,d=1,c=2), (:d, :a))
(b = 2, c = 2)
Functions
Several common function are defined
AlgebraPDF.FGauss
— TypeFGauss{P} <: AbstractFunctionWithParameters
A Gaussian (or normal) function, represented as a subtype of AbstractFunctionWithParameters. The struct is parametered by the type of its parameters
This struct represents a Gaussian distribution with mean μ
and standard deviation σ
. The function is defined as:
\[f(x) = \frac{1}{\sqrt{2π}σ} e^{-\frac{(x-μ)^2}{2σ^2}}\]
Fields
p::P
: Parameters of the Gaussian distribution.P
is a type, a named tuple in the simplest case,
that should contain the keys for the mean and standard deviation.
Example
gaussian = FGauss((my_μ=0.0, my_σ=1.0))
gaussian(1.1) # Evaluate the Gaussian function at x=1.1
gaussian(1.1; p=(my_μ=0.5, my_σ=1.5)) # Evaluate with adjusted parameters.
Notes
- The order of parameters in
P
is important: first mean, then standard deviation. - To evaluate the function at a given point
x
, one can do eithergaussian(x)
, orfunc(gaussian, x)
.
AlgebraPDF.FExp
— TypeFExp{P} <: AbstractFunctionWithParameters
An Exponential function, represented as a subtype of AbstractFunctionWithParameters. The struct is parameterized by the type of its parameters.
This struct represents an exponential distribution function with parameter β
. The function is defined as:
\[f(x) = e^{βx}\]
Fields
p::P
: Parameters of the exponential function.P
is a type, typically a named tuple, that should contain an entry for the slope.
Example
expfunc = FExp((my_β=-0.5))
expfunc(1.1) # Evaluate the Exponential function at x=1.1
expfunc(1.1; p=(my_β=-0.7)) # Evaluate with an adjusted parameter.
Notes
- The parameter
β
defines the rate or scale of the exponential function. - To evaluate the function at a given point
x
, one can use eitherexpfunc(x)
orfunc(expfunc, x)
.
AlgebraPDF.FPol
— TypeFPol{P} <: AbstractFunctionWithParameters
A polynomial function, a linear sum of power serience in x
with an increamental power starting from 0. The coefficients are defined in the parameters. The function is generally defined as:
\[f(x) = c_0 + c_1 x + c_2 x^2 + c_3 x^3 + \cdots\]
Fields
p::P
: Parameters of the polynomial function.
P
is a type, typically a named tuple, that should contain the coefficients of the polynomial, e.g. c0
, c1
, c2
.
Example
polynomial = FPol((c0=1.0, c1=-0.5, c2=0.25))
polynomial(2.0) # Evaluate the polynomial function at x=2.0
polynomial(2.0; p=(c0=1.0, c1=-0.5, c2=0.1)) # Evaluate with adjusted function
Notes
- The coefficients in
P
follow the order of the polynomial terms, starting from the constant term (c0) to higher-degree terms (c1, c2, ...).
The user is reponsible to use appropriate names for the coeffients. FPol((c6=1.0, c2=-0.5, c0=0.25))
is a valid construction, however, extremely comfusing as referres to c_8 + c_2 x + c_0 x^2
- To evaluate the polynomial function at a given point
x
, one can use eitherpolynomial(x)
orfunc(polynomial, x)
.
AlgebraPDF.FDoubleGaussFixedRatio
— TypeFDoubleGaussFixedRatio{P} <: AbstractFunctionWithParameters
A combination of two Gaussian functions with a fixed ratio, represented as a subtype of AbstractFunctionWithParameters. The struct is parameterized by the type of its parameters, which define the characteristics of the two Gaussian functions.
This struct represents a function that is a weighted sum of two Gaussian distributions with a common mean μ
but different standard deviations σ
and n*σ
. The ratio r
defines the weight of the first Gaussian in the sum. The function is defined as:
\[f(x) = r \frac{1}{\sqrt{2π}σ} e^{-\frac{(x-μ)^2}{2σ^2}} + (1-r) \frac{1}{\sqrt{2π}(nσ)} e^{-\frac{(x-μ)^2}{2(nσ)^2}}\]
Fields
p::P
: Parameters of the double Gaussian function.
P
is a type, typically a named tuple, that should contain the keys for mean, standard deviation of the first Gaussian, ratio of the first Gaussian, and the ratio of the second Gaussian's standard deviation to the first' one.
Example
doubleGauss = FDoubleGaussFixedRatio((μ=0.0, σ=1.0, r=0.5, n=2.0))
doubleGauss(1.1) # Evaluate the double Gaussian function at x=1.1
doubleGauss(1.1; p=(μ=0.5, σ=1.5, r=0.7, n=2.5)) # Evaluate with adjusted parameters.
AlgebraPDF.noparsnormf
— Functionnoparsnormf(d::AbstractPDF; p=pars(d))
Returns a single-argument lambda-function with parameters fixed to p
and normalization computed.
AlgebraPDF.nt
— Functionnt(s::Symbol, v = 0.0)
Creates a named tuple (s=v,)
where s
is a provided symbol, and v
is the value.
Macros
AlgebraPDF.@makepdftype
— Macro@makepdftype MyPDF(x;p) = unnormdensity(x, p.a, p.b)
Expected form of the expression is f(x;p)
on the left
AlgebraPDF.@makefuntype
— Macro@makefuntype MyPDF(x;p) = unnormdensity(x, p.a, p.b)
Expected form of the expression is `f(x;p)` on the left
Other Functions
AlgebraPDF.updatevalueorflag
— Functionupdatevalueorflag(p::FlaggedNamedTuple, s::Symbol, isfree::Bool, v=getproperty(pars(p),s))
Implementation of the main update method for FlaggedNamedTuple
parameters.