Learn R Programming

elasdics (version 1.1.3)

compute_elastic_mean: Compute a elastic mean for a collection of curves

Description

Computes a Fréchet mean for the curves stored in data_curves) with respect to the elastic distance. Constructor function for class elastic_mean.

Usage

compute_elastic_mean(
  data_curves,
  knots = seq(0, 1, len = 5),
  type = c("smooth", "polygon"),
  closed = FALSE,
  eps = 0.01,
  pen_factor = 100,
  max_iter = 50
)

Value

an object of class elastic_mean, which is a list

with entries

type

"smooth" if mean was modeled using linear srv-splines or "polygon" if constant srv-splines are used

coefs

spline coeffiecients

knots

spline knots

data_curves

list of data.frames with observed points in each row. First variable t gives the initial parametrization, second variable t_optim the optimal parametrization when the curve is aligned to the mean.

closed

TRUE if the mean is supposed to be a closed curve.

Arguments

data_curves

list of data.frames with observed points in each row. Each variable is one coordinate direction. If there is a variable t, it is treated as the time parametrization, not as an additional coordinate.

knots

set of knots for the mean spline curve

type

if "smooth" linear srv-splines are used which results in a differentiable mean curve if "polygon" the mean will be piecewise linear.

closed

TRUE if the curves should be treated as closed.

eps

the algorithm stops if L2 norm of coefficients changes less

pen_factor

penalty factor forcing the mean to be closed

max_iter

maximal number of iterations

Examples

Run this code
curve <- function(t){
  rbind(t*cos(13*t), t*sin(13*t))
}
set.seed(18)
data_curves <- lapply(1:4, function(i){
  m <- sample(10:15, 1)
  delta <- abs(rnorm(m, mean = 1, sd = 0.05))
  t <- cumsum(delta)/sum(delta)
  data.frame(t(curve(t)) + 0.07*t*matrix(cumsum(rnorm(2*length(delta))),
             ncol = 2))
})

#compute elastic means
knots <- seq(0,1, length = 11)
smooth_elastic_mean <- compute_elastic_mean(data_curves, knots = knots)
plot(smooth_elastic_mean)

knots <- seq(0,1, length = 15)
polygon_elastic_mean <- compute_elastic_mean(data_curves, knots = knots, type = "poly")
lines(get_evals(polygon_elastic_mean), col = "blue", lwd = 2)

#compute closed smooth mean, takes a little longer
# \donttest{
knots <- seq(0,1, length = 11)
closed_elastic_mean <- compute_elastic_mean(data_curves, knots = knots, closed = TRUE)
plot(closed_elastic_mean)# }

Run the code above in your browser using DataLab