Esempio n. 1
0
def test1():
    import numpy as np
    import pylab
    from scipy import sparse

    from regreg.algorithms import FISTA
    from regreg.atoms import l1norm
    from regreg.container import container
    from regreg.smooth import signal_approximator, smooth_function

    Y = np.random.standard_normal(500)
    Y[100:150] += 7
    Y[250:300] += 14

    sparsity = l1norm(500, l=1.0)
    #Create D
    D = (np.identity(500) + np.diag([-1] * 499, k=1))[:-1]
    D = sparse.csr_matrix(D)
    fused = l1norm(D, l=19.5)

    p = container(loss, sparsity, fused)

    soln1 = blockwise(pen, Y)

    solver = FISTA(p.problem())
    solver.fit(max_its=800, tol=1e-10)
    soln2 = solver.problem.coefs

    #plot solution
    pylab.figure(num=1)
    pylab.clf()
    pylab.scatter(np.arange(Y.shape[0]), Y, c='r')
    pylab.plot(soln1, c='y', linewidth=6)
    pylab.plot(soln2, c='b', linewidth=2)
Esempio n. 2
0
def test1():
    import numpy as np
    import pylab
    from scipy import sparse

    from regreg.algorithms import FISTA
    from regreg.atoms import l1norm
    from regreg.container import container
    from regreg.smooth import signal_approximator, smooth_function

    Y = np.random.standard_normal(500)
    Y[100:150] += 7
    Y[250:300] += 14

    sparsity = l1norm(500, l=1.0)
    # Create D
    D = (np.identity(500) + np.diag([-1] * 499, k=1))[:-1]
    D = sparse.csr_matrix(D)
    fused = l1norm(D, l=19.5)

    p = container(loss, sparsity, fused)

    soln1 = blockwise(pen, Y)

    solver = FISTA(p.problem())
    solver.fit(max_its=800, tol=1e-10)
    soln2 = solver.problem.coefs

    # plot solution
    pylab.figure(num=1)
    pylab.clf()
    pylab.scatter(np.arange(Y.shape[0]), Y, c="r")
    pylab.plot(soln1, c="y", linewidth=6)
    pylab.plot(soln2, c="b", linewidth=2)
Esempio n. 3
0
def test2():

    import numpy as np
    import pylab
    from scipy import sparse

    from regreg.algorithms import FISTA
    from regreg.atoms import l1norm
    from regreg.container import container
    from regreg.smooth import quadratic

    n1, n2 = l1norm(1), l1norm(1)
    Y = np.array([30.])
    loss = quadratic.shift(-Y, lagrange=0.5)
    blockwise([n1, n2], Y)
Esempio n. 4
0
def test1():
    import numpy as np
    import pylab
    from scipy import sparse

    from regreg.algorithms import FISTA
    from regreg.atoms import l1norm
    from regreg.container import container
    from regreg.smooth import quadratic

    Y = np.random.standard_normal(500); Y[100:150] += 7; Y[250:300] += 14

    sparsity = l1norm(500, lagrange=1.0)
    #Create D
    D = (np.identity(500) + np.diag([-1]*499,k=1))[:-1]
    D = sparse.csr_matrix(D)

    fused = l1norm.linear(D, lagrange=19.5)
    loss = quadratic.shift(-Y, lagrange=0.5)

    p = container(loss, sparsity, fused)
    
    soln1 = blockwise([sparsity, fused], Y)

    solver = FISTA(p)
    solver.fit(max_its=800,tol=1e-10)
    soln2 = solver.composite.coefs

    #plot solution
    pylab.figure(num=1)
    pylab.clf()
    pylab.scatter(np.arange(Y.shape[0]), Y, c='r')
    pylab.plot(soln1, c='y', linewidth=6)
    pylab.plot(soln2, c='b', linewidth=2)
Esempio n. 5
0
def test2():

    import numpy as np
    import pylab
    from scipy import sparse

    from regreg.algorithms import FISTA
    from regreg.atoms import l1norm
    from regreg.container import container
    from regreg.smooth import signal_approximator, smooth_function

    n1, n2 = l1norm(1), l1norm(1)
    Y = np.array([30.0])
    l = signal_approximator(Y)
    p = container(l, n1, n2)
    blockwise(s, Y, p.problem())
