Title: | Elastic Functional Data Analysis |
---|---|
Description: | Performs alignment, PCA, and modeling of multidimensional and unidimensional functions using the square-root velocity framework (Srivastava et al., 2011 <doi:10.48550/arXiv.1103.3817> and Tucker et al., 2014 <DOI:10.1016/j.csda.2012.12.001>). This framework allows for elastic analysis of functional data through phase and amplitude separation. |
Authors: | J. Derek Tucker [aut, cre] , Aymeric Stamm [ctb] |
Maintainer: | J. Derek Tucker <[email protected]> |
License: | GPL-3 |
Version: | 2.3.3 |
Built: | 2024-10-30 00:58:16 UTC |
Source: | https://github.com/jdtuck/fdasrvf_r |
This function aligns a collection of functions while extracting principal components.
align_fPCA( f, time, num_comp = 3L, showplot = TRUE, smooth_data = FALSE, sparam = 25L, parallel = FALSE, cores = NULL, max_iter = 51L, lambda = 0 )
align_fPCA( f, time, num_comp = 3L, showplot = TRUE, smooth_data = FALSE, sparam = 25L, parallel = FALSE, cores = NULL, max_iter = 51L, lambda = 0 )
f |
A numeric matrix of shape |
time |
A numeric vector of length |
num_comp |
An integer value specifying the number of principal
components to extract. Defaults to |
showplot |
A boolean specifying whether to display plots along the way.
Defaults to |
smooth_data |
A boolean specifying whether to smooth data using box
filter. Defaults to |
sparam |
An integer value specifying the number of times to apply box
filter. Defaults to |
parallel |
A boolean specifying whether computations should run in
parallel. Defaults to |
cores |
An integer value specifying the number of cores to use for
parallel computations. Defaults to |
max_iter |
An integer value specifying the maximum number of iterations.
Defaults to |
lambda |
A numeric value specifying the elasticity. Defaults to |
A list with the following components:
f0
: A numeric matrix of shape storing the original
functions;
fn
: A numeric matrix of the same shape as f0
storing the aligned
functions;
qn
: A numeric matrix of the same shape as f0
storing the aligned
SRSFs;
q0
: A numeric matrix of the same shape as f0
storing the SRSFs of the
original functions;
mqn
: A numeric vector of length storing the mean SRSF;
gam
: A numeric matrix of the same shape as f0
storing the estimated
warping functions;
vfpca
: A list storing information about the vertical PCA with the
following components:
q_pca
: A numeric matrix of shape storing the first
principal directions in SRSF
space; the first dimension is
because, in SRSF space, the
original functions are represented by the SRSF and the initial value of the
functions.
f_pca
: A numeric matrix of shape storing the first
principal directions in
original space;
latent
: A numeric vector of length storing the singular
values of the SVD decomposition in SRSF space;
coef
: A numeric matrix of shape
storing the scores of the
original functions on the first
num_comp
principal components;
U
: A numeric matrix of shape storing the
eigenvectors associated with the SVD decomposition in SRSF space.
Dx
: A numeric vector of length max_iter
storing the value of the cost
function at each iteration.
Tucker, J. D., Wu, W., Srivastava, A., Generative models for functional data using phase and amplitude separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
## Not run: out <- align_fPCA(simu_data$f, simu_data$time) ## End(Not run)
## Not run: out <- align_fPCA(simu_data$f, simu_data$time) ## End(Not run)
Contains the MPEG7 curve data set.
beta
beta
beta
An array of shape storing a sample of
curves from
to
distributed in
different classes, evaluated on a grid of size
.
This function computes tolerance bounds for functional data containing phase and amplitude variation using bootstrap sampling
bootTB( f, time, a = 0.05, p = 0.99, B = 500, no = 5, Nsamp = 100, parallel = TRUE )
bootTB( f, time, a = 0.05, p = 0.99, B = 500, no = 5, Nsamp = 100, parallel = TRUE )
f |
matrix of functions |
time |
vector describing time sampling |
a |
confidence level of tolerance bound (default = 0.05) |
p |
coverage level of tolerance bound (default = 0.99) |
B |
number of bootstrap samples (default = 500) |
no |
number of principal components (default = 5) |
Nsamp |
number of functions per bootstrap (default = 100) |
parallel |
enable parallel processing (default = TRUE) |
Returns a list containing
amp |
amplitude tolerance bounds |
ph |
phase tolerance bounds |
J. D. Tucker, J. R. Lewis, C. King, and S. Kurtek, “A Geometric Approach for Computing Tolerance Bounds for Elastic Functional Data,” Journal of Applied Statistics, 10.1080/02664763.2019.1645818, 2019.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
Jung, S. L. a. S. (2016). "Combined Analysis of Amplitude and Phase Variations in Functional Data." arXiv:1603.01775.
## Not run: out1 <- bootTB(simu_data$f, simu_data$time) ## End(Not run)
## Not run: out1 <- bootTB(simu_data$f, simu_data$time) ## End(Not run)
This function computes the required statistics for building up a boxplot of the aligned functional data. Since the process of alignment provides separation of phase and amplitude variability, the computed boxplot can focus either on amplitude variability or phase variability.
## S3 method for class 'fdawarp' boxplot( x, variability_type = c("amplitude", "phase"), alpha = 0.05, range = 1, what = c("stats", "plot", "plot+stats"), ... ) ## S3 method for class 'ampbox' boxplot(x, ...) ## S3 method for class 'phbox' boxplot(x, ...) ## S3 method for class 'curvebox' boxplot(x, ...)
## S3 method for class 'fdawarp' boxplot( x, variability_type = c("amplitude", "phase"), alpha = 0.05, range = 1, what = c("stats", "plot", "plot+stats"), ... ) ## S3 method for class 'ampbox' boxplot(x, ...) ## S3 method for class 'phbox' boxplot(x, ...) ## S3 method for class 'curvebox' boxplot(x, ...)
x |
An object of class |
variability_type |
A string specifying which kind of variability should
be displayed in the boxplot. Choices are |
alpha |
A numeric value specifying the quantile value. Defaults to
|
range |
A positive numeric value specifying how far the plot whiskers
extend out from the box. The whiskers extend to the most extreme data point
which is no more than |
what |
A string specifying what the function should return. Choices are
|
... |
Unused here. |
The function boxplot.fdawarp()
returns optionally an object of class either
ampbox
if variability_type = "amplitude"
or phbox
if variability_type = "phase"
. S3
methods specialized for objects of these classes are
provided as well to avoid re-computation of the boxplot statistics.
If what
contains stats
, a list containing the computed statistics
necessary for drawing the boxplot. Otherwise, the function simply draws the
boxplot and no object is returned.
## Not run: out <- time_warping(simu_data$f, simu_data$time) boxplot(out, what = "stats") ## End(Not run)
## Not run: out <- time_warping(simu_data$f, simu_data$time) boxplot(out, what = "stats") ## End(Not run)
Calculates the elastic shape distance between two curves beta1
and beta2
.
calc_shape_dist( beta1, beta2, mode = "O", alignment = TRUE, rotation = TRUE, scale = TRUE, include.length = FALSE, lambda = 0 )
calc_shape_dist( beta1, beta2, mode = "O", alignment = TRUE, rotation = TRUE, scale = TRUE, include.length = FALSE, lambda = 0 )
beta1 |
A numeric matrix of shape |
beta2 |
A numeric matrix of shape |
mode |
A character string specifying whether the input curves should be
considered open ( |
alignment |
A boolean value specifying whether the curves should be
aligned before computing the distance matrix. Defaults to |
rotation |
A boolean specifying whether the distance should be made
invariant by rotation. Defaults to |
scale |
A boolean specifying whether the distance should be made
invariant by scaling. This is effectively achieved by making SRVFs having
unit length and switching to an appropriate metric on the sphere between
normalized SRVFs. Defaults to |
include.length |
A boolean specifying whether to include information
about the actual length of the SRVFs in the metric when using normalized
SRVFs to achieve scale invariance. This only applies if |
lambda |
A numeric value specifying the weight of a penalty term that
constraints the warping function to be not too far from the identity.
Defaults to |
Distances are computed between the SRVFs of the original curves. Hence, they
are intrinsically invariant to position. The user can then choose to make
distances invariant to rotation and scaling by setting rotation
and scale
accordingly. Distances can also be made invariant to reparametrization by
setting alignment = TRUE
, in which case curves are aligned using an
appropriate action of the diffeomorphism group on the space of SRVFs.
A list with the following components:
d
: the amplitude (geodesic) distance;
dx
: the phase distance;
q1
: the SRVF of beta1
;
q2n
: the SRVF of beta2
after alignment and possible optimal rotation
and scaling;
beta1
: the input curve beta1
;
beta2n
: the input curve beta2
after alignment and possible optimal
rotation and scaling.
R
: the optimal rotation matrix that has been applied to the second curve;
gam
: the optimal warping function that has been applied to the second
curve;
betascale
: the optimal scaling factor that has been applied to the second
curve.
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
Kurtek, S., Srivastava, A., Klassen, E., and Ding, Z. (2012), “Statistical Modeling of Curves Using Shapes and Related Features,” Journal of the American Statistical Association, 107, 1152–1165.
Srivastava, A., Klassen, E. P. (2016). Functional and shape data analysis, 1. New York: Springer.
out <- calc_shape_dist(beta[, , 1, 1], beta[, , 1, 4])
out <- calc_shape_dist(beta[, , 1, 1], beta[, , 1, 4])
This function computes the required statistics for building up a boxplot of the aligned curve data. The computed boxplot focuses on the aligned curves.
curve_boxplot( x, alpha = 0.05, range = 1, what = c("stats", "plot", "plot+stats"), ... )
curve_boxplot( x, alpha = 0.05, range = 1, what = c("stats", "plot", "plot+stats"), ... )
x |
An object of class |
alpha |
A numeric value specifying the quantile value. Defaults to
|
range |
A positive numeric value specifying how far the plot whiskers
extend out from the box. The whiskers extend to the most extreme data point
which is no more than |
what |
A string specifying what the function should return. Choices are
|
... |
Unused here. |
The function returns optionally an object of class either
curvebox
If what
contains stats
, a list containing the computed statistics
necessary for drawing the boxplot. Otherwise, the function simply draws the
boxplot and no object is returned.
## Not run: out <- curve_srvf_align(beta[, , 1, ], ms="median") curve_boxplot(out, what = "stats") ## End(Not run)
## Not run: out <- curve_srvf_align(beta[, , 1, ], ms="median") curve_boxplot(out, what = "stats") ## End(Not run)
This functions calculates the elastic depth between set of curves. If the
curves are describing multidimensional functional data, then
rotated == FALSE
and mode == 'O'
curve_depth(beta, mode = "O", rotated = TRUE, scale = TRUE, parallel = FALSE)
curve_depth(beta, mode = "O", rotated = TRUE, scale = TRUE, parallel = FALSE)
beta |
Array of sizes |
mode |
Open ( |
rotated |
Include rotation (default = |
scale |
scale curves to unit length (default = |
parallel |
run computation in parallel (default = |
Returns a list containing
amp |
amplitude depth |
phase |
phase depth |
T. Harris, J. D. Tucker, B. Li, and L. Shand, "Elastic depths for detecting shape anomalies in functional data," Technometrics, 10.1080/00401706.2020.1811156, 2020.
data("mpeg7") # note: use more shapes and iterations, small for speed out = curve_depth(beta[,,1,1:2])
data("mpeg7") # note: use more shapes and iterations, small for speed out = curve_depth(beta[,,1,1:2])
Computes the pairwise distance matrix between a set of curves using the
elastic shape distance as computed by calc_shape_dist()
.
curve_dist( beta, mode = "O", alignment = TRUE, rotation = FALSE, scale = FALSE, include.length = FALSE, lambda = 0, ncores = 1L )
curve_dist( beta, mode = "O", alignment = TRUE, rotation = FALSE, scale = FALSE, include.length = FALSE, lambda = 0, ncores = 1L )
beta |
A numeric array of shape |
mode |
A character string specifying whether the input curves should be
considered open ( |
alignment |
A boolean value specifying whether the curves should be
aligned before computing the distance matrix. Defaults to |
rotation |
A boolean specifying whether the distance should be made
invariant by rotation. Defaults to |
scale |
A boolean specifying whether the distance should be made
invariant by scaling. This is effectively achieved by making SRVFs having
unit length and switching to an appropriate metric on the sphere between
normalized SRVFs. Defaults to |
include.length |
A boolean specifying whether to include information
about the actual length of the SRVFs in the metric when using normalized
SRVFs to achieve scale invariance. This only applies if |
lambda |
A numeric value specifying the weight of a penalty term that
constraints the warping function to be not too far from the identity.
Defaults to |
ncores |
An integer value specifying the number of cores to use for
parallel computation. If |
Distances are computed between the SRVFs of the original curves. Hence, they
are intrinsically invariant to position. The user can then choose to make
distances invariant to rotation and scaling by setting rotation
and scale
accordingly. Distances can also be made invariant to reparametrization by
setting alignment = TRUE
, in which case curves are aligned using an
appropriate action of the diffeomorphism group on the space of SRVFs.
A list of two objects, Da
and Dp
, each of class dist
containing
the amplitude and phase distances, respectively.
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
Kurtek, S., Srivastava, A., Klassen, E., and Ding, Z. (2012), “Statistical Modeling of Curves Using Shapes and Related Features,” Journal of the American Statistical Association, 107, 1152–1165.
Srivastava, A., Klassen, E. P. (2016). Functional and shape data analysis, 1. New York: Springer.
out <- curve_dist(beta[, , 1, 1:4])
out <- curve_dist(beta[, , 1, 1:4])
Form geodesic between two curves using Elastic Method
curve_geodesic(beta1, beta2, k = 5)
curve_geodesic(beta1, beta2, k = 5)
beta1 |
curve 1, provided as a matrix of dimensions |
beta2 |
curve 2, provided as a matrix of dimensions |
k |
number of curves along geodesic (default |
a list containing
geod |
curves along geodesic (n,T,k) |
geod_q |
srvf's along geodesic |
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
out <- curve_geodesic(beta[, , 1, 1], beta[, , 1, 5])
out <- curve_geodesic(beta[, , 1, 1], beta[, , 1, 5])
Calculate Karcher Covariance of a set of curves
curve_karcher_cov(v, len = NA)
curve_karcher_cov(v, len = NA)
v |
array of sizes |
len |
lengths of curves (default = |
K covariance matrix
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
out <- curve_karcher_mean(beta[, , 1, 1:2], maxit = 2) # note: use more shapes, small for speed K <- curve_karcher_cov(out$v)
out <- curve_karcher_mean(beta[, , 1, 1:2], maxit = 2) # note: use more shapes, small for speed K <- curve_karcher_cov(out$v)
Calculates Karcher mean or median of a collection of curves using the elastic square-root velocity (SRVF) framework.
curve_karcher_mean( beta, mode = "O", rotated = TRUE, scale = TRUE, lambda = 0, maxit = 20, ms = c("mean", "median"), ncores = 1L )
curve_karcher_mean( beta, mode = "O", rotated = TRUE, scale = TRUE, lambda = 0, maxit = 20, ms = c("mean", "median"), ncores = 1L )
beta |
A numeric array of shape |
mode |
A character string specifying whether the input curves should be
considered open ( |
rotated |
A boolean specifying whether to make the metric
rotation-invariant. Defaults to |
scale |
A boolean specifying whether the distance should be made
invariant by scaling. This is effectively achieved by making SRVFs having
unit length and switching to an appropriate metric on the sphere between
normalized SRVFs. Defaults to |
lambda |
A numeric value specifying the elasticity. Defaults to |
maxit |
An integer value specifying the maximum number of iterations.
Defaults to |
ms |
A character string specifying whether the Karcher mean ("mean") or
Karcher median ("median") is returned. Defaults to |
ncores |
An integer value specifying the number of cores to use for
parallel computation. Defaults to |
An object of class fdacurve
which is a list with the following
components:
beta: A numeric array of shape specifying the
-sample of
-dimensional curves evaluated on
points.
The curves might be slightly different from the input curves as they have
been centered.
mu
: A numeric array of shape specifying the Karcher
mean or median of the SRVFs of the input curves.
type
: A character string specifying whether the Karcher mean or median
is returned.
betamean
: A numeric array of shape specifying the
Karcher mean or median of the input curves.
v
: A numeric array of shape specifying the
shooting vectors.
q
: A numeric array of shape specifying the
SRVFs of the input curves.
E
: A numeric vector of shape specifying XXX (TO DO)
cent
: A numeric array of shape specifying the centers
of the input curves.
len
: A numeric vector of shape specifying the length of the
input curves.
len_q
: A numeric vector of shape specifying the length of the
SRVFs of the input curves.
qun
: A numeric vector of shape specifying the consecutive
values of the cost function.
mean_scale
: A numeric value specifying the mean length of the input
curves.
mean_scale_q
: A numeric value specifying the mean length of the SRVFs
of the input curves.
mode
: A character string specifying the mode of the input curves.
rotated
: A boolean specifying whether the metric is rotation-invariant.
scale
: A boolean specifying whether the metric is scale-invariant.
ms
: A character string specifying whether the Karcher mean or median is
returned.
lambda
: A numeric value specifying the elasticity ??? (TO DO).
rsamps
: ??? (TO DO).
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in Euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
out <- curve_karcher_mean(beta[, , 1, 1:2], maxit = 2) # note: use more shapes, small for speed
out <- curve_karcher_mean(beta[, , 1, 1:2], maxit = 2) # note: use more shapes, small for speed
This function aligns to curves using Elastic Framework
curve_pair_align(beta1, beta2, mode = "O", rotation = TRUE, scale = TRUE)
curve_pair_align(beta1, beta2, mode = "O", rotation = TRUE, scale = TRUE)
beta1 |
curve 1, provided as a matrix of dimensions |
beta2 |
curve 2, provided as a matrix of dimensions |
mode |
Open ( |
rotation |
Include rotation (default = |
scale |
scale curves to unit length (default = |
a list containing
beta2n |
aligned curve 2 to 1 |
q2n |
aligned srvf 2 to 1 |
gam |
warping function |
q1 |
srvf of curve 1 |
beta1 |
centered curve 1 |
beta2 |
centered curve 2 |
R |
rotation matrix |
tau |
seed |
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
out <- curve_pair_align(beta[, , 1, 1], beta[, , 1, 5])
out <- curve_pair_align(beta[, , 1, 1], beta[, , 1, 5])
Calculate principal directions of a set of curves
curve_principal_directions(v, K, mu, len = NA, no = 3, N = 5, mode = "O")
curve_principal_directions(v, K, mu, len = NA, no = 3, N = 5, mode = "O")
v |
array of sizes |
K |
matrix of sizes |
mu |
matrix of sizes |
len |
length of original curves (default = |
no |
number of components |
N |
number of samples on each side of mean |
mode |
Open ( |
Returns a list containing
s |
singular values |
U |
singular vectors |
coef |
principal coefficients |
pd |
principal directions |
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
out <- curve_karcher_mean(beta[, , 1, 1:2], maxit = 2) # note: use more shapes, small for speed K <- curve_karcher_cov(out$v) out <- curve_principal_directions(out$v, K, out$mu)
out <- curve_karcher_mean(beta[, , 1, 1:2], maxit = 2) # note: use more shapes, small for speed K <- curve_karcher_cov(out$v) out <- curve_principal_directions(out$v, K, out$mu)
Aligns a collection of curves using the elastic square-root velocity (srvf)
framework. If the curves are describing multidimensional functional data, then
rotated == FALSE
and mode == 'O'
curve_srvf_align( beta, mode = "O", rotated = TRUE, scale = TRUE, lambda = 0, maxit = 20, ms = "mean", parallel = TRUE )
curve_srvf_align( beta, mode = "O", rotated = TRUE, scale = TRUE, lambda = 0, maxit = 20, ms = "mean", parallel = TRUE )
beta |
Array of sizes |
mode |
Open ( |
rotated |
Optimize over rotation (default = |
scale |
scale curves to unit length (default = |
lambda |
A numeric value specifying the elasticity. Defaults to |
maxit |
maximum number of iterations |
ms |
string defining whether the Karcher mean ("mean") or Karcher median ("median") is returned (default = "mean") |
parallel |
A boolean specifying whether to run calculations in parallel.
Defaults to |
An object of class fdacurve
which is a list with the following
components:
mu
: mean srvf
beta
: centered curves
betamean
: mean or median curve
betan
: aligned curves
qn
: aligned srvfs
type
: string indicating whether mean or median is returned
v
: shooting vectors
q
: array of srvfs
gam
: array of warping functions
cent
: centers of original curves
len
: length of curves
len_q
: length of srvfs
mean_scale
: mean length
mean_scale_q
: mean length srvf
E
: energy
qun
: cost function
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
data("mpeg7") # note: use more shapes and iterations, small for speed out = curve_srvf_align(beta[,,1,1:2],maxit=2,parallel=FALSE)
data("mpeg7") # note: use more shapes and iterations, small for speed out = curve_srvf_align(beta[,,1,1:2],maxit=2,parallel=FALSE)
This function computes the SRVF of a given curve. The function also outputs
the length of the original curve and the norm of the SRVF.
curve_to_q(beta, scale = TRUE)
curve_to_q(beta, scale = TRUE)
beta |
A numeric matrix of shape |
scale |
A boolean value specifying whether the output SRVF function
should be scaled to the hypersphere of |
A list with the following components:
q
: A numeric matrix of the same shape as the input matrix beta
storing
the (possibly scaled) SRVF of the original curve beta
;
len
: A numeric value specifying the length of the original curve;
lenq
: A numeric value specifying the norm of the SRVF of the
original curve.
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in Euclidean spaces. IEEE Transactions on Pattern Analysis and Machine Intelligence, 33(7), 1415-1428.
q <- curve_to_q(beta[, , 1, 1])$q
q <- curve_to_q(beta[, , 1, 1])$q
Converts a curve to its SRVF representation
curve2srvf(beta, is_derivative = FALSE)
curve2srvf(beta, is_derivative = FALSE)
beta |
A numeric matrix of size |
is_derivative |
A boolean value specifying whether the input |
A function that takes a numeric vector of values in
as input and returns the values of the SRVF of the original curve at
.
curve2srvf(beta[, , 1, 1])
curve2srvf(beta[, , 1, 1])
Converts a curve from matrix to functional data object
discrete2curve(beta)
discrete2curve(beta)
beta |
A numeric matrix of size |
A function that takes a numeric vector of values in
as input and returns the values of the original curve at
.
discrete2curve(beta[, , 1, 1])
discrete2curve(beta[, , 1, 1])
Converts a warping function from vector to functional data object
discrete2warping(gam)
discrete2warping(gam)
gam |
A numeric vector of length |
A function that takes a numeric vector of values in
as input and returns the values of the original warping function at
.
discrete2warping(toy_warp$gam[, 1])
discrete2warping(toy_warp$gam[, 1])
This function identifies a amplitude changepoint using a fully functional approach
elastic_amp_change_ff( f, time, d = 1000, h = 0, smooth_data = FALSE, sparam = 25, showplot = TRUE )
elastic_amp_change_ff( f, time, d = 1000, h = 0, smooth_data = FALSE, sparam = 25, showplot = TRUE )
f |
matrix ( |
time |
vector of size |
d |
number of monte carlo iterations of Brownian Bridge (default = 1000) |
h |
window selection of long range covariance function (default = 0) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
showplot |
show results plots (default = T) |
Returns a list object containing
pvalue |
p value |
change |
indice of changepoint |
DataBefore |
functions before changepoint |
DataAfter |
functions after changepoint |
MeanBefore |
mean function before changepoint |
MeanAfter |
mean function after changepoint |
WarpingBefore |
warping functions before changepoint |
WarpingAfter |
warping functions after changepoint |
WarpingMeanBefore |
mean warping function before changepoint |
WarpingMeanAfter |
mean warping function after changepoint |
change_fun |
amplitude change function |
Sn |
test statistic values |
mu |
mean srsfs |
mu_f |
mean functions |
J. D. Tucker and D. Yarger, “Elastic Functional Changepoint Detection of Climate Impacts from Localized Sources”, Envirometrics, 10.1002/env.2826, 2023.
This function identifies changepoints using a functional PCA
elastic_change_fpca( f, time, pca.method = "combined", pc = 0.95, d = 1000, n_pcs = 5, smooth_data = FALSE, sparam = 25, showplot = TRUE )
elastic_change_fpca( f, time, pca.method = "combined", pc = 0.95, d = 1000, n_pcs = 5, smooth_data = FALSE, sparam = 25, showplot = TRUE )
f |
matrix ( |
time |
vector of size |
pca.method |
string specifying pca method (options = "combined", "vert", or "horiz", default = "combined") |
pc |
percentage of cummulation explained variance (default = 0.95) |
d |
number of monte carlo iterations of Brownian Bridge (default = 1000) |
n_pcs |
scalar specify number of principal components (default = 5) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
showplot |
show results plots (default = T) |
Returns a list object containing
pvalue |
p value |
change |
indice of changepoint |
DataBefore |
functions before changepoint |
DataAfter |
functions after changepoint |
MeanBefore |
mean function before changepoint |
MeanAfter |
mean function after changepoint |
WarpingBefore |
warping functions before changepoint |
WarpingAfter |
warping functions after changepoint |
WarpingMeanBefore |
mean warping function before changepoint |
WarpingMeanAfter |
mean warping function after changepoint |
change_fun |
amplitude change function |
Sn |
test statistic values |
J. D. Tucker and D. Yarger, “Elastic Functional Changepoint Detection of Climate Impacts from Localized Sources”, Envirometrics, 10.1002/env.2826, 2023.
This function identifies a phase changepoint using a fully functional approach
elastic_ph_change_ff( f, time, d = 1000, h = 0, smooth_data = FALSE, sparam = 25, showplot = TRUE )
elastic_ph_change_ff( f, time, d = 1000, h = 0, smooth_data = FALSE, sparam = 25, showplot = TRUE )
f |
matrix ( |
time |
vector of size |
d |
number of monte carlo iterations of Brownian Bridge (default = 1000) |
h |
window selection of long range covariance function (default = 0) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
showplot |
show results plots (default = T) |
Returns a list object containing
pvalue |
p value |
change |
indice of changepoint |
DataBefore |
functions before changepoint |
DataAfter |
functions after changepoint |
MeanBefore |
mean function before changepoint |
MeanAfter |
mean function after changepoint |
WarpingBefore |
warping functions before changepoint |
WarpingAfter |
warping functions after changepoint |
WarpingMeanBefore |
mean warping function before changepoint |
WarpingMeanAfter |
mean warping function after changepoint |
change_fun |
amplitude change function |
Sn |
test statistic values |
mu |
mean shooting vectors |
J. D. Tucker and D. Yarger, “Elastic Functional Changepoint Detection of Climate Impacts from Localized Sources”, Envirometrics, 10.1002/env.2826, 2023.
This functions calculates the elastic depth between set of functions in
elastic.depth(f, time, lambda = 0, pen = "roughness", parallel = FALSE)
elastic.depth(f, time, lambda = 0, pen = "roughness", parallel = FALSE)
f |
matrix of sizes |
time |
vector of length |
lambda |
controls amount of warping (default = |
pen |
alignment penalty (default = |
parallel |
run computation in parallel (default = |
Returns a list containing
amp |
amplitude depth |
phase |
phase depth |
amp_dist |
amplitude distance matrix |
phs_dist |
phase distance matrix |
T. Harris, J. D. Tucker, B. Li, and L. Shand, "Elastic depths for detecting shape anomalies in functional data," Technometrics, 10.1080/00401706.2020.1811156, 2020.
depths <- elastic.depth(simu_data$f[, 1:4], simu_data$time)
depths <- elastic.depth(simu_data$f[, 1:4], simu_data$time)
This functions calculates the distances between functions in
and
, where function 2 is aligned to function 1
elastic.distance(f1, f2, time, lambda = 0, pen = "roughness")
elastic.distance(f1, f2, time, lambda = 0, pen = "roughness")
f1 |
sample function 1, provided as a vector of length |
f2 |
sample function 2, provided as a vector of length |
time |
sample points of functions, provided as a vector of length
|
lambda |
controls amount of warping (default = |
pen |
alignment penalty (default = |
Returns a list containing
Dy |
amplitude distance |
Dx |
phase distance |
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
distances <- elastic.distance( f1 = simu_data$f[, 1], f2 = simu_data$f[, 2], time = simu_data$time )
distances <- elastic.distance( f1 = simu_data$f[, 1], f2 = simu_data$f[, 2], time = simu_data$time )
This function identifies a logistic regression model with phase-variability using elastic methods
elastic.logistic( f, y, time, B = NULL, df = 20, max_itr = 20, smooth_data = FALSE, sparam = 25, parallel = FALSE, cores = 2 )
elastic.logistic( f, y, time, B = NULL, df = 20, max_itr = 20, smooth_data = FALSE, sparam = 25, parallel = FALSE, cores = 2 )
f |
matrix ( |
y |
vector of size |
time |
vector of size |
B |
matrix defining basis functions (default = NULL) |
df |
scalar controlling degrees of freedom if B=NULL (default=20) |
max_itr |
scalar number of iterations (default=20) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
parallel |
enable parallel mode using |
cores |
set number of cores to use with |
Returns a list containing
alpha |
model intercept |
beta |
regressor function |
fn |
aligned functions - matrix ( |
qn |
aligned srvfs - similar structure to fn |
gamma |
warping functions - similar structure to fn |
q |
original srvf - similar structure to fn |
B |
basis matrix |
b |
basis coefficients |
Loss |
logistic loss |
type |
model type ('logistic') |
Tucker, J. D., Wu, W., Srivastava, A., Elastic Functional Logistic Regression with Application to Physiological Signal Classification, Electronic Journal of Statistics (2014), submitted.
This function identifies a logistic regression model with phase-variability using elastic pca
elastic.lpcr.regression( f, y, time, pca.method = "combined", no = 5, smooth_data = FALSE, sparam = 25 )
elastic.lpcr.regression( f, y, time, pca.method = "combined", no = 5, smooth_data = FALSE, sparam = 25 )
f |
matrix ( |
y |
vector of size |
time |
vector of size |
pca.method |
string specifying pca method (options = "combined", "vert", or "horiz", default = "combined") |
no |
scalar specify number of principal components (default=5) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
Returns a lpcr object containing
alpha |
model intercept |
b |
regressor vector |
y |
label vector |
warp_data |
fdawarp object of aligned data |
pca |
pca object of principal components |
Loss |
logistic loss |
pca.method |
string specifying pca method used |
J. D. Tucker, J. R. Lewis, and A. Srivastava, “Elastic Functional Principal Component Regression,” Statistical Analysis and Data Mining, 10.1002/sam.11399, 2018.
This function identifies a multinomial logistic regression model with phase-variability using elastic methods
elastic.mlogistic( f, y, time, B = NULL, df = 20, max_itr = 20, smooth_data = FALSE, sparam = 25, parallel = FALSE, cores = 2 )
elastic.mlogistic( f, y, time, B = NULL, df = 20, max_itr = 20, smooth_data = FALSE, sparam = 25, parallel = FALSE, cores = 2 )
f |
matrix ( |
y |
vector of size |
time |
vector of size |
B |
matrix defining basis functions (default = NULL) |
df |
scalar controlling degrees of freedom if B=NULL (default=20) |
max_itr |
scalar number of iterations (default=20) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
parallel |
enable parallel mode using |
cores |
set number of cores to use with |
Returns a list containing
alpha |
model intercept |
beta |
regressor function |
fn |
aligned functions - matrix ( |
qn |
aligned srvfs - similar structure to fn |
gamma |
warping functions - similar structure to fn |
q |
original srvf - similar structure to fn |
B |
basis matrix |
b |
basis coefficients |
Loss |
logistic loss |
type |
model type ('mlogistic') |
Tucker, J. D., Wu, W., Srivastava, A., Elastic Functional Logistic Regression with Application to Physiological Signal Classification, Electronic Journal of Statistics (2014), submitted.
This function identifies a multinomial logistic regression model with phase-variability using elastic pca
elastic.mlpcr.regression( f, y, time, pca.method = "combined", no = 5, smooth_data = FALSE, sparam = 25 )
elastic.mlpcr.regression( f, y, time, pca.method = "combined", no = 5, smooth_data = FALSE, sparam = 25 )
f |
matrix ( |
y |
vector of size |
time |
vector of size |
pca.method |
string specifying pca method (options = "combined", "vert", or "horiz", default = "combined") |
no |
scalar specify number of principal components (default=5) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
Returns a mlpcr object containing
alpha |
model intercept |
b |
regressor vector |
y |
label vector |
Y |
Coded labels |
warp_data |
fdawarp object of aligned data |
pca |
pca object of principal components |
Loss |
logistic loss |
pca.method |
string specifying pca method used |
J. D. Tucker, J. R. Lewis, and A. Srivastava, “Elastic Functional Principal Component Regression,” Statistical Analysis and Data Mining, 10.1002/sam.11399, 2018.
This function identifies a regression model with phase-variability using elastic pca
elastic.pcr.regression( f, y, time, pca.method = "combined", no = 5, smooth_data = FALSE, sparam = 25, parallel = F, C = NULL )
elastic.pcr.regression( f, y, time, pca.method = "combined", no = 5, smooth_data = FALSE, sparam = 25, parallel = F, C = NULL )
f |
matrix ( |
y |
vector of size |
time |
vector of size |
pca.method |
string specifying pca method (options = "combined", "vert", or "horiz", default = "combined") |
no |
scalar specify number of principal components (default = 5) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
parallel |
run in parallel (default = F) |
C |
scale balance parameter for combined method (default = NULL) |
Returns a pcr object containing
alpha |
model intercept |
b |
regressor vector |
y |
response vector |
warp_data |
fdawarp object of aligned data |
pca |
pca object of principal components |
SSE |
sum of squared errors |
pca.method |
string specifying pca method used |
J. D. Tucker, J. R. Lewis, and A. Srivastava, “Elastic Functional Principal Component Regression,” Statistical Analysis and Data Mining, 10.1002/sam.11399, 2018.
This function performs prediction from an elastic regression model with phase-variability
elastic.prediction(f, time, model, y = NULL, smooth_data = FALSE, sparam = 25)
elastic.prediction(f, time, model, y = NULL, smooth_data = FALSE, sparam = 25)
f |
matrix ( |
time |
vector of size |
model |
list describing model from elastic regression methods |
y |
responses of test matrix f (default=NULL) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
Returns a list containing
y_pred |
predicted values of f or probabilities depending on model |
SSE |
sum of squared errors if linear |
y_labels |
labels if logistic model |
PC |
probability of classification if logistic |
Tucker, J. D., Wu, W., Srivastava, A., Elastic Functional Logistic Regression with Application to Physiological Signal Classification, Electronic Journal of Statistics (2014), submitted.
This function identifies a regression model with phase-variability using elastic methods
elastic.regression( f, y, time, B = NULL, lam = 0, df = 20, max_itr = 20, smooth_data = FALSE, sparam = 25, parallel = FALSE, cores = 2 )
elastic.regression( f, y, time, B = NULL, lam = 0, df = 20, max_itr = 20, smooth_data = FALSE, sparam = 25, parallel = FALSE, cores = 2 )
f |
matrix ( |
y |
vector of size |
time |
vector of size |
B |
matrix defining basis functions (default = NULL) |
lam |
scalar regularization parameter (default=0) |
df |
scalar controlling degrees of freedom if B=NULL (default=20) |
max_itr |
scalar number of iterations (default=20) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
parallel |
enable parallel mode using |
cores |
set number of cores to use with |
Returns a list containing
alpha |
model intercept |
beta |
regressor function |
fn |
aligned functions - matrix ( |
qn |
aligned srvfs - similar structure to fn |
gamma |
warping functions - similar structure to fn |
q |
original srvf - similar structure to fn |
B |
basis matrix |
b |
basis coefficients |
SSE |
sum of squared errors |
type |
model type ('linear') |
Tucker, J. D., Wu, W., Srivastava, A., Elastic Functional Logistic Regression with Application to Physiological Signal Classification, Electronic Journal of Statistics (2014), submitted.
This function plots functional data on a time grid
f_plot(t, f)
f_plot(t, f)
t |
A numeric vector of length |
f |
A numeric matrix of shape |
This function transforms functions in from their original functional
space to the SRVF space.
f_to_srvf(f, time)
f_to_srvf(f, time)
f |
Either a numeric vector of a numeric matrix or a numeric array specifying the functions that need to be transformed.
|
time |
A numeric vector of length |
A numeric array of the same shape as the input array f
storing the
SRVFs of the original curves.
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using Fisher-Rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative models for functional data using phase and amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
q <- f_to_srvf(simu_data$f, simu_data$time)
q <- f_to_srvf(simu_data$f, simu_data$time)
A library for functional data analysis using the square root velocity framework which performs pair-wise and group-wise alignment as well as modeling using functional component analysis.
Maintainer: J. Derek Tucker [email protected] (ORCID)
Other contributors:
Aymeric Stamm [email protected] (ORCID) [contributor]
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using Fisher-Rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative models for functional data using phase and amplitude separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
J. D. Tucker, W. Wu, and A. Srivastava, Phase-amplitude separation of proteomics data using extended Fisher-Rao metric, Electronic Journal of Statistics, Vol 8, no. 2. pp 1724-1733, 2014.
J. D. Tucker, W. Wu, and A. Srivastava, “Analysis of signals under compositional noise with applications to SONAR data," IEEE Journal of Oceanic Engineering, Vol 29, no. 2. pp 318-330, Apr 2014.
Tucker, J. D. 2014, Functional Component Analysis and Regression using Elastic Methods. Ph.D. Thesis, Florida State University.
Robinson, D. T. 2012, Function Data Analysis and Partial Shape Matching in the Square Root Velocity Framework. Ph.D. Thesis, Florida State University.
Kurtek, S., Srivastava, A., Klassen, E., and Ding, Z. (2012), “Statistical Modeling of Curves Using Shapes and Related Features,” Journal of the American Statistical Association, 107, 1152–1165.
Huang, W. 2014, Optimization Algorithms on Riemannian Manifolds with Applications. Ph.D. Thesis, Florida State University.
Cheng, W., Dryden, I. L., and Huang, X. (2016). Bayesian registration of functions and curves. Bayesian Analysis, 11(2), 447-475.
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
Cheng, W., Dryden, I. L., and Huang, X. (2016). Bayesian registration of functions and curves. Bayesian Analysis, 11(2), 447-475.
W. Xie, S. Kurtek, K. Bharath, and Y. Sun, A geometric approach to visualization of variability in functional data, Journal of American Statistical Association 112 (2017), pp. 979-993.
Lu, Y., R. Herbei, and S. Kurtek, 2017: Bayesian registration of functions with a Gaussian process prior. Journal of Computational and Graphical Statistics, 26, no. 4, 894–904.
Lee, S. and S. Jung, 2017: Combined analysis of amplitude and phase variations in functional data. arXiv:1603.01775, 1–21.
J. D. Tucker, J. R. Lewis, and A. Srivastava, “Elastic Functional Principal Component Regression,” Statistical Analysis and Data Mining, vol. 12, no. 2, pp. 101-115, 2019.
J. D. Tucker, J. R. Lewis, C. King, and S. Kurtek, “A Geometric Approach for Computing Tolerance Bounds for Elastic Functional Data,” Journal of Applied Statistics, 10.1080/02664763.2019.1645818, 2019.
T. Harris, J. D. Tucker, B. Li, and L. Shand, "Elastic depths for detecting shape anomalies in functional data," Technometrics, 10.1080/00401706.2020.1811156, 2020.
J. D. Tucker and D. Yarger, “Elastic Functional Changepoint Detection of Climate Impacts from Localized Sources”, Envirometrics, 10.1002/env.2826, 2023.
Useful links:
This function aligns a set of functions using Bayesian SRSF framework
function_group_warp_bayes( f, time, iter = 50000, powera = 1, times = 5, tau = ceiling(times * 0.04), gp = seq(dim(f)[2]), showplot = TRUE )
function_group_warp_bayes( f, time, iter = 50000, powera = 1, times = 5, tau = ceiling(times * 0.04), gp = seq(dim(f)[2]), showplot = TRUE )
f |
matrix ( |
time |
sample points of functions |
iter |
number of iterations (default = 150000) |
powera |
Dirichlet prior parameter (default 1) |
times |
factor of length of subsample points to look at (default = 5) |
tau |
standard deviation of Normal prior for increment (default ceil(times*.4)) |
gp |
number of colors in plots (defaults |
showplot |
shows plots of functions (default = T) |
Returns a list containing
f0 |
original functions |
f_q |
f aligned quotient space |
gam_q |
warping functions quotient space |
f_a |
f aligned ambient space |
gam_a |
warping ambient space |
qmn |
mean srsf |
Cheng, W., Dryden, I. L., and Huang, X. (2016). Bayesian registration of functions and curves. Bayesian Analysis, 11(2), 447-475.
## Not run: out <- function_group_warp_bayes(simu_data$f, simu_data$time) ## End(Not run)
## Not run: out <- function_group_warp_bayes(simu_data$f, simu_data$time) ## End(Not run)
This function calculates karcher mean of functions using Bayesian method
function_mean_bayes(f, time, times = 5, group = 1:dim(f)[2], showplot = TRUE)
function_mean_bayes(f, time, times = 5, group = 1:dim(f)[2], showplot = TRUE)
f |
matrix ( |
time |
sample points of functions |
times |
factor of length of subsample points to look at (default = 5) |
group |
(defaults |
showplot |
shows plots of functions (default = T) |
Returns a list containing
distfamily |
dist matrix |
match.matrix |
matrix of warping functions |
position |
position |
mu_5 |
function mean |
rtmatrix |
rtmatrix |
sumdist |
sumdist |
qt.fitted |
aligned srsf functions |
estimator |
estimator |
estimator2 |
estimator2 |
regfuncs |
registered functions |
Cheng, W., Dryden, I. L., and Huang, X. (2016). Bayesian registration of functions and curves. Bayesian Analysis, 11(2), 447-475.
## Not run: out <- function_mean_bayes(simu_data$f, simu_data$time) ## End(Not run)
## Not run: out <- function_mean_bayes(simu_data$f, simu_data$time) ## End(Not run)
map warping function to tangent space at identity
gam_to_h(gam, smooth = FALSE)
gam_to_h(gam, smooth = FALSE)
gam |
Either a numeric vector of a numeric matrix or a numeric array specifying the warping functions |
smooth |
Apply smoothing before gradient |
A numeric array of the same shape as the input array gamma
storing the
shooting vectors of gamma
obtained via finite differences.
map warping function to tangent space at identity
gam_to_v(gam, smooth = FALSE)
gam_to_v(gam, smooth = FALSE)
gam |
Either a numeric vector of a numeric matrix or a numeric array specifying the warping functions |
smooth |
Apply smoothing before gradient |
A numeric array of the same shape as the input array gamma
storing the
shooting vectors of gamma
obtained via finite differences.
This function models the functional data using a Gaussian model extracted from the principal components of the srvfs
gauss_model(warp_data, n = 1, sort_samples = FALSE)
gauss_model(warp_data, n = 1, sort_samples = FALSE)
warp_data |
|
n |
number of random samples (n = 1) |
sort_samples |
sort samples (default = F) |
Returns a fdawarp
object containing
fs |
random aligned samples |
gams |
random warping function samples |
ft |
random function samples |
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
out1 <- gauss_model(simu_warp, n = 10)
out1 <- gauss_model(simu_warp, n = 10)
Computes the distance matrix between a set of shapes.
get_distance_matrix( qfuns, alignment = FALSE, rotation = FALSE, scale = FALSE, lambda = 0, M = 200L, parallel_setup = 1L )
get_distance_matrix( qfuns, alignment = FALSE, rotation = FALSE, scale = FALSE, lambda = 0, M = 200L, parallel_setup = 1L )
qfuns |
A list of functions representing the shapes. Each function
should be a SRVF. See |
alignment |
A boolean value specifying whether the two SRVFs should be
optimally aligned before computing the distance. Defaults to |
rotation |
A boolean value specifying whether the two SRVFs should be
optimally rotated before computing the distance. Defaults to |
scale |
A boolean value specifying whether the two SRVFs should be
projected onto the Hilbert sphere before computing the distance. Defaults
to |
lambda |
A numeric value specifying the regularization parameter for the
optimal alignment. Defaults to |
M |
An integer value specifying the number of points to use when
searching for the optimal rotation and alignment. Defaults to |
parallel_setup |
An integer value specifying the number of cores to use
for parallel computing or an object of class |
An object of class dist
containing the distance matrix between the
shapes.
N <- 4L srvfs <- lapply(1:N, \(n) curve2srvf(beta[, , 1, n])) get_distance_matrix(srvfs, parallel_setup = 1L)
N <- 4L srvfs <- lapply(1:N, \(n) curve2srvf(beta[, , 1, n])) get_distance_matrix(srvfs, parallel_setup = 1L)
Computes the geodesic distance between two SRVFs on the Hilbert sphere
get_hilbert_sphere_distance(q1fun, q2fun)
get_hilbert_sphere_distance(q1fun, q2fun)
q1fun |
A function that takes a numeric vector |
q2fun |
A function that takes a numeric vector |
A numeric value storing the geodesic distance between the two SRVFs.
q1 <- curve2srvf(beta[, , 1, 1]) q2 <- curve2srvf(beta[, , 1, 2]) q1p <- to_hilbert_sphere(q1) q2p <- to_hilbert_sphere(q2) get_hilbert_sphere_distance(q1p, q2p)
q1 <- curve2srvf(beta[, , 1, 1]) q2 <- curve2srvf(beta[, , 1, 2]) q1p <- to_hilbert_sphere(q1) q2p <- to_hilbert_sphere(q2) get_hilbert_sphere_distance(q1p, q2p)
Computes the identity warping function
get_identity_warping()
get_identity_warping()
A function that takes a numeric vector of values in
as input and returns the values of the identity warping function at
.
get_identity_warping()
get_identity_warping()
distance between two SRVFsComputes the distance between two SRVFs
get_l2_distance(q1fun, q2fun, method = "quadrature")
get_l2_distance(q1fun, q2fun, method = "quadrature")
q1fun |
A function that takes a numeric vector |
q2fun |
A function that takes a numeric vector |
method |
A character string specifying the method to use for computing
the |
A numeric value storing the distance between the two SRVFs.
q1 <- curve2srvf(beta[, , 1, 1]) q2 <- curve2srvf(beta[, , 1, 2]) get_l2_distance(q1, q2)
q1 <- curve2srvf(beta[, , 1, 1]) q2 <- curve2srvf(beta[, , 1, 2]) get_l2_distance(q1, q2)
inner product between two SRVFsComputes the inner product between two SRVFs
get_l2_inner_product(q1fun, q2fun)
get_l2_inner_product(q1fun, q2fun)
q1fun |
A function that takes a numeric vector |
q2fun |
A function that takes a numeric vector |
A numeric value storing the inner product between the two
SRVFs.
q1 <- curve2srvf(beta[, , 1, 1]) q2 <- curve2srvf(beta[, , 1, 2]) get_l2_inner_product(q1, q2)
q1 <- curve2srvf(beta[, , 1, 1]) q2 <- curve2srvf(beta[, , 1, 2]) get_l2_inner_product(q1, q2)
Computes the distance between two shapes
get_shape_distance( q1fun, q2fun, alignment = FALSE, rotation = FALSE, scale = FALSE, lambda = 0, M = 200L )
get_shape_distance( q1fun, q2fun, alignment = FALSE, rotation = FALSE, scale = FALSE, lambda = 0, M = 200L )
q1fun |
A function that takes a numeric vector |
q2fun |
A function that takes a numeric vector |
alignment |
A boolean value specifying whether the two SRVFs should be
optimally aligned before computing the distance. Defaults to |
rotation |
A boolean value specifying whether the two SRVFs should be
optimally rotated before computing the distance. Defaults to |
scale |
A boolean value specifying whether the two SRVFs should be
projected onto the Hilbert sphere before computing the distance. Defaults
to |
lambda |
A numeric value specifying the regularization parameter for the
optimal alignment. Defaults to |
M |
An integer value specifying the number of points to use when
searching for the optimal rotation and alignment. Defaults to |
A numeric value storing the distance between the two shapes.
q1 <- curve2srvf(beta[, , 1, 1]) q2 <- curve2srvf(beta[, , 1, 2]) get_shape_distance(q1, q2)
q1 <- curve2srvf(beta[, , 1, 1]) q2 <- curve2srvf(beta[, , 1, 2]) get_shape_distance(q1, q2)
Computes the distance between two warping functions
get_warping_distance(gam1fun, gam2fun)
get_warping_distance(gam1fun, gam2fun)
gam1fun |
A function that takes a numeric vector |
gam2fun |
A function that takes a numeric vector |
A numeric value storing the distance between the two warping functions.
gam1 <- discrete2warping(toy_warp$gam[, 1]) gam2 <- discrete2warping(toy_warp$gam[, 2]) get_warping_distance(gam1, gam2) get_warping_distance(gam1, get_identity_warping())
gam1 <- discrete2warping(toy_warp$gam[, 1]) gam2 <- discrete2warping(toy_warp$gam[, 2]) get_warping_distance(gam1, gam2) get_warping_distance(gam1, get_identity_warping())
This function computes the gradient of f
using finite differences.
gradient(f, binsize, multidimensional = FALSE)
gradient(f, binsize, multidimensional = FALSE)
f |
Either a numeric vector of a numeric matrix or a numeric array specifying the curve(s) that need to be differentiated.
|
binsize |
A numeric value specifying the size of the bins for computing finite differences. |
multidimensional |
A boolean specifying if the curves are
multi-dimensional. This is useful when |
A numeric array of the same shape as the input array f
storing the
gradient of f
obtained via finite differences.
out <- gradient(simu_data$f[, 1], mean(diff(simu_data$time)))
out <- gradient(simu_data$f[, 1], mean(diff(simu_data$time)))
Combination of both boys and girls growth velocity from the Berkley dataset.
growth_vel
growth_vel
growth_vel
A list with two components:
f
: A numeric matrix of shape storing a sample of size
of curves evaluated on a grid of size
.
time
: A numeric vector of size storing the grid on which
the curves
f
have been evaluated.
map shooting vector to warping function at identity
h_to_gam(h)
h_to_gam(h)
h |
Either a numeric vector of a numeric matrix or a numeric array specifying the shooting vectors |
A numeric array of the same shape as the input array h
storing the
warping functions of h
.
This function calculates vertical functional principal component analysis on aligned data
horizFPCA(warp_data, no = 3, var_exp = NULL, ci = c(-1, 0, 1), showplot = TRUE)
horizFPCA(warp_data, no = 3, var_exp = NULL, ci = c(-1, 0, 1), showplot = TRUE)
warp_data |
fdawarp object from time_warping of aligned data |
no |
number of principal components to extract |
var_exp |
compute no based on value percent variance explained (example: 0.95)
will override |
ci |
geodesic standard deviations (default = c(-1,0,1)) |
showplot |
show plots of principal directions (default = T) |
Returns a hfpca object containing
gam_pca |
warping functions principal directions |
psi_pca |
srvf principal directions |
latent |
latent values |
U |
eigenvectors |
vec |
shooting vectors |
mu |
Karcher Mean |
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
hfpca <- horizFPCA(simu_warp, no = 3)
hfpca <- horizFPCA(simu_warp, no = 3)
Contains two simulated images for registration.
im
im
im
A list with two components:
I1
: A numeric matrix of shape storing the 1st image;
I2
: A numeric matrix of shape storing the 2nd image.
map square root of warping function to tangent space
inv_exp_map(Psi, psi)
inv_exp_map(Psi, psi)
Psi |
vector describing psi function at center of tangent space |
psi |
vector describing psi function to map to tangent space |
A numeric array of the same length as the input array psi
storing the
shooting vector of psi
This function calculates the inverse of gamma
invertGamma(gam)
invertGamma(gam)
gam |
vector of |
Returns gamI inverted vector
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
out <- invertGamma(simu_warp$warping_functions[, 1])
out <- invertGamma(simu_warp$warping_functions[, 1])
This function models the functional data using a Gaussian model extracted from the principal components of the srvfs using the joint model
joint_gauss_model(warp_data, n = 1, no = 5)
joint_gauss_model(warp_data, n = 1, no = 5)
warp_data |
fdawarp object from time_warping of aligned data |
n |
number of random samples (n = 1) |
no |
number of principal components (n=4) |
Returns a fdawarp object containing
fs |
random aligned samples |
gams |
random warping function samples |
ft |
random function samples |
qs |
random srvf samples |
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
Jung, S. L. a. S. (2016). "Combined Analysis of Amplitude and Phase Variations in Functional Data." arXiv:1603.01775.
out1 <- joint_gauss_model(simu_warp, n = 10)
out1 <- joint_gauss_model(simu_warp, n = 10)
This function calculates amplitude and phase joint functional principal component analysis on aligned data
jointFPCA( warp_data, no = 3, var_exp = NULL, id = round(length(warp_data$time)/2), C = NULL, ci = c(-1, 0, 1), showplot = T )
jointFPCA( warp_data, no = 3, var_exp = NULL, id = round(length(warp_data$time)/2), C = NULL, ci = c(-1, 0, 1), showplot = T )
warp_data |
fdawarp object from time_warping of aligned data |
no |
number of principal components to extract (default = 3) |
var_exp |
compute no based on value percent variance explained (example: 0.95)
will override |
id |
integration point for f0 (default = midpoint) |
C |
balance value (default = NULL) |
ci |
geodesic standard deviations (default = c(-1,0,1)) |
showplot |
show plots of principal directions (default = T) |
Returns a list containing
q_pca |
srvf principal directions |
f_pca |
f principal directions |
latent |
latent values |
coef |
coefficients |
U |
eigenvectors |
mu_psi |
mean psi function |
mu_g |
mean g function |
id |
point use for f(0) |
C |
optimized phase amplitude ratio |
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Jung, S. L. a. S. (2016). "Combined Analysis of Amplitude and Phase Variations in Functional Data." arXiv:1603.01775.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
jfpca <- jointFPCA(simu_warp, no = 3)
jfpca <- jointFPCA(simu_warp, no = 3)
This function calculates amplitude and phase joint functional principal component analysis on aligned data using the SRVF framework using MFPCA and h representation
jointFPCAh( warp_data, var_exp = 0.99, id = round(length(warp_data$time)/2), C = NULL, ci = c(-1, 0, 1), srvf = TRUE, showplot = TRUE )
jointFPCAh( warp_data, var_exp = 0.99, id = round(length(warp_data$time)/2), C = NULL, ci = c(-1, 0, 1), srvf = TRUE, showplot = TRUE )
warp_data |
fdawarp object from time_warping of aligned data |
var_exp |
compute no based on value percent variance explained (default: 0.99)
will override |
id |
integration point for f0 (default = midpoint) |
C |
balance value (default = NULL) |
ci |
geodesic standard deviations (default = c(-1,0,1)) |
srvf |
use srvf (default = TRUE) |
showplot |
show plots of principal directions (default = T) |
Returns a list containing
q_pca |
srvf principal directions |
f_pca |
f principal directions |
latent |
latent values |
coef |
coefficients |
U |
eigenvectors |
mu_psi |
mean psi function |
mu_g |
mean g function |
id |
point use for f(0) |
C |
optimized phase amplitude ratio |
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Jung, S. L. a. S. (2016). "Combined Analysis of Amplitude and Phase Variations in Functional Data." arXiv:1603.01775.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
jfpcah <- jointFPCAh(simu_warp)
jfpcah <- jointFPCAh(simu_warp)
This function clusters functions and aligns using the elastic square-root velocity function (SRVF) framework.
kmeans_align( f, time, K = 1L, seeds = NULL, centroid_type = c("mean", "medoid"), nonempty = 0L, lambda = 0, showplot = FALSE, smooth_data = FALSE, sparam = 25L, parallel = FALSE, alignment = TRUE, rotation = FALSE, scale = TRUE, omethod = c("DP", "RBFGS"), max_iter = 50L, thresh = 0.01, use_verbose = FALSE )
kmeans_align( f, time, K = 1L, seeds = NULL, centroid_type = c("mean", "medoid"), nonempty = 0L, lambda = 0, showplot = FALSE, smooth_data = FALSE, sparam = 25L, parallel = FALSE, alignment = TRUE, rotation = FALSE, scale = TRUE, omethod = c("DP", "RBFGS"), max_iter = 50L, thresh = 0.01, use_verbose = FALSE )
f |
Either a numeric matrix or a numeric 3D array specifying the functions that need to be jointly clustered and aligned.
If this is multidimensional functional data, it is advised that
|
time |
A numeric vector of length |
K |
An integer value specifying the number of clusters. Defaults to
|
seeds |
An integer vector of length |
centroid_type |
A string specifying the type of centroid to compute.
Choices are |
nonempty |
An integer value specifying the minimum number of curves per
cluster during the assignment step. Set it to a positive value to avoid the
problem of empty clusters. Defaults to |
lambda |
A numeric value specifying the elasticity. Defaults to |
showplot |
A Boolean specifying whether to show plots. Defaults to
|
smooth_data |
A Boolean specifying whether to smooth data using a box
filter. Defaults to |
sparam |
An integer value specifying the number of box filters applied.
Defaults to |
parallel |
A Boolean specifying whether parallel mode (using
|
alignment |
A Boolean specifying whether to perform alignment. Defaults
to |
rotation |
A Boolean specifying whether to perform rotation. Defaults to
to |
scale |
A Boolean specifying whether to scale curves to unit length. Defaults
to |
omethod |
A string specifying which method should be used to solve the
optimization problem that provides estimated warping functions. Choices are
|
max_iter |
An integer value specifying the maximum number of iterations.
Defaults to |
thresh |
A numeric value specifying a threshold on the cost function
below which convergence is assumed. Defaults to |
use_verbose |
A Boolean specifying whether to display information about
the calculations in the console. Defaults to |
An object of class fdakma
which is a list containing:
f0
: the original functions;
q0
: the original SRSFs;
fn
: the aligned functions as matrices or a 3D arrays of the same shape
than f0
by clusters in a list;
qn
: the aligned SRSFs as matrices or a 3D arrays of the same shape
than f0
separated in clusters in a list;
labels
: the cluster memberships as an integer vector;
templates
: the centroids in the original functional space;
templates.q
: the centroids in SRSF space;
distances_to_center
: A numeric vector storing the distances of each
observed curve to its center;
gam
: the warping functions as matrices or a 3D arrays of the same shape
than f0
by clusters in a list;
qun
: cost function value.
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using Fisher-Rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative models for functional data using phase and amplitude separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
Sangalli, L. M., et al. (2010). "k-mean alignment for curve clustering." Computational Statistics & Data Analysis 54(5): 1219-1233.
## Not run: out <- kmeans_align(growth_vel$f, growth_vel$time, K = 2) ## End(Not run)
## Not run: out <- kmeans_align(growth_vel$f, growth_vel$time, K = 2) ## End(Not run)
This function estimates the long run covariance matrix of a given multivariate data sample.
LongRunCovMatrix(mdobj, h = 0, kern_type = "bartlett")
LongRunCovMatrix(mdobj, h = 0, kern_type = "bartlett")
mdobj |
A multivariate data object |
h |
The bandwidth parameter. It is strictly non-zero. Choosing the bandwidth parameter to be zero is identical to estimating covariance matrix assuming iid data. |
kern_type |
Kernel function to be used for the estimation of the long run covariance
matrix. The choices are |
Returns long run covariance matrix
This function aligns a collection of functions using the elastic square-root slope (srsf) framework.
multiple_align_functions( f, time, mu, lambda = 0, pen = "roughness", showplot = TRUE, smooth_data = FALSE, sparam = 25, parallel = FALSE, cores = -1, omethod = "DP", MaxItr = 20, iter = 2000, verbose = TRUE )
multiple_align_functions( f, time, mu, lambda = 0, pen = "roughness", showplot = TRUE, smooth_data = FALSE, sparam = 25, parallel = FALSE, cores = -1, omethod = "DP", MaxItr = 20, iter = 2000, verbose = TRUE )
f |
matrix ( |
time |
vector of size |
mu |
vector of size |
lambda |
controls the elasticity (default = 0) |
pen |
alignment penalty (default="roughness") options are second derivative ("roughness"), geodesic distance from id ("geodesic"), and norm from id ("norm") |
showplot |
shows plots of functions (default = T) |
smooth_data |
smooth data using box filter (default = F) |
sparam |
number of times to apply box filter (default = 25) |
parallel |
enable parallel mode using |
cores |
number of cores in parallel (default=-1, means all cores) |
omethod |
optimization method (DP,DP2,RBFGS,dBayes,expBayes) |
MaxItr |
maximum number of iterations |
iter |
bayesian number of mcmc samples (default 2000) |
verbose |
verbose printing (default TRUE) |
Returns a fdawarp object containing
f0 |
original functions |
fn |
aligned functions - matrix ( |
qn |
aligned SRSFs - similar structure to fn |
q0 |
original SRSF - similar structure to fn |
fmean |
function mean or median - vector of length |
mqn |
SRSF mean or median - vector of length |
gam |
warping functions - similar structure to fn |
orig.var |
Original Variance of Functions |
amp.var |
Amplitude Variance |
phase.var |
Phase Variance |
qun |
Cost Function Value |
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
Calculates the Karcher mean or median of a collection of multivariate
functional data using the elastic square-root velocity (SRVF) framework.
While most of the time, the setting does not require a metric that is
invariant to rotation and scale, this can be achieved through the optional
arguments rotation
and scale
.
multivariate_karcher_mean( beta, mode = "O", alignment = TRUE, rotation = FALSE, scale = FALSE, lambda = 0, maxit = 20L, ms = c("mean", "median"), exact_medoid = FALSE, ncores = 1L, verbose = FALSE )
multivariate_karcher_mean( beta, mode = "O", alignment = TRUE, rotation = FALSE, scale = FALSE, lambda = 0, maxit = 20L, ms = c("mean", "median"), exact_medoid = FALSE, ncores = 1L, verbose = FALSE )
beta |
A numeric array of shape |
mode |
A character string specifying whether the input curves should be
considered open ( |
alignment |
A boolean value specifying whether the curves should be
aligned before computing the distance matrix. Defaults to |
rotation |
A boolean specifying whether the distance should be made
invariant by rotation. Defaults to |
scale |
A boolean specifying whether the distance should be made
invariant by scaling. This is effectively achieved by making SRVFs having
unit length and switching to an appropriate metric on the sphere between
normalized SRVFs. Defaults to |
lambda |
A numeric value specifying the weight of a penalty term that
constraints the warping function to be not too far from the identity.
Defaults to |
maxit |
An integer value specifying the maximum number of iterations.
Defaults to |
ms |
A character string specifying whether the Karcher mean ("mean") or
Karcher median ("median") is returned. Defaults to |
exact_medoid |
A boolean specifying whether to compute the exact medoid
from the distance matrix or as the input curve closest to the pointwise
mean. Defaults to |
ncores |
An integer value specifying the number of cores to use for
parallel computation. Defaults to |
verbose |
A boolean specifying whether to print the progress of the
algorithm. Defaults to |
A list with the following components:
beta
: A numeric array of shape storing the
original input data.
q
: A numeric array of shape storing the SRVFs
of the input data.
betan
: A numeric array of shape storing the
aligned, possibly optimally rotated and optimally scaled, input data.
qn
: A numeric array of shape storing the SRVFs
of the aligned, possibly optimally rotated and optimally scaled, input data.
betamean
: A numeric array of shape storing the Karcher
mean or median of the input data.
qmean
: A numeric array of shape storing the Karcher mean
or median of the SRVFs of the input data.
type
: A character string indicating whether the Karcher mean or median
has been returned.
E
: A numeric vector storing the energy of the Karcher mean or median at
each iteration.
qun
: A numeric vector storing the cost function of the Karcher mean or
median at each iteration.
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. IEEE Transactions on Pattern Analysis and Machine Intelligence, 33 (7), 1415-1428.
out <- multivariate_karcher_mean(beta[, , 1, 1:2], maxit = 2) # note: use more functions, small for speed
out <- multivariate_karcher_mean(beta[, , 1, 1:2], maxit = 2) # note: use more functions, small for speed
This function aligns the SRVFs of two functions in defined on an
interval
using dynamic programming or RBFGS
optimum.reparam( Q1, T1, Q2, T2, lambda = 0, pen = "roughness", method = c("DP", "DPo", "SIMUL", "RBFGS"), f1o = 0, f2o = 0, nbhd_dim = 7 )
optimum.reparam( Q1, T1, Q2, T2, lambda = 0, pen = "roughness", method = c("DP", "DPo", "SIMUL", "RBFGS"), f1o = 0, f2o = 0, nbhd_dim = 7 )
Q1 |
A numeric matrix of shape |
T1 |
A numeric vector of size |
Q2 |
A numeric matrix of shape |
T2 |
A numeric vector of size |
lambda |
A numeric value specifying the amount of warping. Defaults to
|
pen |
alignment penalty (default="roughness") options are second derivative ("roughness"), geodesic distance from id ("geodesic"), and norm from id ("l2gam"), srvf norm from id ("l2psi") |
method |
A string specifying the optimization method. Choices are
|
f1o |
A numeric vector of size |
f2o |
A numeric vector of size |
nbhd_dim |
size of the grid (default = 7) |
A numeric vector of size n_points
storing discrete evaluations of
the estimated boundary-preserving warping diffeomorphism on the initial
grid.
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using Fisher-Rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative models for functional data using phase and amplitude separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
q <- f_to_srvf(simu_data$f, simu_data$time) gam <- optimum.reparam(q[, 1], simu_data$time, q[, 2], simu_data$time)
q <- f_to_srvf(simu_data$f, simu_data$time) gam <- optimum.reparam(q[, 1], simu_data$time, q[, 2], simu_data$time)
This function calculates outlier's using geodesic distances of the SRVFs from the median
outlier.detection(q, time, mq, k = 1.5)
outlier.detection(q, time, mq, k = 1.5)
q |
matrix ( |
time |
vector of size |
mq |
median calculated using |
k |
cutoff threshold (default = 1.5) |
q_outlier |
outlier functions |
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
q_outlier <- outlier.detection( q = toy_warp$q0, time = toy_data$time, mq = toy_warp$mqn, k = .1 )
q_outlier <- outlier.detection( q = toy_warp$q0, time = toy_data$time, mq = toy_warp$mqn, k = .1 )
This function aligns two functions using SRSF framework. It will align f2 to f1
pair_align_functions( f1, f2, time, lambda = 0, pen = "roughness", method = "DP", w = 0.01, iter = 2000 )
pair_align_functions( f1, f2, time, lambda = 0, pen = "roughness", method = "DP", w = 0.01, iter = 2000 )
f1 |
function 1 |
f2 |
function 2 |
time |
sample points of functions |
lambda |
controls amount of warping (default = 0) |
pen |
alignment penalty (default="roughness") options are second derivative ("roughness"), geodesic distance from id ("geodesic"), and norm from id ("norm") |
method |
controls which optimization method (default="DP") options are Dynamic Programming ("DP"), Coordinate Descent ("DP2"), Riemannian BFGS ("RBFGS"), Simultaneous Alignment ("SIMUL"), Dirichlet Bayesian ("dBayes"), and Expo-Map Bayesian ("expBayes") |
w |
controls LRBFGS (default = 0.01) |
iter |
number of mcmc iterations for mcmc method (default 2000) |
Returns a list containing
f2tilde |
aligned f2 |
gam |
warping function |
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
Cheng, W., Dryden, I. L., and Huang, X. (2016). Bayesian registration of functions and curves. Bayesian Analysis, 11(2), 447-475.
Lu, Y., Herbei, R., and Kurtek, S. (2017). Bayesian registration of functions with a Gaussian process prior. Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2017.1336444.
out <- pair_align_functions( f1 = simu_data$f[, 1], f2 = simu_data$f[, 2], time = simu_data$time )
out <- pair_align_functions( f1 = simu_data$f[, 1], f2 = simu_data$f[, 2], time = simu_data$time )
This function aligns two functions using Bayesian SRSF framework. It will align f2 to f1
pair_align_functions_bayes( f1, f2, timet, iter = 15000, times = 5, tau = ceiling(times * 0.4), powera = 1, showplot = TRUE, extrainfo = FALSE )
pair_align_functions_bayes( f1, f2, timet, iter = 15000, times = 5, tau = ceiling(times * 0.4), powera = 1, showplot = TRUE, extrainfo = FALSE )
f1 |
function 1 |
f2 |
function 2 |
timet |
sample points of functions |
iter |
number of iterations (default = 15000) |
times |
factor of length of subsample points to look at (default = 5) |
tau |
standard deviation of Normal prior for increment (default ceil(times*.4)) |
powera |
Dirichlet prior parameter (default 1) |
showplot |
shows plots of functions (default = T) |
extrainfo |
T/F whether additional information is returned |
Returns a list containing
f1 |
function 1 |
f2_q |
registered function using quotient space |
gam_q |
warping function quotient space |
f2_a |
registered function using ambient space |
q2_a |
warping function ambient space |
match_collect |
posterior samples from warping function (returned if extrainfo=TRUE) |
dist_collect |
posterior samples from the distances (returned if extrainfo=TRUE) |
kappa_collect |
posterior samples from kappa (returned if extrainfo=TRUE) |
log_collect |
log-likelihood of each sample (returned if extrainfo=TRUE) |
pct_accept |
vector of acceptance ratios for the warping function (returned if extrainfo=TRUE) |
Cheng, W., Dryden, I. L., and Huang, X. (2016). Bayesian registration of functions and curves. Bayesian Analysis, 11(2), 447-475.
out <- pair_align_functions_bayes( f1 = simu_data$f[, 1], f2 = simu_data$f[, 2], timet = simu_data$time )
out <- pair_align_functions_bayes( f1 = simu_data$f[, 1], f2 = simu_data$f[, 2], timet = simu_data$time )
This function aligns two functions using Bayesian framework. 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 Z-mixture pCN algorithm is used to explore both local and global structure in the posterior distribution.
pair_align_functions_expomap( f1, f2, timet, iter = 20000, burnin = min(5000, iter/2), alpha0 = 0.1, beta0 = 0.1, zpcn = list(betas = c(0.5, 0.05, 0.005, 1e-04), probs = c(0.1, 0.1, 0.7, 0.1)), propvar = 1, init.coef = rep(0, 2 * 10), npoints = 200, extrainfo = FALSE )
pair_align_functions_expomap( f1, f2, timet, iter = 20000, burnin = min(5000, iter/2), alpha0 = 0.1, beta0 = 0.1, zpcn = list(betas = c(0.5, 0.05, 0.005, 1e-04), probs = c(0.1, 0.1, 0.7, 0.1)), propvar = 1, init.coef = rep(0, 2 * 10), npoints = 200, extrainfo = FALSE )
f1 |
observed data, numeric vector |
f2 |
observed data, numeric vector |
timet |
sample points of functions |
iter |
length of the chain |
burnin |
number of burnin MCMC iterations |
alpha0 , beta0
|
IG parameters for the prior of sigma1 |
zpcn |
list of mixture coefficients and prior probabilities for Z-mixture pCN algorithm of the form list(betas, probs), where betas and probs are numeric vectors of equal length |
propvar |
variance of proposal distribution |
init.coef |
initial coefficients of warping function in exponential map; length must be even |
npoints |
number of sample points to use during alignment |
extrainfo |
T/F whether additional information is returned |
The Z-mixture pCN algorithm uses a mixture distribution for the proposal distribution, controlled by input parameter zpcn. The zpcn$betas must be between 0 and 1, and are the coefficients of the mixture components, with larger coefficients corresponding to larger shifts in parameter space. The zpcn$probs give the probability of each shift size.
Returns a list containing
f2_warped |
f2 aligned to f1 |
gamma |
Posterior mean gamma function |
g.coef |
matrix with iter columns, posterior draws of g.coef |
psi |
Posterior mean psi function |
sigma1 |
numeric vector of length iter, posterior draws of sigma1 |
accept |
Boolean acceptance for each sample (if extrainfo=TRUE) |
betas.ind |
Index of zpcn mixture component for each sample (if extrainfo=TRUE) |
logl |
numeric vector of length iter, posterior loglikelihood (if extrainfo=TRUE) |
gamma_mat |
Matrix of all posterior draws of gamma (if extrainfo=TRUE) |
gamma_q025 |
Lower 0.025 quantile of gamma (if extrainfo=TRUE) |
gamma_q975 |
Upper 0.975 quantile of gamma (if extrainfo=TRUE) |
sigma_eff_size |
Effective sample size of sigma (if extrainfo=TRUE) |
psi_eff_size |
Vector of effective sample sizes of psi (if extrainfo=TRUE) |
xdist |
Vector of posterior draws from xdist between registered functions (if extrainfo=TRUE) |
ydist |
Vector of posterior draws from ydist between registered functions (if extrainfo=TRUE) |
Lu, Y., Herbei, R., and Kurtek, S. (2017). Bayesian registration of functions with a Gaussian process prior. Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2017.1336444.
## Not run: # This is an MCMC algorithm and takes a long time to run myzpcn <- list( betas = c(0.1, 0.01, 0.005, 0.0001), probs = c(0.2, 0.2, 0.4, 0.2) ) out <- pair_align_functions_expomap( f1 = simu_data$f[, 1], f2 = simu_data$f[, 2], timet = simu_data$time, zpcn = myzpcn, extrainfo = TRUE ) # overall acceptance ratio mean(out$accept) # acceptance ratio by zpcn coefficient with(out, tapply(accept, myzpcn$betas[betas.ind], mean)) ## End(Not run)
## Not run: # This is an MCMC algorithm and takes a long time to run myzpcn <- list( betas = c(0.1, 0.01, 0.005, 0.0001), probs = c(0.2, 0.2, 0.4, 0.2) ) out <- pair_align_functions_expomap( f1 = simu_data$f[, 1], f2 = simu_data$f[, 2], timet = simu_data$time, zpcn = myzpcn, extrainfo = TRUE ) # overall acceptance ratio mean(out$accept) # acceptance ratio by zpcn coefficient with(out, tapply(accept, myzpcn$betas[betas.ind], mean)) ## End(Not run)
Pairwise align two images This function aligns to images using the q-map framework
pair_align_image( I1, I2, M = 5, ortho = TRUE, basis_type = "t", resizei = FALSE, N = 64, stepsize = 1e-05, itermax = 1000 )
pair_align_image( I1, I2, M = 5, ortho = TRUE, basis_type = "t", resizei = FALSE, N = 64, stepsize = 1e-05, itermax = 1000 )
I1 |
reference image |
I2 |
image to warp |
M |
number of basis elements (default=5) |
ortho |
orthonormalize basis (default=TRUE) |
basis_type |
("t","s","i","o"; default="t") |
resizei |
resize image (default=TRUE) |
N |
size of resized image (default=64) |
stepsize |
gradient stepsize (default=1e-5) |
itermax |
maximum number of iterations (default=1000) |
Returns a list containing
Inew |
aligned I2 |
gam |
warping function |
Q. Xie, S. Kurtek, E. Klassen, G. E. Christensen and A. Srivastava. Metric-based pairwise and multiple image registration. IEEE European Conference on Computer Vision (ECCV), September, 2014
## Not run: # This is a gradient descent algorithm and takes a long time to run out <- pair_align_image(im$I1, im$I2) ## End(Not run)
## Not run: # This is a gradient descent algorithm and takes a long time to run out <- pair_align_image(im$I1, im$I2) ## End(Not run)
This function computes tolerance bounds for functional data containing phase and amplitude variation using principal component analysis
pcaTB(f, time, m = 4, B = 1e+05, a = 0.05, p = 0.99)
pcaTB(f, time, m = 4, B = 1e+05, a = 0.05, p = 0.99)
f |
matrix of functions |
time |
vector describing time sampling |
m |
number of principal components (default = 4) |
B |
number of monte carlo iterations |
a |
confidence level of tolerance bound (default = 0.05) |
p |
coverage level of tolerance bound (default = 0.99) |
Returns a list containing
pca |
pca output |
tol |
tolerance factor |
J. D. Tucker, J. R. Lewis, C. King, and S. Kurtek, “A Geometric Approach for Computing Tolerance Bounds for Elastic Functional Data,” Journal of Applied Statistics, 10.1080/02664763.2019.1645818, 2019.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
Jung, S. L. a. S. (2016). "Combined Analysis of Amplitude and Phase Variations in Functional Data." arXiv:1603.01775.
## Not run: out1 <- pcaTB(simu_data$f, simu_data$time) ## End(Not run)
## Not run: out1 <- pcaTB(simu_data$f, simu_data$time) ## End(Not run)
This function plots open or closed curves
plot_curve(beta, add = FALSE, ...)
plot_curve(beta, add = FALSE, ...)
beta |
Array of sizes |
add |
add to current plot (default = |
... |
additional plotting parameters |
Return shape confidence intervals
This function performs projection of new functions on fPCA basis
## S3 method for class 'hfpca' predict(object, newdata = NULL, ...)
## S3 method for class 'hfpca' predict(object, newdata = NULL, ...)
object |
Object of class inheriting from "horizFPCA" |
newdata |
An optional matrix in which to look for functions with which to predict. If omitted, the original functions are used. |
... |
additional arguments affecting the predictions produced |
Returns a matrix
a |
principle coefficients |
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
This function performs projection of new functions on fPCA basis
## S3 method for class 'jfpca' predict(object, newdata = NULL, ...)
## S3 method for class 'jfpca' predict(object, newdata = NULL, ...)
object |
Object of class inheriting from "jointFPCA" |
newdata |
An optional matrix in which to look for functions with which to predict. If omitted, the original functions are used. |
... |
additional arguments affecting the predictions produced |
Returns a matrix
a |
principle coefficients |
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
This function performs projection of new functions on fPCA basis
## S3 method for class 'jfpcah' predict(object, newdata = NULL, ...)
## S3 method for class 'jfpcah' predict(object, newdata = NULL, ...)
object |
Object of class inheriting from "jointFPCA" |
newdata |
An optional matrix in which to look for functions with which to predict. If omitted, the original functions are used. |
... |
additional arguments affecting the predictions produced |
Returns a matrix
a |
principle coefficients |
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
This function performs prediction from an elastic logistic fPCR regression model with phase-variability
## S3 method for class 'lpcr' predict(object, newdata = NULL, y = NULL, ...)
## S3 method for class 'lpcr' predict(object, newdata = NULL, y = NULL, ...)
object |
Object of class inheriting from "elastic.pcr.regression" |
newdata |
An optional matrix in which to look for variables with which to predict. If omitted, the fitted values are used. |
y |
An optional vector of labels to calculate PC. If omitted, PC is NULL |
... |
additional arguments affecting the predictions produced |
Returns a list containing
y_pred |
predicted probabilities of the class of newdata |
y_labels |
class labels of newdata |
PC |
probability of classification |
J. D. Tucker, J. R. Lewis, and A. Srivastava, “Elastic Functional Principal Component Regression,” Statistical Analysis and Data Mining, 10.1002/sam.11399, 2018.
This function performs prediction from an elastic multinomial logistic fPCR regression model with phase-variability
## S3 method for class 'mlpcr' predict(object, newdata = NULL, y = NULL, ...)
## S3 method for class 'mlpcr' predict(object, newdata = NULL, y = NULL, ...)
object |
Object of class inheriting from "elastic.pcr.regression" |
newdata |
An optional matrix in which to look for variables with which to predict. If omitted, the fitted values are used. |
y |
An optional vector of labels to calculate PC. If omitted, PC is NULL |
... |
additional arguments affecting the predictions produced |
Returns a list containing
y_pred |
predicted probabilities of the class of newdata |
y_labels |
class labels of newdata |
PC |
probability of classification per class |
PC.comb |
total probability of classification |
J. D. Tucker, J. R. Lewis, and A. Srivastava, “Elastic Functional Principal Component Regression,” Statistical Analysis and Data Mining, 10.1002/sam.11399, 2018.
This function performs prediction from an elastic pcr regression model with phase-variability
## S3 method for class 'pcr' predict(object, newdata = NULL, y = NULL, ...)
## S3 method for class 'pcr' predict(object, newdata = NULL, y = NULL, ...)
object |
Object of class inheriting from "elastic.pcr.regression" |
newdata |
An optional matrix in which to look for variables with which to predict. If omitted, the fitted values are used. |
y |
An optional vector of responses to calculate SSE. If omitted, SSE is NULL |
... |
additional arguments affecting the predictions produced |
Returns a list containing
y_pred |
predicted values of newdata |
SSE |
sum of squared errors |
J. D. Tucker, J. R. Lewis, and A. Srivastava, “Elastic Functional Principal Component Regression,” Statistical Analysis and Data Mining, 10.1002/sam.11399, 2018.
This function performs projection of new functions on fPCA basis
## S3 method for class 'vfpca' predict(object, newdata = NULL, ...)
## S3 method for class 'vfpca' predict(object, newdata = NULL, ...)
object |
Object of class inheriting from "vertFPCA" |
newdata |
An optional matrix in which to look for functions with which to predict. If omitted, the original functions are used. |
... |
additional arguments affecting the predictions produced |
Returns a matrix
a |
principle coefficients |
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
This function converts SRVFs to curves
q_to_curve(q, scale = 1)
q_to_curve(q, scale = 1)
q |
either a matrix of shape |
scale |
scale of from curve_to_q (default = |
beta array describing curve
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
q <- curve_to_q(beta[, , 1, 1])$q beta1 <- q_to_curve(q)
q <- curve_to_q(beta[, , 1, 1])$q beta1 <- q_to_curve(q)
This function aligns two SRVF functions using Dynamic Programming. If the
curves beta1 and beta2 are describing multidimensional functional data, then
rotation == FALSE
and mode == 'O'
reparam_curve( beta1, beta2, lambda = 0, method = "DP", w = 0.01, rotated = TRUE, isclosed = FALSE, mode = "O" )
reparam_curve( beta1, beta2, lambda = 0, method = "DP", w = 0.01, rotated = TRUE, isclosed = FALSE, mode = "O" )
beta1 |
curve 1, provided as a matrix of dimensions |
beta2 |
curve 1, provided as a matrix of dimensions |
lambda |
controls amount of warping (default = |
method |
controls which optimization method. Options are
Dynamic Programming ( |
w |
controls LRBFGS (default = |
rotated |
boolean if rotation is desired |
isclosed |
boolean if curve is closed |
mode |
Open ( |
return a List containing
gam |
warping function |
R |
rotation matrix |
tau |
seed point |
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
gam <- reparam_curve(beta[, , 1, 1], beta[, , 1, 5])$gam
gam <- reparam_curve(beta[, , 1, 1], beta[, , 1, 5])$gam
Finds the optimal warping function between two images using the elastic framework
reparam_image(It, Im, gam, b, stepsize = 1e-05, itermax = 1000, lmark = FALSE)
reparam_image(It, Im, gam, b, stepsize = 1e-05, itermax = 1000, lmark = FALSE)
It |
template image matrix |
Im |
test image matrix |
gam |
initial warping array |
b |
basis matrix |
stepsize |
gradient stepsize (default=1e-5) |
itermax |
maximum number of iterations (default=1000) |
lmark |
use landmarks (default=FALSE) |
Returns a list containing
gamnew |
final warping |
Inew |
aligned image |
H |
energy |
stepsize |
final stepsize |
Q. Xie, S. Kurtek, E. Klassen, G. E. Christensen and A. Srivastava. Metric-based pairwise and multiple image registration. IEEE European Conference on Computer Vision (ECCV), September, 2014
This function resamples a curve to a number of points
resamplecurve(x, N = 100, mode = "O")
resamplecurve(x, N = 100, mode = "O")
x |
matrix defining curve (n,T) |
N |
Number of samples to re-sample curve, N usually is > T |
mode |
Open ("O") or Closed ("C") curves |
xn matrix defining resampled curve
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
xn <- resamplecurve(beta[, , 1, 1], 200)
xn <- resamplecurve(beta[, , 1, 1], 200)
Generates random warping functions
rgam(N, sigma, num)
rgam(N, sigma, num)
N |
length of warping function |
sigma |
variance of warping functions |
num |
number of warping functions |
gam warping functions
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
gam = rgam(N=101, sigma=.01, num=35)
gam = rgam(N=101, sigma=.01, num=35)
Sample shapes from model
sample_shapes(x, no = 3, numSamp = 10)
sample_shapes(x, no = 3, numSamp = 10)
x |
An object of class |
no |
number of principal components |
numSamp |
number of samples |
Returns a fdacurve
object containing
betans |
random aligned curves |
qns |
random aligned srvfs |
betans |
random curves |
qs |
random srvfs |
gams |
random reparametrization functions |
R |
random rotation matrices |
Srivastava, A., Klassen, E., Joshi, S., Jermyn, I., (2011). Shape analysis of elastic curves in euclidean spaces. Pattern Analysis and Machine Intelligence, IEEE Transactions on 33 (7), 1415-1428.
out <- curve_srvf_align(beta[, , 1, 1:5], maxit = 2, parallel=FALSE) # note: use more shapes, small for speed out.samples <- sample_shapes(out)
out <- curve_srvf_align(beta[, , 1, 1:5], maxit = 2, parallel=FALSE) # note: use more shapes, small for speed out.samples <- sample_shapes(out)
This function computes Confidence bounds for shapes using elastic metric
shape_CI( beta, a = 0.95, no = 5, Nsamp = 100, mode = "O", rotated = TRUE, scale = TRUE, lambda = 0, parallel = TRUE )
shape_CI( beta, a = 0.95, no = 5, Nsamp = 100, mode = "O", rotated = TRUE, scale = TRUE, lambda = 0, parallel = TRUE )
beta |
Array of sizes |
a |
confidence level (default = 0.95) |
no |
number of principal components (default = 5) |
Nsamp |
number of functions to generate (default = 100) |
mode |
Open ( |
rotated |
Optimize over rotation (default = |
scale |
scale curves to unit length (default = |
lambda |
A numeric value specifying the elasticity. Defaults to |
parallel |
enable parallel processing (default = T) |
Return shape confidence intervals
J. D. Tucker, J. R. Lewis, C. King, and S. Kurtek, “A Geometric Approach for Computing Tolerance Bounds for Elastic Functional Data,” Journal of Applied Statistics, 10.1080/02664763.2019.1645818, 2019.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
A functional dataset where the individual functions are given by: ,
, where
and
are i.i.d. normal
with mean one and standard deviation 0.25. Each of these functions is then
warped according to:
if
, otherwise
(
) is the identity warping). The variables are as
follows: f containing the 21 functions of 101 samples and time which
describes the sampling.
simu_data
simu_data
simu_data
A list with 2 components:
f
: A numeric matrix of shape storing a sample of size
of curves evaluated on a grid of size
.
time
: A numeric vector of size storing the grid on which
the curves
f
have been evaluated.
A functional dataset where the individual functions are given by: ,
, where
and
are i.i.d. normal
with mean one and standard deviation 0.25. Each of these functions is then
warped according to:
if
, otherwise
(
) is the identity warping). The variables are as
follows: f containing the 21 functions of 101 samples and time which
describes the sampling which has been aligned.
simu_warp
simu_warp
simu_warp
A list which contains the output of the time_warping()
function applied on
the data set simu_data
.
A functional dataset where the individual functions are given by: ,
, where
and
are i.i.d. normal
with mean one and standard deviation 0.25. Each of these functions is then
warped according to:
if
, otherwise
(
) is the identity warping). The variables are as
follows: f containing the 21 functions of 101 samples and time which
describes the sampling which has been aligned.
simu_warp_median
simu_warp_median
simu_warp_median
A list which contains the output of the time_warping()
function finding the
median applied on the data set simu_data
.
This function smooths functions using standard box filter
smooth.data(f, sparam)
smooth.data(f, sparam)
f |
matrix ( |
sparam |
number of times to run box filter |
fo smoothed functions
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
fo <- smooth.data(simu_data$f, 25)
fo <- smooth.data(simu_data$f, 25)
This function calculates the srvf of warping functions with corresponding shooting vectors and finds the mean
SqrtMean(gam)
SqrtMean(gam)
gam |
matrix ( |
Returns a list containing
mu |
Karcher mean psi function |
gam_mu |
Karcher mean warping function |
psi |
srvf of warping functions |
vec |
shooting vectors |
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
out <- SqrtMean(simu_warp$warping_functions)
out <- SqrtMean(simu_warp$warping_functions)
This function calculates the srvf of warping functions with corresponding shooting vectors and finds the inverse of mean
SqrtMeanInverse(gam)
SqrtMeanInverse(gam)
gam |
matrix ( |
gamI
inverse of Karcher mean warping function
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
gamI <- SqrtMeanInverse(simu_warp$warping_functions)
gamI <- SqrtMeanInverse(simu_warp$warping_functions)
This function calculates the srvf of warping functions with corresponding shooting vectors and finds the median
SqrtMedian(gam)
SqrtMedian(gam)
gam |
matrix ( |
Returns a list containing
median |
Karcher median psi function |
gam_median |
Karcher mean warping function |
psi |
srvf of warping functions |
vec |
shooting vectors |
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
out <- SqrtMedian(simu_warp_median$warping_functions)
out <- SqrtMedian(simu_warp_median$warping_functions)
This function transforms SRVFs back to the original functional space for
functions in .
srvf_to_f(q, time, f0 = 0)
srvf_to_f(q, time, f0 = 0)
q |
Either a numeric vector of a numeric matrix or a numeric array specifying the SRSFs that need to be transformed.
|
time |
A numeric vector of length |
f0 |
Either a numeric value or a numeric vector of or a numeric matrix specifying the initial value of the curves in the original functional space. It must be:
|
A numeric array of the same shape as the input q
storing the
transformation of the SRVFs q
back to the original functional space.
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative models for functional data using amplitude and phase separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
q <- f_to_srvf(simu_data$f, simu_data$time) f <- srvf_to_f(q, simu_data$time, simu_data$f[1, ])
q <- f_to_srvf(simu_data$f, simu_data$time) f <- srvf_to_f(q, simu_data$time, simu_data$f[1, ])
Converts from SRVF to curve representation
srvf2curve(qfun, beta0 = NULL)
srvf2curve(qfun, beta0 = NULL)
qfun |
A function that takes a numeric vector |
beta0 |
A numeric vector of length |
A function that takes a numeric vector of values in
as input and returns the values of the underlying curve at
.
srvf2curve(curve2srvf(beta[, , 1, 1]))
srvf2curve(curve2srvf(beta[, , 1, 1]))
This function aligns a collection of -dimensional curves that are
observed on the same grid.
time_warping( f, time, lambda = 0, penalty_method = c("roughness", "geodesic", "norm"), centroid_type = c("mean", "median"), center_warpings = TRUE, smooth_data = FALSE, sparam = 25L, parallel = FALSE, cores = -1, optim_method = c("DP", "DPo", "DP2", "RBFGS"), max_iter = 20L )
time_warping( f, time, lambda = 0, penalty_method = c("roughness", "geodesic", "norm"), centroid_type = c("mean", "median"), center_warpings = TRUE, smooth_data = FALSE, sparam = 25L, parallel = FALSE, cores = -1, optim_method = c("DP", "DPo", "DP2", "RBFGS"), max_iter = 20L )
f |
A numeric matrix of shape |
time |
A numeric vector of length |
lambda |
A numeric value specifying the elasticity. Defaults to |
penalty_method |
A string specifying the penalty term used in the
formulation of the cost function to minimize for alignment. Choices are
|
centroid_type |
A string specifying the type of centroid to align to.
Choices are |
center_warpings |
A boolean specifying whether to center the estimated
warping functions. Defaults to |
smooth_data |
A boolean specifying whether to smooth curves using a box
filter. Defaults to |
sparam |
An integer value specifying the number of times to apply the
box filter. Defaults to |
parallel |
A boolean specifying whether to run calculations in parallel.
Defaults to |
cores |
number of cores in parallel (default=-1, means all cores) |
optim_method |
A string specifying the algorithm used for optimization.
Choices are |
max_iter |
An integer value specifying the maximum number of iterations.
Defaults to |
An object of class fdawarp
which is a list with the following
components:
time
: a numeric vector of length storing the original grid;
f0
: a numeric matrix of shape storing the original
sample of
functions observed on a grid of size
;
q0
: a numeric matrix of the same shape as f0
storing the original
SRSFs;
fn
: a numeric matrix of the same shape as f0
storing the aligned
functions;
qn
: a numeric matrix of the same shape as f0
storing the aligned SRSFs;
fmean
: a numeric vector of length storing the mean or median
curve;
mqn
: a numeric vector of length storing the mean or median SRSF;
warping_functions
: a numeric matrix of the same shape as f0
storing the
estimated warping functions;
original_variance
: a numeric value storing the variance of the original
sample;
amplitude_variance
: a numeric value storing the variance in amplitude of
the aligned sample;
phase_variance
: a numeric value storing the variance in phase of the
aligned sample;
qun
: a numeric vector of maximum length max_iter + 2
storing the values
of the cost function after each iteration;
lambda
: the input parameter lambda
which specifies the elasticity;
centroid_type
: the input centroid type;
optim_method
: the input optimization method;
inverse_average_warping_function
: the inverse of the mean estimated
warping function;
rsamps
: TO DO.
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using Fisher-Rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative models for functional data using phase and amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
## Not run: out <- time_warping(simu_data$f, simu_data$time) ## End(Not run)
## Not run: out <- time_warping(simu_data$f, simu_data$time) ## End(Not run)
Projects an SRVF onto the Hilbert sphere
to_hilbert_sphere(qfun, qnorm = sqrt(get_l2_inner_product(qfun, qfun)))
to_hilbert_sphere(qfun, qnorm = sqrt(get_l2_inner_product(qfun, qfun)))
qfun |
A function that takes a numeric vector |
qnorm |
A numeric value specifying the |
A function that takes a numeric vector of values in
as input and returns the values of the SRVF projected onto the Hilbert
sphere.
q <- curve2srvf(beta[, , 1, 1]) to_hilbert_sphere(q)
q <- curve2srvf(beta[, , 1, 1]) to_hilbert_sphere(q)
A functional dataset where the individual functions are given by a Gaussian
peak with locations along the -axis. The variables are as follows: f
containing the 29 functions of 101 samples and time which describes the
sampling.
toy_data
toy_data
toy_data
A list with two components:
f
: A numeric matrix of shape storing a sample of size
of curves evaluated on a grid of size
.
time
: A numeric vector of size storing the grid on which
the curves
f
have been evaluated.
A functional dataset where the individual functions are given by a Gaussian
peak with locations along the -axis. The variables are as follows: f
containing the 29 functions of 101 samples and time which describes the
sampling which as been aligned.
toy_warp
toy_warp
toy_warp
A list which contains the output of the time_warping()
function applied on
the data set toy_data
.
map shooting vector to warping function at identity
v_to_gam(v)
v_to_gam(v)
v |
Either a numeric vector of a numeric matrix or a numeric array specifying the shooting vectors |
A numeric array of the same shape as the input array v
storing the
warping functions v
.
This function calculates vertical functional principal component analysis on aligned data
vertFPCA( warp_data, no = 3, var_exp = NULL, id = round(length(warp_data$time)/2), ci = c(-1, 0, 1), showplot = TRUE )
vertFPCA( warp_data, no = 3, var_exp = NULL, id = round(length(warp_data$time)/2), ci = c(-1, 0, 1), showplot = TRUE )
warp_data |
fdawarp object from time_warping of aligned data |
no |
number of principal components to extract |
var_exp |
compute no based on value percent variance explained (example: 0.95)
will override |
id |
point to use for f(0) (default = midpoint) |
ci |
geodesic standard deviations (default = c(-1,0,1)) |
showplot |
show plots of principal directions (default = T) |
Returns a vfpca object containing
q_pca |
srvf principal directions |
f_pca |
f principal directions |
latent |
latent values |
coef |
coefficients |
U |
eigenvectors |
id |
point used for f(0) |
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
vfpca <- vertFPCA(simu_warp, no = 3)
vfpca <- vertFPCA(simu_warp, no = 3)
Applies a warping function to a given curve
warp_curve(betafun, gamfun)
warp_curve(betafun, gamfun)
betafun |
A function that takes a numeric vector |
gamfun |
A function that takes a numeric vector |
A function that takes a numeric vector of values in
as input and returns the values of the warped curve at
.
curv <- discrete2curve(beta[, , 1, 1]) gamf <- discrete2warping(seq(0, 1, length = 100)^2) warp_curve(curv, gamf)
curv <- discrete2curve(beta[, , 1, 1]) gamf <- discrete2warping(seq(0, 1, length = 100)^2) warp_curve(curv, gamf)
This function warps function by
warp_f_gamma(f, time, gamma, spl.int = FALSE)
warp_f_gamma(f, time, gamma, spl.int = FALSE)
f |
vector function |
time |
time |
gamma |
vector warping function |
spl.int |
use spline interpolation (default F) |
fnew warped function
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
fnew <- warp_f_gamma( f = simu_data$f[, 1], time = simu_data$time, gamma = seq(0, 1, length.out = 101) )
fnew <- warp_f_gamma( f = simu_data$f[, 1], time = simu_data$time, gamma = seq(0, 1, length.out = 101) )
This function warps srsf by
warp_q_gamma(q, time, gamma, spl.int = FALSE)
warp_q_gamma(q, time, gamma, spl.int = FALSE)
q |
vector |
time |
time |
gamma |
vector warping function |
spl.int |
use spline interpolation (default F) |
qnew warped function
Srivastava, A., Wu, W., Kurtek, S., Klassen, E., Marron, J. S., May 2011. Registration of functional data using fisher-rao metric, arXiv:1103.3817v2.
Tucker, J. D., Wu, W., Srivastava, A., Generative Models for Function Data using Phase and Amplitude Separation, Computational Statistics and Data Analysis (2012), 10.1016/j.csda.2012.12.001.
q <- f_to_srvf(simu_data$f, simu_data$time) qnew <- warp_q_gamma(q[, 1], simu_data$time, seq(0, 1, length.out = 101))
q <- f_to_srvf(simu_data$f, simu_data$time) qnew <- warp_q_gamma(q[, 1], simu_data$time, seq(0, 1, length.out = 101))
Applies a warping function to a given SRVF
warp_srvf(qfun, gamfun, betafun = NULL)
warp_srvf(qfun, gamfun, betafun = NULL)
qfun |
A function that takes a numeric vector |
gamfun |
A function that takes a numeric vector |
betafun |
A function that takes a numeric vector |
A function that takes a numeric vector of values in
as input and returns the values of the warped SRVF.
q <- curve2srvf(beta[, , 1, 1]) warp_srvf(q, get_identity_warping())
q <- curve2srvf(beta[, , 1, 1]) warp_srvf(q, get_identity_warping())