warp: Warp elements of a univariate functional dataset

Description Usage Arguments Details Value See Also Examples

View source: R/fData.R

Description

This function carries out the warping of elements of a univariate functional dataset by using a set of pre-computed warping functions.

Usage

1
warp(fData, warpings)

Arguments

fData

the functional dataset whose observations must be warped in form of fData object.

warpings

the warping functions H_1, …, H_N, in form of fData object, defined over the registered/warped grid.

Details

Given a univariate functional dataset X_1(t), …, X_N(t) and a set of warping functions H_1(t), …, H_N(t), such that:

H_i : s \longrightarrow t = H_i(s), \quad \forall 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:

X_1 \circ H_1(t), …, X_N \circ H_N(t).

Value

The function returns the univariate functional dataset of warped functions, in form of fData object.

See Also

fData

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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)

roahd documentation built on Nov. 4, 2021, 1:07 a.m.