Esempio n. 6
0
def test2():

    import numpy as np
    import pylab
    from scipy import sparse

    from regreg.algorithms import FISTA
    from regreg.atoms import l1norm
    from regreg.container import container
    from regreg.smooth import signal_approximator, smooth_function

    n1, n2 = l1norm(1), l1norm(1)
    Y = np.array([30.])
    l = signal_approximator(Y)
    p = container(l, n1, n2)
    blockwise(s, Y, p.problem())
Esempio n. 7
0
import pylab
import numpy as np
import scipy.sparse

from regreg.algorithms import FISTA
from regreg.smooth import l2normsq
from regreg.atoms import l1norm, maxnorm
from regreg.seminorm import seminorm


sparsity = l1norm(500, l=1.3)
D = (np.identity(500) + np.diag([-1]*499,k=1))[:-1]
D = scipy.sparse.csr_matrix(D)
fused = l1norm(D, l=20)

penalty = seminorm(sparsity,fused)


Y = np.random.standard_normal(500); Y[100:150] += 7; Y[250:300] += 14
loss = l2normsq.shift(-Y, l=0.5)
problem = loss.add_seminorm(penalty)
solver = FISTA(problem)
solver.fit(max_its=100, tol=1e-10)
solution = solver.problem.coefs

import pylab
pylab.scatter(np.arange(Y.shape[0]), Y, c='r')
pylab.plot(solution, color='yellow', linewidth=5)

l1_fused = np.fabs(D * solution).sum()
l1_sparsity = np.fabs(solution).sum()
Esempio n. 8
0
import pylab
import numpy as np
import scipy.sparse

from regreg.algorithms import FISTA
from regreg.smooth import quadratic
from regreg.atoms import l1norm, maxnorm
from regreg.seminorm import seminorm

D = (np.diag(np.ones(500)) - np.diag(np.ones(499),1))[:-1]
DT = scipy.sparse.csr_matrix(D.T)
D = scipy.sparse.csr_matrix(D)

Y = np.random.standard_normal(500); Y[100:150] += 7; Y[250:300] += 14
loss = quadratic.shift(-Y, l=0.5)
penalty = l1norm(D, l=20)

problem = loss.add_seminorm(seminorm(penalty))
solver = FISTA(problem)
solver.fit(max_its=100, tol=1e-10)
solution = solver.problem.coefs

l1_soln = np.fabs(D * solution).sum()

tfocs_penalty = maxnorm(499, l=l1_soln)
tfocs_loss = quadratic.affine(DT, -Y, l=0.5)
tfocs_loss.coefs = np.zeros(499)
tfocs_problem = tfocs_loss.add_seminorm(tfocs_penalty)
tfocs_solver = FISTA(tfocs_problem)
tfocs_solver.debug = True
tfocs_solver.fit(max_its=1000, tol=1e-10)
Esempio n. 9
0
import numpy as np
import pylab	
from scipy import sparse

from regreg.algorithms import FISTA
from regreg.atoms import l1norm
from regreg.container import container
from regreg.smooth import l2normsq
 
Y = np.random.standard_normal(500); Y[100:150] += 7; Y[250:300] += 14
loss = l2normsq.shift(-Y, coef=0.5)

sparsity = l1norm(len(Y), 1.4)
# TODO should make a module to compute typical Ds
D = sparse.csr_matrix((np.identity(500) + np.diag([-1]*499,k=1))[:-1])
fused = l1norm.linear(D, 25.5)
problem = container(loss, sparsity, fused)
   
solver = FISTA(problem.composite())
solver.fit(max_its=100, tol=1e-10)
solution = solver.composite.coefs

delta1 = np.fabs(D * solution).sum()
delta2 = np.fabs(solution).sum()

fused_constraint = l1norm.linear(D, bound=delta1)
sparsity_constraint = l1norm(500, bound=delta2)

constrained_problem = container(loss, fused_constraint, sparsity_constraint)
constrained_solver = FISTA(constrained_problem.composite())
constrained_solver.composite.lipshitz = 1.01
Esempio n. 10
0
import scipy.sparse

