# Sparse 2d fused lasso
library(genlasso)
set.seed(1)
dim1 = dim2 = 10
n = 100
y = as.numeric(row(diag(dim1)) > 5 & col(diag(dim2)) > 5) * 3 + rnorm(n)
a10 = fusedlasso2d(y, dim1=dim1, dim2=dim2, gamma=0.5, maxsteps=10)
a20 = fusedlasso2d(y, dim1=dim1, dim2=dim2, gamma=0.5, maxsteps=20)
a30 = fusedlasso2d(y, dim1=dim1, dim2=dim2, gamma=0.5, maxsteps=30)
b20 = iterate(a10, moresteps=10)
b30 = iterate(b20, moresteps=10)
# Check for equality; should match on all but 'call'
b20$call = a20$call
b30$call = a30$call
all.equal(target=a20, current=b20)
all.equal(target=a30, current=b30)
Run the code above in your browser using DataLab