library(pracma) options(warn=-1) # turns off warnings, to turn on: "options(warn=0)" # Importing the libraries for (f in list.files(path="nt_toolbox/toolbox_general/", pattern="*.R")) { source(paste("nt_toolbox/toolbox_general/", f, sep="")) } for (f in list.files(path="nt_toolbox/toolbox_signal/", pattern="*.R")) { source(paste("nt_toolbox/toolbox_signal/", f, sep="")) } for (f in list.files(path="nt_toolbox/toolbox_graph/", pattern="*.R")) { source(paste("nt_toolbox/toolbox_graph/", f, sep="")) } set.seed(0) n = 400 p = round(n/4) A = randn(p,n) / sqrt(p) s = 17 sel = sample(c(1 : n)) x0 = zeros(n, 1) x0[sel[1:s]] = 1 y = A %*% x0 proxG = function(x, gamma) {x * pmax(1 - ((gamma) / abs(x)), 0)} options(repr.plot.width=5, repr.plot.height=3.5) t = linspace(-1,1) plot(t, proxG(t, 0.3), type="l", col="blue", ylab="", xlab="") pA = t(A) %*% solve(A%*% t(A)) proxF = function(x,y){x + pA %*% (y - A %*% x)} mu = 1 gamma = 1 rproxG = function(x,tau){2 * proxG(x,tau) - x} rproxF = function(x, tau){2 * proxF(x,tau) - x} niter = 500 source("nt_solutions/optim_4b_dr/exo1.R") # Insert your code here # Insert your code here. # Insert your code here. source("nt_solutions/optim_4b_dr/exo2.R") # Insert your code here. q = 1000 slist = seq(14, 42, 2) Slist = slist[mod(c(1 : q), length(slist)) + 1] # Genetate signals so that |x0(:,j)| has sparsity |Slist(j)|. U = rand(n,q) v = c(apply(U,2,sort)) v = v[c(0: (q - 1)) * n + Slist] x0 = 1 * (U <= t(matrix(rep(v, n), ncol=n))) y = A %*% x0 source("nt_solutions/optim_4b_dr/exo3.R") # Insert your code here.