elastes is a R package that provides functions for the computation of functional elastic shape means over sets of open planar curves. The package is particularly suitable for settings where these curves are only sparsely and irregularly observed. It uses a novel approach for elastic shape mean estimation, where planar curves are treated as complex functions and a full Procrustes mean is estimated from the corresponding smoothed Hermitian covariance surface. This is combined with the methods for elastic mean estimation proposed in Steyer, Stöcker, Greven (2022). See Stöcker et. al. (2022) for details.
The simplest way to obtain elastes is to install it directly from CRAN. Type the following command in your R console:
install.packages("elastes")
You can install the development version from GitHub with:
# install.packages("devtools")
::install_github("mpff/elastes") devtools
Calculate a smooth elastic shape mean for sparse spirals.
library(elastes)
# define spiral curve
<- function(t){
curve rbind(t*cos(13*t), t*sin(13*t))
}
# randomly draw sparse spirals with noise
set.seed(18)
<- lapply(1:10, function(i){
data_curves <- sample(10:15, 1)
m <- abs(rnorm(m, mean = 1, sd = 0.05))
delta <- cumsum(delta)/sum(delta)
t data.frame(t(curve(t)) + 0.07*t*matrix(cumsum(rnorm(2*length(delta))),
ncol = 2))
})
# apply random rotation and scaling to spiral curves
<- function(curve){ ( 0.5 + runif(1) ) * curve }
rand_scale <- function(curve){
rand_rotate <- colnames(curve)
names <- 2*pi*runif(1)
theta <- matrix(c(cos(theta), sin(theta), -sin(theta), cos(theta)), nrow = 2, ncol = 2)
mat <- as.matrix(curve) %*% t(mat)
curve.rot <- as.data.frame(curve.rot)
curve.rot colnames(curve.rot) <- names
return(curve.rot)
}<- lapply(data_curves, rand_scale)
data_curves <- lapply(data_curves, rand_rotate)
data_curves
# compute smooth procrustes mean using a 2nd order penalty in the estimation
<- seq(0,1, length = 11)
knots <- compute_elastic_shape_mean(
elastic_shape_mean
data_curves,knots = knots,
type = "smooth",
penalty = 2
)plot(elastic_shape_mean)