pair_align_functions_infHMC: Align two functions using hierarchical Bayesian framework...

View source: R/pair_align_functions_infHMC.R

pair_align_functions_infHMCR Documentation

Align two functions using hierarchical Bayesian framework with infinite-dimensional HMC

Description

This function aligns two functions using a hierarchical Bayesian framework assuming measurement error. It will align f2 to f1. It is based on mapping warping functions to a hypersphere, and a subsequent exponential mapping to a tangent space. In the tangent space, the \infty-dimensional HMC algorithm is used to explore both local and global structure in the posterior distribution.

Usage

pair_align_functions_infHMC(
  f1,
  f2,
  timet,
  iter = 10000,
  burnin = NULL,
  thin = 50,
  nchains = 1,
  alpha0 = 0.1,
  beta0 = 0.1,
  alpha = 1,
  beta = 1,
  h = 0.01,
  L = 4L,
  adapt = TRUE,
  target_accept = 0.65,
  f1propvar = 1e-04,
  f2propvar = 1e-04,
  L1propvar = 0.3,
  L2propvar = 0.3,
  vpriorvar = 1,
  vpriordecay = 1,
  init.coef = rep(0, 20),
  basis = c("fourier", "legendre"),
  warp_rep = c("shooting", "clr"),
  init = c("dp", "coef"),
  sampfreq = 5L,
  extrainfo = FALSE,
  verbose = TRUE
)

Arguments

f1

numeric vector of M samples of function 1

f2

numeric vector of M samples of function 2

timet

time vector of length M

iter

length of the chain

burnin

number of burn-in MCMC iterations; defaults to min(5e3, floor(iter / 2))

thin

thinning of the stored posterior draws

nchains

number of MCMC chains to run

alpha0, beta0

inverse gamma prior parameters for the measurement error variances

alpha, beta

inverse gamma prior parameters for the SRVF model variance

h

the initial HMC step size is sqrt(h) (a rotation angle)

L

maximum number of leapfrog steps

adapt

whether to adapt the HMC step size during burn-in

target_accept

target HMC acceptance rate when adapting

f1propvar, f2propvar

proposal variances for f1 and f2

L1propvar, L2propvar

proposal standard deviations of the Gaussian process length scales of f1 and f2

vpriorvar

prior variance scale of the warping coefficients

vpriordecay

the prior variance of coefficient pair j is vpriorvar / j^vpriordecay

init.coef

initial coefficients of the warping function; length must be even

basis

basis for the warping coefficients, either "fourier" or "legendre"

warp_rep

warping function representation, either "shooting" (the v-transform) or "clr" (the h-transform)

init

where the first chain starts: "dp" at the elastic (dynamic programming) alignment of the smoothed functions, or "coef" at init.coef. Further chains always start at random coefficients. A chain started at the identity can settle in a poor local mode

sampfreq

subsampling frequency used when fitting the initial Gaussian process models to f1 and f2

extrainfo

whether additional information is returned

verbose

whether to show a progress bar

Details

With warp_rep = "shooting", v = \Phi c is a shooting vector at the identity of the Hilbert sphere of SRSFs of warping functions and must satisfy |v| < \pi (draws outside are rejected); with warp_rep = "clr", h = \Phi c is the centered log-derivative, \gamma' = \exp(h) / \int \exp(h), which is unconstrained. The likelihood gradient with respect to c is exact and v is updated with the preconditioned HMC of Beskos et al. (2011). timet is assumed to be uniformly sampled.

Value

Returns a list containing

f1

posterior draws of f_1

f2

posterior draws of f_2

gamma

posterior mean warping function

v_coef

posterior draws of the warping coefficients

psi

posterior mean psi function

sigma

posterior draws of the SRVF model standard deviation

sigma1, sigma2

posterior draws of the measurement error variances

s1, s2

posterior draws of the Gaussian process variances

L1, L2

posterior draws of the Gaussian process length scales

f2_warped_mu

f2 warped by the posterior mean warping function

epsilon

HMC step size at each iteration

theta_accept

acceptance of the warping samples (if extrainfo)

f1_accept, f2_accept

acceptance of the f1, f2 samples (if extrainfo)

L1_accept, L2_accept

acceptance of the length scales (if extrainfo)

gamma_mat

matrix of posterior draws of gamma (if extrainfo)

gamma_stats

pointwise 95% credible band of gamma (if extrainfo)

SSE

SSE of the level 2 likelihood (if extrainfo)

logl

log-likelihood trace (if extrainfo)

f2_warped

posterior draws of the aligned f2 (if extrainfo)

phasedist

posterior draws of the phase distance (if extrainfo)

ampdist

posterior draws of the amplitude distance (if extrainfo)

posterior_gamma_modes

modes of the posterior of gamma, found by clustering the chains (if nchains > 1)

posterior_gamma_modes_cr

credible regions of the modes (if nchains > 1)

References

Tucker, J. D., Shand, L., and Chowdhary, K. (2021). Multimodal Bayesian registration of noisy functions using Hamiltonian Monte Carlo. Computational Statistics and Data Analysis, 163, 107298.

Beskos, A., Pinski, F. J., Sanz-Serna, J. M., and Stuart, A. M. (2011). Hybrid Monte Carlo on Hilbert spaces. Stochastic Processes and their Applications, 121(10), 2201-2230.

Examples

## Not run: 
  # This is an MCMC algorithm and takes a long time to run
  out <- pair_align_functions_infHMC(
    f1 = simu_data$f[, 1],
    f2 = simu_data$f[, 21],
    timet = simu_data$time,
    iter = 1000
  )
  mean(out$theta_accept)

## End(Not run)

fdasrvf documentation built on Nov. 21, 2026, 1:09 a.m.