projectCurveWavelets: Function to project a curve on a wavelet basis.

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/ext_functional.R

Description

This function performs the Discrete Wavelet Transform (DWT) on a numeric vector representing a curve (i.e. a "functional" datum) observed on a grid and thresholds the wavelet coefficients, thus yielding a denoised and compressed representation of the same curve.

Usage

1
2
projectCurveWavelets( x, y, irreg.grid=FALSE, grid.length=NULL,
filter.number=10, family="DaubLeAsymm", bc="periodic", verbose=FALSE, ... )

Arguments

x

a numeric vector of x coordinates at which the curve is observed.

y

a numeric vector of y coordinates representing the curve. x and y must have the same length.

irreg.grid

logical. TRUE if x is not an equispaced grid.

grid.length

a positive power of 2 or NULL (default). In order to apply the DWT, length(x) must be a positive power of 2. By default, if grid.length=NULL and length(x) is not a power of 2, x is extended to an equispaced grid whose length is positive power of 2 and y is extended interpolated on the extended grid. If projectCurveWavelets is used on multiple curves, grid.length should be set manually to ensure that all the discretized curves have the same length before the DWT is applied on each of them.

filter.number

an integer specifying the smoothness of the wavelet used in the wavelet decomposition of y. See the functions wd and irregwd of wavethresh for details.

family

a character string specifying the family of wavelets used in the wavelet decomposition of y. See the functions wd and irregwd of wavethresh for details.

bc

a character string specifying how to handle the boundary condition. See the functions wd and irregwd of wavethresh for details.

verbose

logical. Controls the printing of "informative" messages whilst the computation progresses. Such messages are generally annoying so it is turned off by default.

...

further arguments to control the thresholding of the wavelet coefficients. See threshold.wd and threshold.irregwd of the wavethresh package for details. By default, projectCurvesWavelets uses the default values of threshold.wd and threshold.irregwd to perform the thresholding of the wavelet coefficients.

Details

The function normalizes the input grid to the standard unit interval, i.e. the minimum and the maximum values of x.grid are respectively 0 and 1.

projectCurveWavelet is designed to be used as a preliminary step towards functional clustering using the mean shift algorithm. Given a sample of curves, projectCurveWavelet can be used to represent each curve as a sparse vector of coefficients. These coefficients can be fed as a matrix to msClustering or bmsClustering and clustered via the mean shift algorithm or the blurring mean shift algorithm.

Value

The function outputs a list with names

coefficients

a numeric vector of thresholded wavelet coefficients.

y.wdT

an object of class wd or irregwd. See threshold.wd and threshold.irregwd of the wavethresh package for details.

y.wavelet

a numeric vector with the reconstruction of y after the application of the DWT and the thresholding of the wavelet coefficients.

x.grid

the extended and equispaced grid of x values associated to y.wavelet.

Author(s)

Mattia Ciollaro and Daren Wang

References

Nason, G. (2010) Wavelet methods in statistics with R.

See Also

wavethresh wd irregwd threshold.wd threshold.irregwd wr msClustering bmsClustering

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
## generate a noisy curve observed on a regular grid
set.seed( 1 )
n.grid <- 1000
x <- seq( 2, 8, length=n.grid )
sigma.epsilon1 <- 2
sigma.epsilon2 <- 2.5
sigma.epsilon3 <- 3
sigma.epsilon4 <- 1
epsilon <- rnorm( 1000, sd=rep( c( sigma.epsilon1,
sigma.epsilon2, sigma.epsilon3, sigma.epsilon4 ),
rep( 250, 4 ) ) )
y <- x*sin( 3*x ) + 0.3*x^2 + epsilon

## project on wavelet basis with soft universal thresholding
## of the wavelet coefficients
wave <- projectCurveWavelets( x, y, type="soft", policy="universal" )

## plot wavelet reconstruction of the curve
## Not run: 
x.norm <- ( x - min( x ) ) / ( max( x ) - min( x ) )
plot( x.norm, y )
lines( wave$x.grid, wave$y.wavelet, col=2, lwd=3 )
## End(Not run)

## inspect wavelet coefficients
wave.coeffs <- wave$coefficients
print( length( wave.coeffs ) )  ## 1023 coefficients
print( sum( wave.coeffs != 0 ) )  ## only 12 are non-zero

mattiaciollaro/MeanShift documentation built on May 21, 2019, 1:23 p.m.