BridgeLandmarks.jl
BridgeLandmarks.GuidRecursions
BridgeLandmarks.GuidedProposal
BridgeLandmarks.Landmarks
BridgeLandmarks.LandmarksAux
BridgeLandmarks.LandmarksAux
BridgeLandmarks.MarslandShardlow
BridgeLandmarks.MarslandShardlowAux
BridgeLandmarks.MarslandShardlowAux
BridgeLandmarks.ObsInfo
BridgeLandmarks.Pars_ahs
BridgeLandmarks.Pars_ms
Base.:*
Base.:*
Base.conj!
Base.show
Bridge.B
Bridge.B
Bridge.B!
Bridge.B!
Bridge._b!
Bridge.a
Bridge.a!
Bridge.auxiliary
Bridge.auxiliary
Bridge.b!
Bridge.b!
Bridge.b!
Bridge.b!
Bridge.constdiff
Bridge.target
Bridge.σ!
Bridge.σ!
Bridge.σ!
Bridge.σ!
BridgeLandmarks.HMC
BridgeLandmarks.K̄
BridgeLandmarks._r!
BridgeLandmarks.adapt_pospar_step
BridgeLandmarks.adaptpcnstep
BridgeLandmarks.adjust_to_newpars
BridgeLandmarks.amul
BridgeLandmarks.amul
BridgeLandmarks.amul
BridgeLandmarks.cholinverse!
BridgeLandmarks.construct_gp_xobsT
BridgeLandmarks.construct_nfs
BridgeLandmarks.convert_samplepath
BridgeLandmarks.convert_samplepath
BridgeLandmarks.copypaths!
BridgeLandmarks.deepvalue
BridgeLandmarks.deepvalue
BridgeLandmarks.extract_initial_and_endstate
BridgeLandmarks.getpars
BridgeLandmarks.gp!
BridgeLandmarks.gp!
BridgeLandmarks.gp!
BridgeLandmarks.gp_update!
BridgeLandmarks.gram_matrix
BridgeLandmarks.gram_matrix!
BridgeLandmarks.gramkernel
BridgeLandmarks.guidingbackwards!
BridgeLandmarks.hamiltonian
BridgeLandmarks.hamiltonian
BridgeLandmarks.kernel
BridgeLandmarks.landmarksforward
BridgeLandmarks.landmarksmatching
BridgeLandmarks.landmarksmatching
BridgeLandmarks.lm_mcmc
BridgeLandmarks.lyapunovpsdbackward_step!
BridgeLandmarks.lρtilde
BridgeLandmarks.merge_state
BridgeLandmarks.onemask
BridgeLandmarks.set_guidrec
BridgeLandmarks.set_obsinfo
BridgeLandmarks.show_updates
BridgeLandmarks.slogρ!
BridgeLandmarks.slogρ_mom!
BridgeLandmarks.slogρ_pos!
BridgeLandmarks.split_state
BridgeLandmarks.tame
BridgeLandmarks.template_estimation
BridgeLandmarks.template_estimation
BridgeLandmarks.trun
BridgeLandmarks.update_cyclicmatching
BridgeLandmarks.update_guidrec!
BridgeLandmarks.update_initialstate!
BridgeLandmarks.update_mT!
BridgeLandmarks.update_pars!
BridgeLandmarks.update_path!
BridgeLandmarks.write_acc
BridgeLandmarks.write_info
BridgeLandmarks.write_initendstates
BridgeLandmarks.write_mcmc_iterates
BridgeLandmarks.write_noisefields
BridgeLandmarks.write_observations
BridgeLandmarks.write_params
BridgeLandmarks.z
BridgeLandmarks.σp
BridgeLandmarks.σq
BridgeLandmarks.σq
BridgeLandmarks.σt!
BridgeLandmarks.σt!
BridgeLandmarks.σtmul
BridgeLandmarks.σ̃
BridgeLandmarks.σ̃
BridgeLandmarks.∇K̄
BridgeLandmarks.∇K̄
BridgeLandmarks.∇kernel
BridgeLandmarks.∇kernel
BridgeLandmarks.∇z
BridgeLandmarks.Landmarks
— Type.Landmarks{S,T} <: ContinuousTimeProcess{State{PointF}}
Arguments
a
: Hamiltonian kernel parameterc
: kernel multiplicate parametern
:: Int64 number of landmarksdb
::Float64 square domain bound used for construction of noise fieldsnfstd
: standard deviation of noisefields (assumed to be the same for all noisefields)nfs
: vector of noisefields
BridgeLandmarks.LandmarksAux
— Type.LandmarksAux{S,T} <: ContinuousTimeProcess{State{PointF}}
Arguments
a
: Hamiltonian kernel parameterc
: kernel multiplicate parameterxT
: State at time T used for constructing the auxiliary processn
: number of landmarksnfs
: vector of noisefields
BridgeLandmarks.LandmarksAux
— Method.LandmarksAux(P::Landmarks, xT, gramT) = LandmarksAux(P.a,P.c, xT, P.n, P.nfs, gramT)
BridgeLandmarks.MarslandShardlow
— Type.MarslandShardlow{T} <: ContinuousTimeProcess{State{PointF}}
Arguments
a
: Hamiltonian kernel parameterc
: kernel multiplicate parameterγ
: noise levelλ
: mean reversion parameter (heath-bath parameter in Marsland-Shardlow (2017))n
: number of landmarks
MarslandShardlowAux{S,T} <: ContinuousTimeProcess{State{PointF}}
Arguments
a
: Hamiltonian kernel parameterc
: kernel multiplicate parameterγ
: noise levelλ
: mean reversion parameter (heath-bath parameter in Marsland-Shardlow (2017))xT
: State at time T used for constructing the auxiliary processn
: number of landmarksgramT
: Gram-matrix at xT
BridgeLandmarks.MarslandShardlowAux
— Method.MarslandShardlowAux(P::MarslandShardlow, xT, gramT) = MarslandShardlowAux(P.a,P.c, P.γ, P.λ, xT, P.n, gramT)
BridgeLandmarks.Pars_ahs
— Type.struct summarising settings for updates on mcmc algorithm.
Besides initial values for (c,γ), the values that are most likely to require adjustments are covθprop
, δpos
, δmom
, stdev
, db
ρlowerbound
: lower bound for ρ, this is a a number in [0,1). Wiener innovations are updated according to Wnew = ρinit * Wold + sqrt(1-ρinit^2) * Wind where Wind is an independnet Wiener process. At each iteration, ρ is sampled uniformly on [ρlowerbound, 1]η
: Stepsize cooling function for the adaptation to ensure diminishing adaptation.
Set at n -> min(0.1, 1.0/√n)
adaptskip
: to define guided proposals, we need to plug-in a momentum vector at time T. This is unobserved, and by default initialised as the zero vector. Now everyadaptskip
iterations,mT
is updated to the value obtained in that iteration. In addition, everyadaptskip
iterations, adaptive tuning of mcmc
parameters is performed.
σobs
: If covariance matrix of extrinsic noise is not specified, then it is set to σobs^2*Idt
: mesh width using for discretisation (the mesh always gets transformed by a time-change s -> s*(2-s))cinit
, : initial value forc
. Note that we assume Hamltonain kernel x -> c exp(-|x|^2/(2a^2))γinit
: initial value forgamma
which quantifies the amount of intrinsic noise.aprior
: prior ona
cprior
: prior onc
γprior
: prior onγ
stdev
: For the AHS-model we take noise fields centred at points that are both horizontally and vertically separaeted by a distance that is an integer multiple of 2stdev
db
: assign noisefields within the box [-db[1], db[1]] x -db[2], db[2]κ
: in case of landmarksmatching, κ quantifies diffusiveness of the prior on the initial momentaδpos
: stepsize for updating intial positions. Note that the value of δpos is adapted during mcmc-iterations.δmom
: stepsize for updating intial momenta. Note that the value of δmom is adapted during mcmc-iterations.skip_saveITER
: skip every skip_saveITER iteration in saving paths
BridgeLandmarks.Pars_ms
— Type.struct summarising settings for updates on mcmc algorithm.
Besides initial values for (c,γ), the values that are most likely to require adjustments are covθprop
, δpos
, δmom
ρlowerbound
: lower bound for ρ, this is a a number in [0,1). Wiener innovations are updated according to Wnew = ρinit * Wold + sqrt(1-ρinit^2) * W_ind
where W_ind is an independnet Wiener process. At each iteration, ρ is sampled uniformly on [ρlowerbound, 1]
η
: Stepsize cooling function for the adaptation to ensure diminishing adaptation.
Set at n -> min(0.1, 1.0/√n)
adaptskip
: to define guided proposals, we need to plug-in a momentum vector at time T. This is unobserved, and by default initialised as the zero vector. Now everyadaptskip
iterations,mT
is updated to the value obtained in that iteration. In addition, everyadaptskip
iterations, adaptive tuning of mcmc
parameters is performed.
σobs
: If covariance matrix of extrinsic noise is not specified, then it is set to σobs^2*Idt
: mesh width using for discretisation (the mesh always gets transformed by a time-change s -> s*(2-s))cinit
, : initial value forc
. Note that we assume Hamltonain kernel x -> c exp(-|x|^2/(2a^2))γinit
: initial value forgamma
which quantifies the amount of intrinsic noise.aprior
: prior ona
cprior
: prior onc
γprior
: prior onγ
κ
: in case of landmarksmatching, κ quantifies diffusiveness of the prior on the initial momentaδpos
: stepsize for updating intial positions. Note that the value of δpos is adapted during mcmc-iterations.δmom
: stepsize for updating intial momenta. Note that the value of δmom is adapted during mcmc-iterations.skip_saveITER
: skip every skip_saveITER iteration in saving paths
BridgeLandmarks.construct_nfs
— Method.construct_nfs(db::Array{Float64,1}, nfstd, γ)
Construct sequence of Noisefields for AHS model db: domainbound. Vector db[1], db[2], where sources are places on square grid specified by (-db[1]:2nfstd:db[1]) x -db[2]:2nfstd:db[2] nfstd: standard deviation of noise fields (the smaller: the more noise fields we use) γ: if set to one, then the value of the noise field on the positions is approximately 1 at all locations in the domain
BridgeLandmarks.gramkernel
— Method.gramkernel(q, P; ϵ = 10^(-12))
Gram matrix for kernel with vector of landmarks given by q::Vector(PointF) ϵ*I is added to avoid numerical problems that destroy PSDness of the Gram matrix
BridgeLandmarks.landmarksforward
— Method.Forward simulate landmarks process specified by P on grid t.
Returns driving motion W and landmarks process X
t: time grid
x0: starting point
P: landmarks specification
BridgeLandmarks.landmarksmatching
— Method.landmarksmatching(
xobs0::Array{PointF},xobsT::Array{PointF};
pars = Pars_ms(),
updatescheme = [:innov, :mala_mom],
ITER = 100,
outdir=@__DIR__,
Σobs = nothing,
ainit = nothing,
printskip=20
)
Arguments
xobs0
: Array of PointF (coordinates of inital shape)xobsT
: Array of PointF (coordinats of shape at time T)
Optional arguments
pars
: eitherpars_ms() or
pars_ahs()` (this selects the model and default parameter values)updatescheme
: array of mcmc updatesITER
: number of iterationsoutdir
: path of directory to which output is writtenΣobs
: If provided, a length two array, where the first (second) element gives an Array{Unc} elements, where each element specifies the covariance of the extrinsic noise for each landmark at time 0 (final time T). If not provided, Σobs is constructed using the value of pars.σobsanit
: Hamiltonian kernel parameter. If not provided, defaults to settingainit = mean(norm.([xobs0[i]-xobs0[i-1] for i in 2:n]))
printskip
: skip every printskip observations in writing output to console
Example:
# prepare some test data
n = 7
xobs0 = [PointF(2.0cos(t), sin(t))/4.0 for t in collect(0:(2pi/n):2pi)[2:end]]
θ, ψ = π/6, 0.1
rot = SMatrix{2,2}(cos(θ), sin(θ), -sin(θ), cos(θ))
stretch = SMatrix{2,2}(1.0 + ψ, 0.0, 0.0, 1.0 - ψ)
shift = [0.5, -1.0]
xobsT = [rot * stretch * xobs0[i] + shift for i in 1:n]
landmarksmatching(xobs0,xobsT; ITER=10)
landmarksmatching(xobs0,xobsT; ITER=10, pars=BL.Pars_ahs())
BridgeLandmarks.landmarksmatching
— Method.landmarksmatching(
landmarks0::Matrix{Float64},landmarksT::Matrix{Float64};
pars = Pars_ms(),
updatescheme = [:innov, :mala_mom],
ITER = 100,
outdir=@__DIR__,
Σobs = nothing,
ainit = nothing
)
landmarksmatching, where the input does not consist of arrays of points, but both the initial shape and final shape are represented by a matrix. Each row of the matrix gives the coordinates of a landmark.
BridgeLandmarks.lm_mcmc
— Method.(t, obsinfo, mT, P, ITER, subsamples, xinit, pars, priorθ, priormom, updatescheme, outdir, printskip)
This is the main function call for doing either MCMC or SGD for landmark models Backward ODEs used are in terms of the LMμ-parametrisation
Arguments
t
: time gridobsinfo
: struct of typeObsInfo
mT
: vector of momenta at time T used for constructing guiding termP
: target processITER
: number of iterationssubsamples
: vector of indices of iterations that are to be savedxinit
: initial value on state at time 0 (x0
)pars
: tuning pars for updates (see?Pars_ms()
and?Pars_ahs()
for documentation)priorθ
: prior on θ = (a,c,γ)priormom
: prior on initial momentaupdatescheme
: vector specifying mcmc-updatesoutdir
output directory for animationprintskip
skip everyprintskip
iterations in writing output to console
Returns:
Xsave
: saved iterations of all states at all times in tt_parsave
: saved iterations of all parameter updatesinitendstates_save
: saved iterations of initial and endstateaccinfo
: acceptance indicators of mcmc-updatesδ
: value of(δpos, δmom)
af the final iteration of the algorithm (these are stepsize parameters for updating initial positions and momenta respectively)ρ
: value ofρinit
at the final iteration of the algorithmδa
: value ofδa
at the final iteration of the algorithm (step size for updating Hamiltonian kernel parametera
)
BridgeLandmarks.show_updates
— Method.show_updates()
Convenience function to show the available implemted updates.
BridgeLandmarks.template_estimation
— Method.template_estimation(
xobsT::Array{PointF};
pars = Pars_ms(),
updatescheme = [:innov, :rmmala_pos, :parameter],
ITER = 100,
outdir=@__DIR__,
Σobs = nothing,
ainit = nothing
xinitq = nothing
)
Arguments
xobsT
: an array, where each element of the array gives the coordinates of a shape (i.e. the landmarks, which
are represented as an array of PointF)
Optional arguments
pars
: eitherpars_ms()
or
pars_ahs()`` (this selects the model and default parameter values)updatescheme
: array of mcmc updatesITER
: number of iterationsoutdir
: path of directory to which output is writtenΣobs
: If provided, a length two array, where the first (second) element gives an Array{Unc} elements, where each element specifies the covariance of the extrinsic noise for each landmark at time 0 (final time T). If not provided, Σobs is constructed using the value of pars.σobsanit
: Hamiltonian kernel parameter. If not provided, defaults to settingainit = mean(norm.([xobs0[i]-xobs0[i-1] for i in 2:n]))
xinitq::Array{PointF}
: Initialisation for the shape. If not provided xobsT[1] will be taken for initialisation.printskip
: skip every printskip observations in writing output to console
Example:
``` # Make test example data set n = 5 nshapes = 7 q0 = [PointF(2.0cos(t), sin(t)) for t in collect(0:(2pi/n):2pi)[2:end]] # initial shape is an ellipse x0 = State(q0, randn(PointF,n)) xobsT = Vector{PointF}[]
T = 1.0; dt = 0.01; t = 0.0:dt:T
Ptrue = MarslandShardlow(2.0, 0.1, 1.7, 0.0, n)
for k in 1:nshapes
Wf, Xf = BridgeLandmarks.landmarksforward(t, x0, Ptrue)
push!(xobsT, Xf.yy[end].q + σobs * randn(PointF,n))
end
template_estimation(xobsT)
`
BridgeLandmarks.template_estimation
— Method.template_estimation(
landmarksT::Array{Matrix{Float64}};
pars = Pars_ms(),
updatescheme = [:innov, :mala_mom],
ITER = 100,
outdir=@__DIR__,
Σobs = nothing,
ainit = nothing
)
BridgeLandmarks.GuidRecursions
— Type.GuidRecursions{TL,TM⁺,TM, Tμ, TH, TLt0, TMt⁺0, Tμt0}
GuidRecursions defines a struct that contains all info required for computing the guiding term and likelihood (including ptilde term) for a single shape
Arguments
Suppose t is the specified (fixed) time grid. Then the elements of the struct are:
Lt
: matrices LMt⁺
`: matrices M⁺ (inverses of M)M
: matrices Mμ
`: vectors μHt
: matrices H, where H = L' M LLt0
: L(0) (so obtained from L(0+) after gpupdate step incorporating observation xobs0)Mt⁺0
: M⁺(0) (so obtained from M⁺(0+) after gpupdate step incorporating observation xobs0)μt0
: μ(0) (so obtained μ(0+) after gpupdate step incorporating observation xobs0)
BridgeLandmarks.GuidedProposal
— Type.GuidedProposal{T,Ttarget,Taux,TL,Txobs0,TxobsT,Tnshapes,TmT,F} <: ContinuousTimeProcess{T}
struct that contains target, auxiliary process for each shape, time grid, observation at time 0, observations at time T, number of shapes, and momenta in final state used for constructing the auxiliary processes guidrec
is a vector of GuidRecursions, which contains the results from the backward recursions and gpupdate step at time zero
Arguments
target::Ttarget # target diffusion P
aux::Vector{Taux} # auxiliary diffusion for each shape (Ptilde for each shape)
tt::Vector{Float64} # grid of time points on single segment (S,T]
xobs0::Txobs0 # observation at time 0
xobsT::Vector{TelxobsT} # vector of observations at time T
guidrec::Vector{TL} # guided recursions on grid tt
nshapes::Int64 # number of shapes
mT::Vector{TmT} # vector of artificial momenta used for constructing auxiliary process (one for each shape)
endpoint::F
Example (for landmarksmatching)
n = 5
P = MarslandShardlow(1.0, 2.0, 0.5, 0.0, n)
xT = State(rand(PointF,n),rand(PointF,n))
Paux = [BridgeLandmarks.auxiliary(P,xT)]
tt = collect(0:0.05:1.0)
xobs0 = rand(PointF,n)
xobsT = [rand(PointF,n)]
σobs = 0.01
Σobs = fill([σobs^2 * one(UncF) for i in 1:n],2)
obsinfo = BridgeLandmarks.set_obsinfo(xobs0,xobsT,Σobs, true,false)
gr = [BridgeLandmarks.init_guidrec(tt,obsinfo)]
nshapes = 1
mT = [rand(PointF,n)]
Q = BridgeLandmarks.GuidedProposal(P,Paux,tt,xobs0,xobsT,gr,nshapes,mT)
BridgeLandmarks.ObsInfo
— Type.struct containing information on the observations
We assue observations V0 and VT, where
- V0 = L0 * X0 + N(0,Σ0)
- VT = LT * X0 + N(0,ΣT)
In addition, μT is a vector of zeros (for initialising the backward ODE on μ) (possibly remove later)
Base.:*
— Method.Base.:*(H::InverseCholesky, X)
Compute y = HX where Hinv = LL' (Cholesky decomposition
Input are L and X, output is Y
y = H X is equivalent to LL'y = X, which can be solved by first backsolving LZ=X for z and next backsolving L'Y = Z
L is a lower triangular matrix with element of type UncMat X is a matrix with elements of type UncMat Returns a matrix with elements of type UncMat
Base.:*
— Method.Base.:*(H::InverseCholesky, x::State)
Compute y = Hx where Hinv = LL' (Cholesky decomposition
Input are L and x, output is y
y=Hx is equivalent to LL'y=x, which can be solved by first backsolving Lz=x for z and next backsolving L'y=z
L is a lower triangular matrix with element of type UncMat x is a State or vector of points Returns a State (Todo: split up again and return vector for vector input)
Base.conj!
— Method.Compute transpose of square matrix of Unc matrices
A = reshape([Unc(1:4), Unc(5:8), Unc(9:12), Unc(13:16)],2,2) B = copy(A) A conj!(B)
Base.show
— Method.Base.show(io::IO, state::State)
Good display of variable of type State
Bridge.B!
— Method.Bridge.B!(t,X,out, Paux::LandmarksAux, xT)
Compute B̃(t) * X (B̃ from auxiliary process) and write to out Both B̃(t) and X are of type UncMat
Bridge.B!
— Method.Bridge.B!(t,X,out, Paux::MarslandShardlowAux)
Compute B̃(t) * X (B̃ from auxiliary process) and write to out Both B̃(t) and X are of type UncMat
Bridge.B
— Method.Bridge.B(t, Paux::LandmarksAux, xT)
Compute tildeB(t) for landmarks auxiliary process
Bridge.B
— Method.Bridge.B(t, Paux::MarslandShardlowAux)
Compute tildeB(t) for landmarks auxiliary process
Bridge._b!
— Method._b!((i,t), x::State, out::State, Q::GuidedProposal,k)
Evaluate drift bᵒ of guided proposal at (t,x), write into out
Bridge.a!
— Method.Bridge.a!(t, x_, out, P::Union{Landmarks,LandmarksAux})
Bridge.a
— Method.Bridge.a(t, P::Union{MarslandShardlow, MarslandShardlowAux})
Returns matrix a(t) for Marsland-Shardlow model
Bridge.auxiliary
— Method.auxiliary(Q::GuidedProposal,k::Int64) = Q.aux[k]
Extract auxiliary process of k-th shape.
Bridge.auxiliary
— Method.auxiliary(P::Union{MarslandShardlow, Landmarks}, xT, gramT)
Construct auxiliary process corresponding to P
and xT
Bridge.b!
— Method.Bridge.b!(t, x, out, Paux::LandmarksAux)
Evaluate drift of landmarks auxiliary process in (t,x) and save to out x is a state and out as well
Bridge.b!
— Method.Evaluate drift of landmarks in (t,x) and save to out x is a state and out as well
Bridge.b!
— Method.Bridge.b!(t, x, out, Paux::MarslandShardlowAux)
Evaluate drift of landmarks auxiliary process in (t,x) and save to out x is a state and out as well
Bridge.b!
— Method.Bridge.b!(t, x, out, P::MarslandShardlow)
Evaluate drift of landmarks in (t,x) and save to out x is a state and out as well
Bridge.constdiff
— Method.constdiff(Q::GuidedProposal)
If true, both the target and auxiliary process have constant diffusion coefficient.
Bridge.target
— Method.target(Q::GuidedProposal) = Q.target
Bridge.σ!
— Method.σ!(t, x, dw, out, Q::GuidedProposal)
Evaluate σ(t,x) dw and write into out
Bridge.σ!
— Method.Bridge.σ!(t, x_, dm, out, P::Union{Landmarks,LandmarksAux})
Compute sigma(t,x) * dm where dm is a vector and sigma is the diffusion coefficient of landmarks write to out which is of type State
Bridge.σ!
— Method.Bridge.σ!(t, x, dm, out, P::MarslandShardlowAux, xT)
Compute σ(t,x) * dm and write to out
Bridge.σ!
— Method.Bridge.σ!(t, x, dm, out, P::MarslandShardlow)
Compute σ(t,x) * dm and write to out
BridgeLandmarks.HMC
— Method.Adapting Radford Neal's R implementation of Hamiltonian Monte Carlo with
stepsize ϵ and L steps
BridgeLandmarks.K̄
— Method.K̄(q,τ)
K̄(q,τ) = exp(-Bridge.inner(q)/(2*τ^2)) Kernel for noisefields of AHS-model
BridgeLandmarks._r!
— Method._r!((i,t), x::State, out::State, Q::GuidedProposal,k)
Evaluate tilde_r (appearing in guiding term of guided proposal) at (t,x), write into out
BridgeLandmarks.adapt_pospar_step
— Method.adapt_pospar_step!(δ, n, accinfo, η, update; adaptskip = 15, targetaccept=0.5)
Adapt the step size for updates, where tuning par has to be positive. The adaptation is multiplication/divsion by exp(η(n)).
BridgeLandmarks.adaptpcnstep
— Method.adaptpcnstep(n, accpcn, ρ, nshapes, η; adaptskip = 15, targetaccept=0.5)
Adjust pcN-parameter ρ
adaptive every adaptskip
steps. For that ρ
is first tranformed to (-∞, ∞), then updated, then mapped back to (0,1)
BridgeLandmarks.adjust_to_newpars
— Method.adjust_to_newpars(Q::GuidedProposal,(aᵒ,cᵒ,γᵒ),obsinfo)
Provide new parameter values for GuidedProposal Q
, these are written into fields target
and aux
. Returns a new instance of GuidedProposal
, adjusted to the new set of parameters.
BridgeLandmarks.amul
— Method.Multiply a(t,x) times a state Returns a state (first multiply with sigma', via function σtmul, next left-multiply this vector with σ)
BridgeLandmarks.amul
— Method.amul(t, x::State, xin::State, P::Union{MarslandShardlow, MarslandShardlowAux})
Multiply a(t,x) times xin (which is of type state) Returns variable of type State
BridgeLandmarks.amul
— Method.amul(t, x::State, xin::Vector{<:Point}, P::Union{Landmarks,LandmarksAux})
Multiply a(t,x) times a vector of points Returns a State (first multiply with sigma', via function σtmul, next left-multiply this vector with σ)
BridgeLandmarks.cholinverse!
— Method.cholinverse!(L, x)
Solve L L'y =x using two backsolves, L should be lower triangular
BridgeLandmarks.construct_gp_xobsT
— Method.construct_gp_xobsT(Q, xobsTᵒ)
Update xobsTᵒ into auxiliary process of Q, following by recomputing the backwards ODEs
BridgeLandmarks.convert_samplepath
— Method.convert_samplepath(X)
Useful for storage of a samplepath of states Ordering is as follows:
- time
- landmark nr
- for each landmark: q1, q2 p1, p2
With m time-steps, n landmarks, this entails a vector of length m * n * 2 * d
BridgeLandmarks.convert_samplepath
— Method.convert_samplepath(Xvec::Vector)
Useful for storage of a samplepath of states Ordering is as follows:
- shape
- time
- landmark nr
- for each landmark: q1, q2 p1, p2
With m time-steps, n landmarks, this entails a vector of length m * n * 2 * d
BridgeLandmarks.copypaths!
— Method.function copypaths!(X,Xᵒ)
Write Xᵒ into X
BridgeLandmarks.deepvalue
— Method.deepvalue(x)
If x
is a vector of Float64, x
is returned. If x
is a vector of Dual-numbers, its Float64 part is returned.
BridgeLandmarks.deepvalue
— Method.deepvalue(x::State)
Extract Float64 part of elements in State (so in case of Dual numbers, derivative part is dropped)
extract_initial_and_endstate(iteratenr::Int64, Xpath)
Extract from a sample path its states at time zero and time T (endtime)
iteratnr:: integer that indicates iteration.nr in mcmc-algorithm Xpath:: Bridge.Samplepath
Returns a matrix with first column iteratenr repeated, second column state at time zero, third column state a time T
The second and third column as ordered as follows (in case of two dimensional landmarks): landmark 1 pos1 landmark 1 pos2 landmark 1 mom1 landmark 1 mom2
landmark 2 pos1 landmark 2 pos2 landmark 2 mom1 landmark 2 mom2
...
BridgeLandmarks.getpars
— Method.getpars(Q::GuidedProposal)
Extract parameters from GuidedProposal Q
, that is, (a,c,γ)
`
BridgeLandmarks.gp!
— Function.gp!(::LeftRule, Xᵒ, x0, W, Q::GuidedProposal,k; skip = sk, ll0 = true)
Simulate guided proposal as specified in Q
and compute loglikelihood for one shape, starting from x0
, using Wiener increments W
Write into
Xᵒ
Returns
logliklihood.
BridgeLandmarks.gp!
— Method.gp!(::LeftRule, X::Vector, q, p , W, Q::GuidedProposal; skip = sk, ll0 = true)
Simulate guided proposal and compute loglikelihood (vector version, multiple shapes) q
and p
make up a state (could in fact be turned into the intial state by merge_state(q,p)
)
BridgeLandmarks.gp!
— Method.gp!(::LeftRule, X, x0, W, Q::GuidedProposal; skip = sk, ll0 = true)
Simulate guided proposal and compute loglikelihood (vector version, multiple shapes) x0
is assumed to be of type State
BridgeLandmarks.gp_update!
— Method.gp_update!(Lt0₊, Mt⁺0₊::Array{Pnt,2}, μt0₊, (L0, Σ0, xobs0), Lt0, Mt⁺0, μt0) where Pnt
Guided proposal update for newly incoming observation at time zero. Information on new observations at time zero is (L0, Σ0, xobs0)
Values just after time zero, (Lt0₊, Mt⁺0₊, μt0₊)
are updated to time zero, the result being written into (Lt0, Mt⁺0, μt0)
BridgeLandmarks.gram_matrix!
— Method.gram_matrix!(out, q, P)
Write into out the Gram matrix for kernel with vector of landmarks given by q::Vector(PointF)
BridgeLandmarks.gram_matrix
— Method.gram_matrix(q, P)
Gram matrix for kernel with vector of landmarks given by q::Vector(PointF)
BridgeLandmarks.guidingbackwards!
— Method.guidingbackwards!(::Lm, t, (Lt, Mt⁺, μt), Paux, obsinfo; implicit=true, lowrank=false)
Solve backwards recursions in L, M, μ parametrisation on grid t
Arguments
t
: time grid(Lt, Mt⁺, μt)
: containers to write the solutions intoPaux
: auxiliary processobsinfo
: of type ObsInfo containing information on the observationsimplicit
: if true an implicit Euler backwards scheme is used (else explicit forward)
Case lowrank=true
still gives an error: fixme!
BridgeLandmarks.hamiltonian
— Method.hamiltonian(x, P)
Hamiltonian for deterministic part of landmarks model
BridgeLandmarks.hamiltonian
— Method.hamiltonian(x::NState, P::MarslandShardlow)
Returns Hamiltonian at x
for deterministic system (no Wiener noise)
BridgeLandmarks.kernel
— Method.kernel(q, P::LandmarkModel)
kernel in Hamiltonian: P.c * exp(-Bridge.inner(q)/(2*P.a^2))
Version where B̃ and ã do not depend on try
BridgeLandmarks.lρtilde
— Method.lρtilde(x0, Q,k)
Compute log ρ̃(0,x_0,k), where k indexes shape
BridgeLandmarks.merge_state
— Method.merge_state(q,p)
Merge q
and p
parts of state to an element of type NState
.
Note that merge does the inverse operation
Example
y = State(rand(PointF,3),rand(PointF,3))
q, p = split_state(y)
yy = merge_state(q,p)
yy-y
BridgeLandmarks.onemask
— Method.onemask(x::Number) = one(x)
BridgeLandmarks.set_guidrec
— Method.set_guidrec(Q::GuidedProposal, gr) = GuidedProposal(Q.target, Q.aux, X.tt, Q.xobs, Q.xobsT, gr,Q.nshapes, Q.endpoint)
Update guidrec
field of Q to gr
BridgeLandmarks.set_obsinfo
— Method.set_obsinfo(xobs0,xobsT,Σobs, obs_atzero::Bool,fixinitmomentato0::Bool)
Constructor for ObsInfo.
Arguments
n
: number of landmarksobs_atzero
: Boolean, if true, the initial configuration is observedfixinitmomenta0
: Boolean, if true, the initial momenta are fixed to zeroΣobs
: 2-element array where Σobs0 = Σobs[1] and ΣobsT = Σobs[2] Both Σobs0 and ΣobsT are arrays of length n of type UncF that give the observation covariance matrix on each landmarkxobs0
: in case obs_atzero=true, it is provided and passed through; in other cases it is constructed such that the backward ODEs are initialised correctly.
Note that there are three cases:
obs_atzero=true
: this refers to the case of observing one landmark configuration at times 0 and Tobs_atzero=false & fixinitmomentato0=false
: case of observing multiple shapes at time T, both positions and momenta at time zero assumed unknownobs_atzero=false & fixinitmomentato0=true
: case of observing multiple shapes at time T, positions at time zero assumed unknown, momenta at time 0 are fixed to zero
BridgeLandmarks.slogρ!
— Method.slogρ!(q, p, Q, W, X, priormom,llout)
Main use of this function is to get gradient information of the loglikelihood with respect ot the initial state.
Arguments
q
andp
make up the initial state (which could be obtained fromx0 = merge_state(q,p)
)Q
: GuidePropsoal!W
: vector of innovationsX
: sample pathpriormom
: prior on the initial momentallout
: vector where loglikelihoods for each shape are written into
Writes into
- The guided proposal is written into
X
. - The computed loglikelihood for each shape is written into
llout
Returns
- loglikelihood (summed over all shapes) + the logpriordensity of the initial momenta
BridgeLandmarks.slogρ_mom!
— Method.slogρ_mom!(q, Q, W, X,priormom, llout) = (p) -> slogρ!(q, p , Q, W, X, priormom, llout)
BridgeLandmarks.slogρ_pos!
— Method.slogρ_pos!(p, Q, W, X,priormom, llout) = (q) -> slogρ!(q, p , Q, W, X, priormom, llout)
BridgeLandmarks.split_state
— Method.split_state(x::NState)
Split a state into its q
and p
parts, where the latter are reinterpreted as vectors.
Note that merge does the inverse operation
Example
y = State(rand(PointF,3),rand(PointF,3))
q, p = split_state(y)
yy = merge_state(q,p)
yy-y
BridgeLandmarks.tame
— Method.tame(x) = x/(I + norm(x))
Useful for tamed version of Langevin algorithm
BridgeLandmarks.trun
— Method.trun(x,h) = x/max(1.0,0.5*h*norm(x))
useful function for truncated version of mala
BridgeLandmarks.update_cyclicmatching
— Method.update_cyclicmatching(X, ll,obs_info, Xᵒ, W, Q)
writes into / modifies
X
ll
Returns
Q
, obsinfo
, accept
BridgeLandmarks.update_guidrec!
— Method.update_guidrec!(Q, obsinfo)
Q::GuidedProposal obsinfo::ObsInfo
Computes backwards recursion for (L,M⁺,μ), including gp-update step at time 0. Next, the guidrec
field or Q
is updated. Returns Q
.
BridgeLandmarks.update_initialstate!
— Method.update_initialstate!(X,Xᵒ,W,ll,x,xᵒ,∇, ∇ᵒ, Q::GuidedProposal, δ, update,priormom, (dK, inv_dK), At)
Arguments
X
: current iterate of vector of sample pathsXᵒ
: vector of sample paths to write proposal intoW
: current vector of Wiener incrementsll
: current value of loglikelihoodx
,xᵒ
,∇x
,∇xᵒ
: allocated vectors for initial state and its gradient (both actual and proposed values)sampler
: either sgd (not checked yet) or mcmcQ
: GuidedProposalδ
: vector with MALA stepsize for initial state positions (δ[1]) and initial state momenta (δ[2])update
: can be:mala_pos
,:mala_mom
, :rmmalapos,
:rmmalamom,
:rmrw_mom
priormom
: prior on initial momenta- (dK, inv_dK): gramkernel at x0.q and its inverse
Writes into / modifies
X
: landmarks pathsx
: initial state of the landmark paths- `
∇
: gradient of loglikelihood with respect to initial statex
ll
: a vector with as k-th element the loglikelihood for the k-th shape
Returns
- 0/1 indicator (reject/accept)
BridgeLandmarks.update_mT!
— Method.update_mT(Q, mTv, obsinfo)
Update State vector of auxiliary process for each shape. For the k-th shape, the momentum gets replaced with mTv[k]
Example
See documentation for GuidedProposal to contruct an example instance, say Q
```julia mTv = [zeros(PointF,5)]
BridgeLandmarks.update_mT!(Q, mTv, obsinfo)
BridgeLandmarks.update_pars!
— Method.update_pars!(X, Xᵒ,W, Q, x, ll, priorθ, covθprop, obsinfo, At)
For fixed Wiener increments and initial state, update parameters by random-walk-MH.
Writes into / modifies
X
: landmark paths under landmarks process with parameter θ ll
: vector of loglikelihoods (one for each shape)
Returns
Q, accept
: where accept
is 1/0 according to accept/reject in the MH-step.
BridgeLandmarks.update_path!
— Method.update_path!(X,Xᵒ,W,Wᵒ,Wnew,ll,x, Q, ρ)
Update bridges for all shapes using Crank-Nicholsen scheme with parameter ρ
(only in case the method is mcmc). Newly accepted bridges are written into (X,W)
, loglikelihood on each segment is written into vector ll
All Wiener increments are always updated.
Write into
X
: diffusion pathsW
: innovationsll
: vector of loglikehoods (k-th element is for the k-th shape)
BridgeLandmarks.write_acc
— Method.write_acc(accinfo,outdir)
Write dataframe with acceptance numbers of updatesteps to a csv file
BridgeLandmarks.write_info
— Method.Write info to txt file
BridgeLandmarks.write_initendstates
— Method.write_initendstates(initendstates_save)
initendstatessave is an Array of matrices, each matrix corresponding to one iteration, with ordering as specified in `extractinitialandendstate`
BridgeLandmarks.write_mcmc_iterates
— Method.write_mcmc_iterates(Xsave, tt_, n, nshapes, subsamples, outdir)
Write bridge iterates to file
Arguments:
Xsave
: contains values of bridgestt_
: grid on which bridges are simulatedn
: nr of bridgesnshapes
: nr of shapessubsamples
: indices of iterates that are kept and saved in Xsaveoutdir
: output directory
BridgeLandmarks.write_noisefields
— Method.write_noisefields(P,outdir)
Write noisefields to file (empty in case of MS-model)
BridgeLandmarks.write_observations
— Method.write_observations(xobs0, xobsT, n, nshapes, outdir)
Write observations to csv file
BridgeLandmarks.write_params
— Method.write_params(parsave,subsamples,outdir)
Write parameter iterates to file
BridgeLandmarks.z
— Method.Define z(q) = < ∇K̄(q - δ,τ), λ >
Required for Stratonovich -> Ito correction in AHS-model
BridgeLandmarks.σp
— Method.σp(q, p, nf::Noisefield) = -Diagonal(p .* nf.γ .* ∇K̄(q - nf.δ,nf.τ))
Suppose one noise field nf Returns diagonal matrix with noisefield for momentum at point location q (can be vector or Point)
BridgeLandmarks.σq
— Method.σq(q, nf::Noisefield) = Diagonal(nf.γ * K̄(q - nf.δ,nf.τ))
Suppose one noise field nf Returns diagonal matrix with noisefield for position at point location q (can be vector or Point)
BridgeLandmarks.σq
— Method.For AHS model compute total noise field on position experienced at a point x.
Useful for plotting purposes.
Example usage:
σq(Point(0.0, 0.0), nfs)
σq([0.0; 0.0], nfs)
BridgeLandmarks.σt!
— Method.compute σ(t,x)' y, where y::State
the result is a vector of points that is written to out
BridgeLandmarks.σt!
— Method.σt!(t, x_, y::State{Pnt}, out, P::MarslandShardlow) where Pnt
compute σ(t,x)' y, where y::State the result is a vector of points that is written to out
BridgeLandmarks.σtmul
— Method.Compute sigma(t,x)' * y where y is a state and sigma is the diffusion coefficient of landmarks returns a vector of points of length P.nfs
BridgeLandmarks.σ̃
— Method.σ̃(t, Paux::LandmarksAux, xT)
Return matrix σ̃(t) for LandmarksAux
BridgeLandmarks.σ̃
— Method.σ̃(t, P::Union{MarslandShardlow, MarslandShardlowAux})
Return sparse matrix matrix σ̃(t)
BridgeLandmarks.∇K̄
— Method.∇K̄(q, qT, τ)
Needed for b! in case P is auxiliary process
BridgeLandmarks.∇K̄
— Method.∇K̄(q,τ)
Gradient of kernel for noisefields
BridgeLandmarks.∇kernel
— Method.Needed for b! in case P is auxiliary process
BridgeLandmarks.∇kernel
— Method.∇kernel(q, P::LandmarkModel)
gradient of kernel in hamiltonian
BridgeLandmarks.∇z
— Method.Define ∇z(q) = ∇ < ∇K̄(q - δ,τ), λ >
Required for Stratonovich -> Ito correction in AHS-model
A Julia package for stochastic landmarks matching and template estimation. Inference is based on guided proposals and, more specifically, a simple version of the Backward Filtering Forward Guiding (BFFG) algorithm from https://arxiv.org/pdf/1712.03807.pdf. Two stochastic landmarks models are implemented:
- The model by Arnaudon, Holm and Sommer based on stochastic Euler-Poincare equations.
- The model by Trouve and Vialard, which adds a Wiener term to the equation of the momentum of a landmark.
Matching of two landmark configurations
Estimation of a template configuration
Setting parameters
Plotting methods (based on R - ggplot)
Internal details
At each time, the state of the landmarks process is a vector of positions and momenta. Each of such a vector is a Point{Float64}
(with alias PointF
) and hence a State
can be constructed
st = State(rand(PointF),5), rand(PointF,5))
Example
Compute skeleton graph h
with separating sets S
and CPDAG g
from the 47x1190 data set NCI-60 on expression profiles of miRNAs and mRNAs.
```julia using BridgeLandmarks
Performance
Contribution
See
References
- Alain Trouve and Francois-Xavier Vialard. Shape splines and stochastic shape evolutions: A second order point of view. Quarterly of Applied Mathematics, 70(2):219–251, 2012. ISSN 0033-569X, 1552-4485. doi: 10.1090/S0033-569X-2012-01250-4.
- Alexis Arnaudon, Darryl D. Holm, and Stefan Sommer. A Geometric Framework
for Stochastic Shape Analysis. Foundations of Computational Mathematics, 19(3): 653–701, June 2019. ISSN 1615-3383. doi: 10.1007/s10208-018-9394-z.
- M. Mider, M.R. Schauer and F.H. van der Meulen (2020) Continuous-discrete smoothing of diffusions
- A. Arnaudon, F.H. van der Meulen, M.R. Schauer and S. Sommer (2020) Diffusion bridges for stochastic Hamiltonian systems with applications to shape analysis
- J. Bierkens, F.H. van der Meulen and M.R. Schauer (2019) Simulation of elliptic and hypo-elliptic conditional diffusions. To appear in Advances in Applied Probability