# NOT RUN {
##----- A toy example of piecewise constant signal -------
set.seed(0)
n <- 100
x = seq(1/n, 1,length.out = n)
y0 = 0*x; y0[x>0.5] = 1
y = y0 + rnorm(n, sd = 0.1)
fit <- amias(y, k = 1)
plot(fit)
##----- A toy example of piecewise linear trend -------
set.seed(0)
y0 = 2*(0.5-x); y0[x>0.5] = 2*(x[x>0.5]-0.5)
y = y0 + rnorm(n, sd = 0.1)
fit <- amias(y, D_type = "tfq", q = 1, k = 1)
print(fit)
##------ Piecewise constant trend filtering example in Wen et al.(2018).-----
set.seed(1)
data <- SimuBlocks(2048, sigma=0.5)
# with user-specified initialized active set (Here we use the true active set for initialization)
fit <- amias(data$y, k = 11, A = data$SetA)
plot(fit)
lines(data$x, data$y0, type="s") # Add the true signal for reference
# with adjustment
fit <- amias(data$y, k = 11, adjust = TRUE, delta = 20)
plot(fit, main = "Blocks")
lines(data$x, data$y0, type="s") # Add the true signal for reference
##------ Piecewise linear trend filtering example in Wen et al.(2018).-----
set.seed(1)
data <- SimuWave(512)
fit <- amias(data$y, q = 1, D_type = "tfq", k = 8, adjust = TRUE, delta = 30)
plot(fit, main = "Wave")
lines(data$x, data$y0, type="l")
##------ Doppler example in Wen et al.(2018).-----
set.seed(1)
data <- SimuDoppler(1024)
A.ini <- sample(1024,30)
op <- par(mfrow=c(1,2))
fit1 <- amias(data$y, q = 2, D_type = "tfq", k = 30, A = A.ini) # piecewise quadratic
plot(fit1, main = "Doppler")
fit2 <- amias(data$y, q = 3, D_type = "tfq", k = 30, A = A.ini) # piecewise Cubic polynomial
plot(fit2, main = "Doppler")
par(op)
# }
Run the code above in your browser using DataLab