# The 1d fused lasso
set.seed(0)
n = 100
beta0 = rep(sample(1:10,5),each=n/5)
beta0 = beta0-mean(beta0)
y = beta0 + rnorm(n,sd=0.8)
a = fusedlasso1d(y)
lambda = 4
b1 = coef(a,lambda=lambda)$beta
gamma = 0.5
b2 = softthresh(a,lambda=lambda,gamma=gamma)
plot(1:n,y)
lines(1:n,b1)
lines(1:n,b2,col="red")
legend("topright",lty=1,col=c("black","red"),
legend=c(expression(gamma==0),expression(gamma==0.5)))
Run the code above in your browser using DataLab