Functional Alignment¶
The main functions deal with the alignment of functional data using the
square-root slope (srsf) framework. Where an input into a function is
expecting an array of functions the shape is assumed to be (M,N) with M
being the number of sample points and N being the number of functions.
SRSF Functions¶
-
f_to_srsf(f::Array, timet=0, smooth=false)¶ Convert function to square-root slope (srsf) functions
fis an array of shape(M,N)as described above. By default the function will generate timing information, otherwisetimetshould be vector of lengthMdescribing the timing information. Ifsmooth=truethe input data will be smoothed first using smoothing splines.
-
srsf_to_f(q::Array, timet, f0=0.0)¶ Convert srsf to function space
qis an array with the standard shape.timetis a vector of timing infomration.f0is the initial value of the function in f-space, this is required to make the transformation a bijection.
-
smooth_data(f::Array, sparam=10)¶ Smooth functional data using a box filter
fis an array with the standard shape.sparamis the number of times to run the filter.
-
smooth_data!(f::Array, sparam=10) same as smooth_data, except the smoothing is done in-place
-
trapz(x::Vector, y::Array, dim=1)¶ Trapezodial Integration
xis a vector of time samples.yis the reponse anddimis the dimension to integrate along.
-
optimum_reparam(q1, timet, q2, lam=0.0, method="DP", w=0.01, f1o=0.0, f2o=0.0)¶ Calculates the optimum reparamertization (warping) between two srsfs q1 and q2.
q1andq2can be vectors or arrays of the standard shape.timetis a vector describing the time samples.lamcontrols the amount of warping.methodis the optimization method to find the warping. The default is Simultaneous Alignment (“SIMUL”). Other options are Dynamic Programming (“DP” or “DP2”) and Riemannian BFGS (“RBFGS”).
-
warp_f_gamma(time::Vector, f::Vector, gam::Vector)¶ Warp function f by warping function gamma
-
warp_q_gamma(time::Vector, q::Vector, gam::Vector)¶ Warp srsf q by warping function gamma
-
elastic_distance(f1::Vector, f2::Vector, timet::Vector, method="SIMUL")¶ Calculates the elastic distance between two functions and returns the amplitude distance
daand phase distancedp.
-
rgam(N, sigma, num)¶ Generate random warping functions of length
N.sigmacontrols the standard deviation across the random samples andnumis the number of random samples.
Alignment¶
-
srsf_align(f, timet; method="mean", smooth=false, sparam=10, lam=0.0, optim="DP", MaxItr=20)¶ Aligns a collection of functions using the elastic square-root slope (srsf) framework.
fis and array of shape (M,N) of N functions with M samplestimetis a vector of size M describing the sample pointsmethod(string) calculate Karcher Mean or Median (options = “mean” or “median”) (default=”mean”)smoothSmooth the data using a box filter (default = false)sparamNumber of times to run smoothing filter (default 10)lamcontrols the elasticity (default = 0)optimoptimization method to find warping, default is Simultaneous Alignment (“SIMUL”). Other options are Dynamic Programming (“DP2”), Riemanain BFGS (“RBFGS”)MaxItrmaximum number of iterations
Returns Dict containing:
fnaligned functions - array of shape (M,N) of N functions with M samplesqnaligned srsfs - similar structure to fnq0original srsfs - similar structure to fnfmeanfunction mean or median - vector of length Nmqnsrvf mean or median - vector of length Ngamwarping functions - similar structure to fnorig_varOriginal Variance of Functionsamp_varAmplitude Variancephase_varPhase Variance
-
align_fPCA(f, timet; num_comp=3, smooth=false, sparam=10, MaxItr=50)¶ Aligns a collection of functions while extracting principal components. The functions are aligned to the principal components
farray of shape (M,N) of N functions with M samplestimetvector of size M describing the sample pointsnum_compNumber of components (default = 3)smoothSmooth the data using a box filter (default = false)sparamNumber of times to run smoothing filter (default 10)MaxItrmaximum number of iterations
Returns Dict containing:
fnaligned functions - array of shape (M,N) of N functions with M samplesqnaligned srvfs - similar structure to fnq0original srvf - similar structure to fnmqnsrvf mean or median - vector of length Mgamwarping functions - similar structure to fnq_pcasrsf principal directionsf_pcafunctional principal directionslatentlatent valuescoefcoefficientsUeigenvectorsorig_varOriginal Variance of Functionsamp_varAmplitude Variancephase_varPhase Variance