import matplotlib.pylab as plt

from pyprox import douglas_rachford
from pyprox.operators import soft_thresholding
from pyprox.context import Context

# Dimension of the problem
n = 500
p = n // 4

# Matrix and observations
A = np.random.randn(p, n)
y = np.random.randn(p, 1)

# operator callbacks
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)))

# context
ctx = Context(full_output=True, maxiter=1000)
ctx.callback = lambda x: lin.norm(x, 1)

t1 = time.time()
x, fx = douglas_rachford(prox_f, prox_g, np.zeros((n, 1)), context=ctx)
t2 = time.time()
print("Performed 1000 iterations in " + str(t2 - t1) + " seconds.")

plt.plot(fx)
plt.show()
import numpy as np
import scipy.linalg as lin
import pylab as pl

from pyprox import douglas_rachford
from pyprox.operators import soft_thresholding

# Dimension of the problem
n = 500
p = n // 4

# Matrix and observations
A = np.random.randn(p, n)
y = np.random.randn(p, 1)

# operator callbacks
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)))

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()
print "Performed 1000 iterations in " + str(t2 - t1) + " seconds."

pl.plot(fx)
pl.show()
Example #3
0
from pyprox import douglas_rachford
from pyprox.operators import soft_thresholding

# Dimension of the problem
n = 500
p = n // 4

# Matrix and observations
A = np.random.randn(p, n)
y = np.random.randn(p, 1)

# operator callbacks
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)))

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()
print "Performed 1000 iterations in " + str(t2 - t1) + " seconds."

pl.plot(fx)
pl.show()
Example #4
0
import matplotlib.pylab as plt

from pyprox import douglas_rachford
from pyprox.operators import soft_thresholding
from pyprox.context import Context

# Dimension of the problem
n = 500
p = n // 4

# Matrix and observations
A = np.random.randn(p, n)
y = np.random.randn(p, 1)

# operator callbacks
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)))

# context
ctx = Context(full_output=True, maxiter=1000)
ctx.callback = lambda x: lin.norm(x, 1)

t1 = time.time()
x, fx = douglas_rachford(prox_f, prox_g, np.zeros((n, 1)), context=ctx)
t2 = time.time()
print("Performed 1000 iterations in " + str(t2 - t1) + " seconds.")

plt.plot(fx)
plt.show()
# modules
import time

import numpy as np
import pylab as plt

from pyprox import douglas_rachford

# Dimension of the problem
n = 500
p = n//4

# Matrix and observations
A = np.random.randn(p,n)
y = np.random.randn(p,1)

# operator callbacks
F = lambda x: np.linalg.norm(x,1)
ProxF = soft_thresholding
ProxG = lambda x,tau: x + np.dot(A.T, np.linalg.solve(np.dot(A,A.T),
    y - np.dot(A,x)))

t1 = time.time()
x, fx = douglas_rachford(ProxF, ProxG, np.zeros((n,1)),
    maxiter=1000, full_output=1, retall=0, callback=F)
t2 = time.time()
print "Performed 1000 iterations in " + str(t2-t1) + " seconds."

plt.plot(fx)
plt.show()