User's Guide

User's Guide

Kernel

Kernel can be specified as a matrix or as a function. It is possible to set arbitrary function of 2 variables or use one of predefined kernels.

getOpticsKernels(name::String, alpha::Real = 1.)

Arguments

  • name - name of a kernel

  • alpha - kernel function parameter

Returns: kernel, function of 2 variables.

Available kernels:

  • rectangular:
\[K(x, y) = \begin{cases} 1, \text{if } \frac{|x-y|}{\alpha} < 1 \ \text{; } 0 \text{ otherwise} \end{cases}\]
  • diffraction:
\[K(x, y) = \left(\frac{sin(\frac{\pi (x-y)}{s_0})}{\frac{\pi (x-y)}{s_0}}\right)^2\]
\[s_0 = \frac{\alpha}{0.886}\]
  • gaussian:
\[K(x, y) = \frac{2}{\alpha}\sqrt{\frac{\ln2}{\pi}}e^{4\ln2\left(\frac{x-y}{\alpha}\right)^2}\]
  • triangular:
\[K(x, y) = \begin{cases} \frac{1 - \frac{|x-y|}{\alpha}}{\alpha}, \text{if } \frac{|x-y|}{\alpha} < 1 \ \text{; } 0 \text{ otherwise} \end{cases}\]
  • dispersive:
\[K(x, y) = \frac{\alpha}{2 \pi}\left((x-y)^2 + \left(\frac{\alpha}{2}\right)^2\right)\]
  • exponential:
\[K(x, y) = \frac{\ln2}{\alpha}e^{2\ln2\frac{|x-y|}{\alpha}}\]
  • heaviside:
\[K(x, y) = \begin{cases} 1, \text{if } x>0 \ \text{; } 0 \text{ otherwise} \end{cases}\]
source
discretize_kernel(basis::Basis, kernel::Function, measurement_points::AbstractVector{<:Real})

Arguments

  • basis – basis
  • kernel – kernel function
  • measurement_points – array of data points

Returns: discretized kernel K::Array{Real, 2}, $K_{mn} = \int\limits_a^b K(x, y_n) \psi_m(x) dx$ - matrix of size n$\times$m, where $m$ - number of basis functions, $n$ - number of data points.

source

Bases

Abstract type for all bases.

source
omega(basis::Basis, order::Int)

Arguments

  • basis - basis
  • order - order of derivatives

Returns: Omega::Array{Real, 2}, $\Omega_{mn} = \int\limits_a^b \frac{d^{order} \psi_m}{dx^{order}} \frac{d^{order} \psi_n}{dx^{order}}$ - matrix of size n$\times$n of the mean values of derivatives of order order, where n - number of functions in basis.

source

Fourier basis

Fourier basis with length $2n+1$: {$0.5$, $\sin(\frac{\pi (x - \frac{a+b}{2})}{b-a})$, $\cos(\frac{\pi (x - \frac{a+b}{2})}{b-a})$, ..., $\sin(\frac{\pi n (x - \frac{a+b}{2})}{b-a})$, $\cos(\frac{\pi n (x - \frac{a+b}{2})}{b-a})$}.

FourierBasis(a::Real, b::Real, n::Int)

a, b – the beginning and the end of the segment n – number of harmonics

Fields

  • a::Real – beginning of the support
  • b::Real – end of the support
  • n::Int – number of harmonics
  • basis_functions::AbstractVector – array of basis functions
source

Cubic Spline basis

Cubic spline basis on given knots with length $n$.

CubicSplineBasis(
    knots::AbstractVector{<:Real},
    boundary_condition::Union{Tuple{Union{String, Nothing}, Union{String, Nothing}}, Nothing, String}=nothing
    )
CubicSplineBasis(
    a::Real, b::Real, n::Int,
    boundary_condition::Union{Tuple{Union{String, Nothing}, Union{String, Nothing}}, Nothing, String}=nothing
    )

knots – knots of spline boundary_condition – boundary conditions of basis functions. If tuple, the first element affects left bound, the second element affects right bound. If string, both sides are affected. Possible options: "dirichlet", nothing

Fields

  • a::Real – beginning of the support, matches the first element of the array knots
  • b::Real – end of the support, matches the last element of the array knots
  • knots::AbstractVector{<:Real} – array of points on which the spline is built
  • basis_functions::AbstractVector – array of basis functions
source

Legendre polynomials basis

Legendre polynomials basis with length $n$.

LegendreBasis(a::Real, b::Real, n::Int)

a, b – the beginning and the end of the support n – number of basis functions

Fields

  • a::Real – beginning of the support
  • b::Real – end of the support
  • basis_functions::AbstractVector{BaseFunction} – array of basis functions
source

Bernstein polynomials basis

Bernstein polynomials basis.

BernsteinBasis(
    a::Real, b::Real, n::Int,
    boundary_condition::Union{Tuple{Union{String, Nothing}, Union{String, Nothing}}, Nothing, String}=nothing
    )

a, b – the beginning and the end of the segment n – number of basis functions boundary_condition – boundary conditions of basis functions. If tuple, the first element affects left bound, the second element affects right bound. If string, both sides are affected. Possible options: "dirichlet", nothing.

Fields

  • a::Real – beginning of the support
  • b::Real – end of the support
  • basis_functions::AbstractVector{Function} – array of basis functions
  • boundary_condition::Tuple{Union{String, Nothing}, Union{String, Nothing}} – boundary conditions of basis functions. Possible options: "dirichlet", nothing.