from regreg.algorithms import FISTA
from regreg.smooth import l2normsq
from regreg.atoms import l1norm, maxnorm
from regreg.seminorm import seminorm

D = (np.diag(np.ones(500)) - np.diag(np.ones(499), 1))[:-1]
DT = scipy.sparse.csr_matrix(D.T)
D = scipy.sparse.csr_matrix(D)

Y = np.random.standard_normal(500)
Y[100:150] += 7
Y[250:300] += 14
loss = l2normsq.shift(-Y, l=0.5)
penalty = l1norm(D, l=20)

problem = loss.add_seminorm(seminorm(penalty))
solver = FISTA(problem)
solver.fit(max_its=100, tol=1e-10)
solution = solver.problem.coefs

l1_soln = np.fabs(D * solution).sum()

tfocs_penalty = maxnorm(499, l=l1_soln)
tfocs_loss = l2normsq.affine(DT, -Y, l=0.5)
tfocs_loss.coefs = np.zeros(499)
tfocs_problem = tfocs_loss.add_seminorm(tfocs_penalty)
tfocs_solver = FISTA(tfocs_problem)
tfocs_solver.debug = True
tfocs_solver.fit(max_its=1000, tol=1e-10)
Esempio n. 11
0
import numpy as np
import pylab
from scipy import sparse

from regreg.algorithms import FISTA
from regreg.atoms import l1norm
from regreg.container import container
from regreg.smooth import signal_approximator

Y = np.random.standard_normal(500); Y[100:150] += 7; Y[250:300] += 14

sparsity = l1norm(500, l=1.3)
#Create D
D = (np.identity(500) + np.diag([-1]*499,k=1))[:-1]
D = sparse.csr_matrix(D)
fused = l1norm.linear(D, l=25.5)

loss = signal_approximator(Y)

problem = container(loss, sparsity, fused)
solver = FISTA(problem.problem())
solver.fit(max_its=800,tol=1e-10)
soln = solver.problem.coefs

#plot solution
pylab.figure(num=1)
pylab.clf()
pylab.plot(soln, c='g')
pylab.scatter(np.arange(Y.shape[0]), Y)
    
Esempio n. 12
0
import numpy as np
import pylab
from scipy import sparse

from regreg.algorithms import FISTA
from regreg.atoms import l1norm
from regreg.container import container
from regreg.smooth import l2normsq

Y = np.random.standard_normal(500)
Y[100:150] += 7
Y[250:300] += 14
loss = l2normsq.shift(-Y, coef=0.5)

sparsity = l1norm(len(Y), 1.4)
# TODO should make a module to compute typical Ds
D = sparse.csr_matrix((np.identity(500) + np.diag([-1] * 499, k=1))[:-1])
fused = l1norm.linear(D, 25.5)
problem = container(loss, sparsity, fused)

solver = FISTA(problem.composite())
solver.fit(max_its=100, tol=1e-10)
solution = solver.composite.coefs

delta1 = np.fabs(D * solution).sum()
delta2 = np.fabs(solution).sum()

fused_constraint = l1norm.linear(D, bound=delta1)
sparsity_constraint = l1norm(500, bound=delta2)

constrained_problem = container(loss, fused_constraint, sparsity_constraint)
Esempio n. 13
0
import numpy as np
import pylab
from scipy import sparse

from regreg.algorithms import FISTA
from regreg.atoms import l1norm
from regreg.container import container
from regreg.smooth import signal_approximator

Y = np.random.standard_normal(500)
Y[100:150] += 7
Y[250:300] += 14

sparsity = l1norm(500, l=1.3)
#Create D
D = (np.identity(500) + np.diag([-1] * 499, k=1))[:-1]
D = sparse.csr_matrix(D)
fused = l1norm.linear(D, l=25.5)

loss = signal_approximator(Y)

problem = container(loss, sparsity, fused)
solver = FISTA(problem.problem())
solver.fit(max_its=800, tol=1e-10)
soln = solver.problem.coefs

#plot solution
pylab.figure(num=1)
pylab.clf()
pylab.plot(soln, c='g')
pylab.scatter(np.arange(Y.shape[0]), Y)