In [1]:
from __future__ import division
import time
import numpy as np
import scipy.linalg as lin
import pylab as pl
from locore.algorithms import douglas_rachford
from locore.operators import soft_thresholding
Dimension of the problem
In [2]:
n = 500
p = n // 4
Matrix and observations
In [3]:
A = np.random.randn(p, n)
y = np.random.randn(p, 1)
Operator callbacks
In [4]:
F = lambda x: lin.norm(x, 1)
prox_f = soft_thresholding
prox_g = lambda x, tau: x + np.dot(A.T, lin.solve(np.dot(A, A.T),
y - np.dot(A, x)))
Run
In [5]:
t1 = time.time()
x, fx = douglas_rachford(prox_f, prox_g, np.zeros((n, 1)),
maxiter=1000, full_output=1, retall=0, callback=F)
t2 = time.time()
Show
In [6]:
print "Performed 1000 iterations in " + str(t2 - t1) + " seconds."
pl.plot(fx)
pl.show()