source

Parameters of reconstruction algorithm

Regularization parameters

Abstract type for all algorithms for choosing regularization parameters

source

$alphas = argmax(P(alphas|f))$ Mode of the distribution is found by sampling using BAT.jl

ArgmaxBAT(alphas::Union{AbstractVector{<:Real}, Nothing}=nothing,
lower::Union{AbstractVector{<:Real}, Nothing}=nothing,
higher::Union{AbstractVector{<:Real}, Nothing}=nothing,
initial::Union{AbstractVector{<:Real}, Nothing}=nothing,
algo::MCMCAlgorithm=MetropolisHastings(),
nchains::Int=2,
nsamples::Int=1e4,
)

Fields

  • alphas::Union{AbstractVector{<:Real}, Nothing} – values of regularization parameters
  • lower::Union{AbstractVector{<:Real}, Nothing} – lower possible values of regularization parameters
  • higher::Union{AbstractVector{<:Real}, Nothing} – higher possible values of regularization parameters
  • initial::Union{AbstractVector{<:Real}, Nothing} – initial values of regularization parameters
  • algo::MCMCAlgorithm – algorithm of sampling (for more info see BAT.jl documentation)
  • nchains::Int – number of chains to sample
  • nsamples::Int – number of samples
source

$alphas = argmax(P(alphas|f))$ Mode of the distribution is found by sampling using Optim.jl

ArgmaxOptim(alphas::Union{AbstractVector{<:Real}, Nothing}=nothing,
lower::Union{AbstractVector{<:Real}, Nothing}=nothing,
higher::Union{AbstractVector{<:Real}, Nothing}=nothing,
initial::Union{AbstractVector{<:Real}, Nothing}=nothing,
algo=BFGS()
)

Fields

  • alphas::Union{AbstractVector{<:Real}, Nothing} – values of regularization parameters
  • lower::Union{AbstractVector{<:Real}, Nothing} – lower possible values of regularization parameters
  • higher::Union{AbstractVector{<:Real}, Nothing} – higher possible values of regularization parameters
  • initial::Union{AbstractVector{<:Real}, Nothing} – initial values of regularization parameters
  • algo – algorithm of optimization (for more info see Optim.jl documentation)
source

Allows to compute $\varphi$ averaging over all parameters

Marginalize()

Fields

  • alphas::Nothing – no fixed regularization parameters
source

User-defined parameters

User(alphas::AbstractVector{<:Real})

Fields

  • alphas::AbstractVector{<:Real} – fixed regularization parameters
source

Reconstruction algorithms

Abstract type for all solution algorithms

source

Analytical solution

Analytically()

Fields no fields

source

Solve with BATSampling

BATSampling(log_data_distribution::Union{Function, Nothing}=nothing,
algo::MCMCAlgorithm=MetropolisHastings(),
nchains::Int=2,
nsamples::Int=1e4
)

Fields

  • log_data_distribution::Union{Function, Nothing} – logarithm of data distribution
  • algo::MCMCAlgorithm – algorithm foe sampling (foe more info see BAT.jlj documentation)
  • nchains::Int – number of chains to sample
  • nsamples::Int – number of samples
source

Solve with AHMCSampling

AHMCSampling(log_data_distribution::Union{Function, Nothing}=nothing,
nchains::Int=1,
nsamples::Int=1e4
)

Fields

  • log_data_distribution::Union{Function, Nothing} – logarithm of data distribution
  • nchains::Int – number of chains to sample
  • nsamples::Int – number of samples
source

Solve with DHMCSampling

DHMCSampling(log_data_distribution::Union{Function, Nothing}=nothing,
nchains::Int=1,
nsamples::Int=1e4
)

Fields

  • log_data_distribution::Union{Function, Nothing} – logarithm of data distribution
  • nchains::Int – number of chains to sample
  • nsamples::Int – number of samples
source

Reconstruction

Main.TurchinReg.solveFunction.

Solve the problem

solve(
    basis::Basis,
    data::Union{AbstractVector{<:Real}, Function},
    data_errors::Union{AbstractVecOrMat{<:Real}, Function},
    kernel::Union{Function, AbstractMatrix{<:Real}},
    measurement_points::Union{AbstractVector{<:Real}, Nothing}=nothing,
    algo::AlgoType=Analytically(),
    alphas::AlphasType=ArgmaxBAT(),
    omegas::Union{Array{Array{T, 2}, 1}, Nothing} where T<:Real = nothing,
    phi_bounds::PhiBounds=PhiBounds(),
    )
source

Result

Constructs solution function by coefficients, basis and errors.

PhiVec(coeff::Array{<:Real}, basis::Basis, errors::Array{<:Real})
PhiVec(coeff::Array{<:Real}, basis::Basis)
PhiVec(result::Dict{String, Array{<:Real}}, basis::Basis)

Fields

  • coeff::Array{<:Real} – coefficients of decomposition of a function in basis
  • basis::Basis – basis
  • errors::Union{Array{<:Real}, Nothing} – coefficients of decomposition of a function errors in basis
  • solution_function(x::Real)::Function – returns constructed function's value at given point
  • error_function(x::Real)::Union{Function, Nothing} – returns constructed function's error at given point, if errors are specified, otherwise is nothing
  • alphas::Union{AbstractVector{<:Real}, Nothing} – list of regularization parameters
source