TVRegDiffR: Total Variation Regularized Numerical Differentiation...

Description Usage Arguments Details Value Author(s) References Examples

View source: R/TVRegDiffR.R

Description

Estimate the derivative of noisy data using total variation regularized differentiation.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
TVRegDiffR(
  data,
  iter,
  alph,
  u0 = NULL,
  scale = "small",
  ep = 1e-06,
  dx = 1/length(data),
  plotflag = 0,
  tol = 1e-06,
  maxit = 1000
)

Arguments

data

Vector of data to be differentiated.

iter

Number of iterations to run the main loop. A stopping condition based on the norm of the gradient vector g below would be an easy modification. No default value.

alph

Regularization parameter. This is the main parameter to fiddle with. Start by varying by orders of magnitude until reasonable results are obtained. A value to the nearest power of 10 is usally adequate. No default value. Higher values increase regularization strenght and improve conditioning.

u0

Initialization of the iteration. Default value is the naive derivative (without scaling), of appropriate length (this being different for the two methods). Although the solution is theoretically independent of the intialization, a poor choice can exacerbate conditioning issues when the linear system is solved.

scale

'large' or 'small' (case insensitive). Default is 'small'. 'small' has somewhat better boundary behavior, but becomes unwieldly for data larger than 1000 entries or so. 'large' has simpler numerics but is more efficient for large-scale problems. 'large' is more readily modified for higher-order derivatives, since the implicit differentiation matrix is square.

ep

Parameter for avoiding division by zero. Default value is 1e-6. Results should not be very sensitive to the value. Larger values improve conditioning and therefore speed, while smaller values give more accurate results with sharper jumps.

dx

Grid spacing, used in the definition of the derivative operators. Default is the reciprocal of the data size.

plotflag

Flag whether to display plot at each iteration. Default is 0 (no). Useful, but adds significant running time.

tol

R Version Only: Tolerance passed to preconditiond conjugate gradient solver

maxit

R Version Only: Maximum iterations passed to preconditiond conjugate gradient solver

Details

C++ code for preconditioned conjugate gradient method adapted from cPCG::pcgsolve

Value

Estimate of the regularized derivative of data. Due to different grid assumptions, length( u ) = length( data ) + 1 if scale = 'small', otherwise length( u ) = length( data ).

Author(s)

R translation: Nathaniel Price (natbprice@gmail.com)

Original Matlab Code: Rick Chartrand (rickc@lanl.gov)

References

Rick Chartrand, "Numerical differentiation of noisy, nonsmooth data," ISRN Applied Mathematics, Vol. 2011, Article ID 164564, 2011.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Load small demo data
data("smalldemodata")

# Unpack data
x <- smalldemodata$x
obs <- smalldemodata$obs
true <- smalldemodata$true
dydx_true <- rep(-1, length(x))
dydx_true[x > 0.5] <- 1
dx <- x[2] - x[1]

# Extimate derivative
dydx <- TVRegDiffR(
  data = obs,
  iter = 100,
  alph = 0.2,
  scale = "small",
  ep = 1e-6,
  dx = dx
)
dydx <- dydx[-1]

natbprice/tvdiff documentation built on Jan. 10, 2021, 6:51 a.m.