コード例 #1
0
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()

new_fused = l1norm(D, l=l1_fused)
new_sparsity = l1norm(500, l=l1_sparsity)
conjugate = l2normsq.shift(Y, l=0.5)
コード例 #2
0
ファイル: nearlyisotonic.py プロジェクト: sowuy/regreg
import pylab
from scipy import sparse

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

n = 100
Y = np.random.standard_normal(n)
Y[:-30] += np.arange(n - 30) * 0.2

D = (np.identity(n) - np.diag(np.ones(n - 1), -1))[1:]
nisotonic = positive_part.linear(-sparse.csr_matrix(D), l=3)

loss = l2normsq.shift(-Y, l=0.5)
p = container(loss, nisotonic)
solver = FISTA(p.problem())

vals = solver.fit(max_its=25000, tol=1e-05)
soln = solver.problem.coefs.copy()

nisotonic.atoms[0].l = 100.
solver.fit(max_its=25000, tol=1e-05)
soln2 = solver.problem.coefs.copy()

nisotonic.atoms[0].l = 1000.
solver.fit(max_its=25000, tol=1e-05)
soln3 = solver.problem.coefs.copy()

X = np.arange(n)
コード例 #3
0
ファイル: constrained.py プロジェクト: Xiaoying-Tian/regreg
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
コード例 #4
0
ファイル: nearlyisotonic.py プロジェクト: fperez/regreg
from regreg.algorithms import FISTA
from regreg.atoms import positive_part
from regreg.container import container
from regreg.smooth import l2normsq


n = 100
Y = np.random.standard_normal(n)
Y[:-30] += np.arange(n-30) * 0.2

D = (np.identity(n) - np.diag(np.ones(n-1),-1))[1:]
nisotonic = positive_part.linear(-sparse.csr_matrix(D), l=3)


loss = l2normsq.shift(-Y,l=0.5)
p = container(loss, nisotonic)
solver=FISTA(p.problem())

vals = solver.fit(max_its=25000, tol=1e-05)
soln = solver.problem.coefs.copy()

nisotonic.atoms[0].l = 100.
solver.fit(max_its=25000, tol=1e-05)
soln2 = solver.problem.coefs.copy()

nisotonic.atoms[0].l = 1000.
solver.fit(max_its=25000, tol=1e-05)
soln3 = solver.problem.coefs.copy()

X = np.arange(n)
コード例 #5
0
ファイル: constrained.py プロジェクト: vishalbelsare/regreg
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)