This function carries out the warping of elements of a univariate functional dataset by using a set of pre-computed warping functions.
warp(fData, warpings)
the functional dataset whose observations must be warped in
form of fData
object.
the warping functions H1,…,HN, in form of
fData
object, defined over the registered/warped grid.
The function returns the univariate functional dataset of warped
functions, in form of fData
object.
Given a univariate functional dataset X1(t),…,XN(t) and a set of warping functions H1(t),…,HN(t), such that: Hi:s⟶t=Hi(s),∀i=1,…,N, where s spans the warped (or registered) grid and t spans the original grid, the function computes the warping given by the following composition: X1∘H1(t),…,XN∘HN(t).
set.seed( 1618033 )
N = 30
t0 = 0
t1 = 1
P = 1e3 + 1
time_grid = seq( t0, t1, length.out = P )
means = round( runif( N,
t0 + (t1 - t0) / 8,
t1 - (t1 - t0) / 8 ), 3 )
Data = matrix( sapply( means,
function( m )( dnorm( time_grid, mean = m, sd = 0.05 ) ) ),
ncol = P, nrow = N, byrow = TRUE )
fD = fData( time_grid, Data )
# Piecewise linear warpings
template_warping = function( m )( c( time_grid[ time_grid <= 0.5 ] * m / 0.5,
( time_grid[ time_grid > 0.5 ]
- 0.5 ) * (1 - m ) / 0.5 + m ) )
warpings = matrix( sapply( means, template_warping ),
ncol = P,
nrow = N, byrow = TRUE )
wfD = fData( time_grid, warpings )
fD_warped = warp( fD, wfD )
dev.new()
oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 3))
plot( fD,
main = 'Unregistered functions', xlab = 'actual grid', ylab = 'values' )
plot( wfD,
main = 'Warping functions', xlab = 'registered grid',
ylab = 'actual grid' )
plot( fD_warped,
main = 'Warped functions', xlab = 'registered grid',
ylab = 'values' )
par(oldpar)