示例#1
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())
示例#2
0
文件: blocks.py 项目: fperez/regreg
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())
示例#3
0
文件: isotonic.py 项目: sowuy/regreg
import numpy as np
import pylab
from scipy import sparse

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

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:]

isotonic = nonnegative.linear(sparse.csr_matrix(D))
loss = signal_approximator(Y)
p = container(loss, isotonic)
solver = FISTA(p.problem(initial=np.zeros(n)))
solver.debug = True

vals = solver.fit(max_its=25000, tol=1e-08, backtrack=True)
soln = solver.problem.coefs

X = np.arange(n)
pylab.clf()
pylab.scatter(X, Y)
pylab.step(X, soln, 'r--')
示例#4
0
文件: isotonic.py 项目: fperez/regreg
import numpy as np
import pylab
from scipy import sparse

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

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:]


isotonic = nonnegative.linear(sparse.csr_matrix(D))
loss = signal_approximator(Y)
p = container(loss, isotonic)
solver=FISTA(p.problem(initial=np.zeros(n)))
solver.debug=True

vals = solver.fit(max_its=25000, tol=1e-08, backtrack=True)
soln = solver.problem.coefs

X = np.arange(n)
pylab.clf()
pylab.scatter(X, Y)
pylab.step(X, soln, 'r--')