affine.factored_matrix

Module: affine.factored_matrix

Inheritance diagram for regreg.affine.factored_matrix:

digraph inheritance06cbf8477c { rankdir=LR; size="8.0, 12.0"; "affine.factored_matrix.factored_matrix" [URL="#regreg.affine.factored_matrix.factored_matrix",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="A class for storing the SVD of a linear_tranform. "]; "affine.factored_matrix.nuclear_norm" [URL="#regreg.affine.factored_matrix.nuclear_norm",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="The nuclear norm"]; "atoms.svd_norms.nuclear_norm" -> "affine.factored_matrix.nuclear_norm" [arrowsize=0.5,style="setlinewidth(0.5)"]; "affine.factored_matrix.operator_norm" [URL="#regreg.affine.factored_matrix.operator_norm",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "atoms.svd_norms.operator_norm" -> "affine.factored_matrix.operator_norm" [arrowsize=0.5,style="setlinewidth(0.5)"]; "atoms.seminorms.seminorm" [URL="regreg.atoms.seminorms.html#regreg.atoms.seminorms.seminorm",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="An atom that can be in lagrange or bound form."]; "regreg.atoms.atom" -> "atoms.seminorms.seminorm" [arrowsize=0.5,style="setlinewidth(0.5)"]; "atoms.svd_norms.nuclear_norm" [URL="regreg.atoms.svd_norms.html#regreg.atoms.svd_norms.nuclear_norm",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="The nuclear norm"]; "atoms.svd_norms.svd_atom" -> "atoms.svd_norms.nuclear_norm" [arrowsize=0.5,style="setlinewidth(0.5)"]; "atoms.svd_norms.operator_norm" [URL="regreg.atoms.svd_norms.html#regreg.atoms.svd_norms.operator_norm",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="The operator norm"]; "atoms.svd_norms.svd_atom" -> "atoms.svd_norms.operator_norm" [arrowsize=0.5,style="setlinewidth(0.5)"]; "atoms.svd_norms.svd_atom" [URL="regreg.atoms.svd_norms.html#regreg.atoms.svd_norms.svd_atom",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "atoms.seminorms.seminorm" -> "atoms.svd_norms.svd_atom" [arrowsize=0.5,style="setlinewidth(0.5)"]; "problems.composite.composite" [URL="regreg.problems.composite.html#regreg.problems.composite.composite",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="A generic way to specify a problem in composite form."]; "problems.composite.nonsmooth" [URL="regreg.problems.composite.html#regreg.problems.composite.nonsmooth",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="A composite subclass that explicitly returns 0"]; "problems.composite.composite" -> "problems.composite.nonsmooth" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.atoms.atom" [URL="regreg.atoms.html#regreg.atoms.atom",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="A class that defines the API for support functions."]; "problems.composite.nonsmooth" -> "regreg.atoms.atom" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

This module contains the implementation operator and nuclear norms, used in matrix completion problems and other low-rank factorization problems.

Classes

factored_matrix

class regreg.affine.factored_matrix.factored_matrix(linear_operator, min_singular=0.0, tol=1e-05, initial_rank=None, initial=None, affine_offset=None, debug=False)

Bases: object

A class for storing the SVD of a linear_tranform. Has affine_transform attributes like linear_map.

__init__(linear_operator, min_singular=0.0, tol=1e-05, initial_rank=None, initial=None, affine_offset=None, debug=False)

Initialize self. See help(type(self)) for accurate signature.

property X
adjoint_map(x)
affine_map(x)
copy()
property factors
linear_map(x)
offset_map(x, copy=False)

nuclear_norm

class regreg.affine.factored_matrix.nuclear_norm(shape, lagrange=None, bound=None, offset=None, quadratic=None, initial=None, initial_rank=10, warm_start=None)

Bases: regreg.atoms.svd_norms.nuclear_norm

The nuclear norm

__init__(shape, lagrange=None, bound=None, offset=None, quadratic=None, initial=None, initial_rank=10, warm_start=None)

Initialize self. See help(type(self)) for accurate signature.

classmethod affine(linear_operator, offset, lagrange=None, diag=False, bound=None, quadratic=None)

This is the same as the linear class method but with offset as a positional argument

apply_offset(x)

If self.offset is not None, return x-self.offset, else return x.

property bound
bound_prox(X, bound=None)

Return unique minimizer

\[{B}^{\delta}(\theta) = \text{argmin}_{B \in \mathbb{R}^{{n \times p}}} \frac{1}{2} \|\theta-B\|^2_2 \ \text{s.t.} \ \|B\|_* \leq \delta\]

where \(\delta\) is the bound parameter and \(\theta\) is arg.

If the argument bound is None and the atom is in bound mode, self.bound is used as the bound parameter, else an exception is raised.

The class atom’s bound_prox just returns the appropriate bound parameter for use by the subclasses.

Parameters

arg : np.ndarray(np.float)

Argument of the proximal map.

bound : float (optional)

Bound for the constraint on the seminorm. Defaults to self.bound.

Returns

Z : np.ndarray(np.float)

The proximal map of arg.

static check_subgradient(atom, prox_center)

For a given seminorm, verify the KKT condition for the problem for the proximal problem

\[\text{minimize}_u \frac{1}{2} \|u-z\|^2_2 + h(z)\]

where \(z\) is the prox_center and \(h\) is atom which may be in Lagrange or bound form.

If the atom is in Lagrange form, this function should return two values equal to the seminorm of the minimizer. If it is bound form it should return two values equal to the dual seminorm of the residual, i.e. the prox_center minus the minimizer.

Parameters

atom : seminorm

prox_center : np.ndarray(np.float)

Center for the proximal map.

Returns

v1, v2 : float

Two values that should be equal if the proximal map is correct.

property conjugate

The conjugate of an atom.

constraint(X, bound=None)

Verify \(\|B\|_* \leq \delta\), where \(\delta\) is bound.

If the result is True, returns 0, else returns np.inf.

The class seminorm’s constraint just returns the appropriate bound parameter for use by the subclasses.

property dual
get_bound()

Get method of the bound property.

>>> import regreg.api as rr
>>> constraint = rr.nuclear_norm((5,4), bound=2.3) 
>>> constraint.bound
2.3
get_conjugate()

Return the conjugate of an given atom.

>>> import regreg.api as rr
>>> penalty = rr.nuclear_norm((5,4), lagrange=3.4)
>>> penalty.get_conjugate() 
operator_norm(..., bound=3.4...)
get_dual()

Return the dual of an atom. This dual is formed by making introducing new variables \(v=Ax\) where \(A\) is self.linear_transform.

>>> import regreg.api as rr
>>> penalty = rr.nuclear_norm((5,4), lagrange=2.3)
>>> penalty 
nuclear_norm(..., lagrange=2.3...)
>>> penalty.dual 
(<regreg.affine.identity object at 0x...>, operator_norm(..., bound=2.3...))

If there is a linear part to the penalty, the linear_transform may not be identity. For example, the 1D fused LASSO penalty:

>>> D = (np.identity(4) + np.diag(-np.ones(3),1))[:-1]
>>> D
array([[ 1., -1.,  0.,  0.],
       [ 0.,  1., -1.,  0.],
       [ 0.,  0.,  1., -1.]])
>>> linear_atom = rr.l1norm.linear(D, lagrange=2.3)
>>> linear_atom 
affine_atom(l1norm((3,), lagrange=2.3...), array([[ 1., -1.,  0.,  0.],
       [ 0.,  1., -1.,  0.],
       [ 0.,  0.,  1., -1.]]))
>>> linear_atom.dual 
(<regreg.affine.linear_transform object at 0x...>, supnorm((3,), bound=2.3...))
get_lagrange()

Get method of the lagrange property.

>>> import regreg.api as rr
>>> penalty = rr.nuclear_norm((5,4), lagrange=3.4)
>>> penalty.lagrange
3.4
get_offset()
get_quadratic()

Get the quadratic part of the composite.

property lagrange
lagrange_prox(X, lipschitz=1, lagrange=None)

Return unique minimizer

\[{B}^{\lambda}(\theta) = \text{argmin}_{B \in \mathbb{R}^{{n \times p}}} \frac{L}{2} \|\theta-B\|^2_2 + \lambda \|B\|_* \]

Above, \(\lambda\) is the Lagrange parameter and \(L\) is the Lipschitz parameter and \(\theta\) is arg.

If the argument lagrange is None and the atom is in lagrange mode, self.lagrange is used as the lagrange parameter, else an exception is raised.

The class atom’s lagrange_prox just returns the appropriate lagrange parameter for use by the subclasses.

Parameters

arg : np.ndarray(np.float)

Argument of the proximal map.

lipschitz : float

Coefficient in front of the quadratic.

lagrange : float (optional)

Lagrange factor in front of the seminorm. Defaults to self.lagrange.

Returns

Z : np.ndarray(np.float)

The proximal map of arg.

latexify(var=None, idx='')

Return a LaTeX representation of an object.

>>> import regreg.api as rr
>>> penalty = rr.l1norm(10, lagrange=0.9)
>>> penalty.latexify(var=r'\gamma') 
'\\lambda_{} \\|\\gamma\\|_1'
Parameters

var : string

Argument of the functions

idx : string

Optional subscript index.

Returns

L : string

A LaTeX representation of the atom.

classmethod linear(linear_operator, lagrange=None, diag=False, bound=None, quadratic=None, offset=None)
property linear_transform

The linear transform applied before a penalty is computed. Defaults to regreg.affine.identity

>>> from regreg.api import l1norm
>>> penalty = l1norm(30, lagrange=3.4)
>>> type(penalty.linear_transform)
<class 'regreg.affine.identity'>
nonsmooth_objective(arg, check_feasibility=False)

The nonsmooth objective function of the atom. Includes self.quadratic.objective(arg).

>>> import regreg.api as rr
>>> penalty = rr.l1norm(4, lagrange=2)
>>> penalty.nonsmooth_objective([3, 4, 5, 9])
42.0
>>> 2 * sum([3, 4, 5, 9])
42
Parameters

arg : np.ndarray(np.float)

Argument of the seminorm.

check_feasibility : bool

If True, then return np.inf if appropriate.

Returns

value : np.float

The seminorm of arg.

objective(x, check_feasibility=False)
objective_template = '\\|%(var)s\\|_*'
objective_vars = {'dualnormklass': 'operator_norm', 'initargs': '(5,4)', 'linear': 'D', 'normklass': 'nuclear_norm', 'offset': '\\alpha', 'shape': '{n \\times p}', 'var': 'B'}
property offset
prox_tol = 1e-05
proximal(quadratic, prox_control=None)

The proximal operator. If the atom is in Lagrange mode, this has the form

\[B^{\lambda}(\theta) = \text{argmin}_{B \in \mathbb{R}^{{n \times p}}} \frac{L}{2} \|\theta-B\|^2_2 + \lambda h(B-\alpha) + \langle B, \eta \rangle\]

where \(\alpha\) is self.offset, \(\eta\) is quadratic.linear_term, \(\theta\) is quadratic.center and

\[h(B) = \|B\|_*\]

If the atom is in bound mode, then this has the form

\[B^{\delta}(\theta) = \text{argmin}_{B \in \mathbb{R}^{{n \times p}}} \frac{L}{2} \|\theta-B\|^2_2 + \langle B, \eta \rangle \ \text{s.t.} \ h(B - \alpha) \leq \delta\]
>>> import regreg.api as rr
>>> penalty = rr.l1norm(4, lagrange=2)
>>> Q = rr.identity_quadratic(1.5, [3, -4, -1, 1], 0, 0)
>>> penalty.proximal(Q) 
array([ 1.6666..., -2.6666..., -0.        ,  0.        ])
Parameters

quadratic : regreg.identity_quadratic.identity_quadratic

A quadratic added to the atom before minimizing.

prox_control : [None, dict]

This argument is ignored for seminorms, but otherwise is passed to regreg.algorithms.FISTA if the atom needs to be solved iteratively.

Returns

Z : np.ndarray(np.float)

The proximal map of the implied center of quadratic.

proximal_optimum(quadratic)
proximal_step(quadratic, prox_control=None)

Compute the proximal optimization

Parameters

prox_control: [None, dict]

If not None, then a dictionary of parameters for the prox procedure

property quadratic

Quadratic part of the object, instance of regreg.identity_quadratic.identity_quadratic.

seminorm(X, check_feasibility=False, lagrange=None)

Return \(\lambda \cdot \|B\|_*\), where \(\lambda\) is lagrange. If check_feasibility is True, and seminorm is unbounded, will return np.inf if appropriate.

The class seminorm’s seminorm just returns the appropriate lagrange parameter for use by the subclasses.

set_bound(bound)

Set method of the bound property.

>>> import regreg.api as rr
>>> constraint = rr.nuclear_norm((5,4), bound=3.4) 
>>> constraint.bound
3.4
>>> constraint.bound = 2.3
>>> constraint.bound
2.3
>>> penalty = rr.nuclear_norm((5,4), lagrange=2.3)
>>> penalty.bound = 3.4 
Traceback (most recent call last):
...
AttributeError: atom is in lagrange mode
set_lagrange(lagrange)

Set method of the lagrange property.

>>> import regreg.api as rr
>>> penalty = rr.nuclear_norm((5,4), lagrange=3.4)
>>> penalty.lagrange
3.4
>>> penalty.lagrange = 2.3
>>> penalty.lagrange
2.3
>>> constraint = rr.nuclear_norm((5,4), bound=3.4)
>>> constraint.lagrange = 3.4 
Traceback (most recent call last):
...
AttributeError: atom is in bound mode
set_offset(value)
set_quadratic(quadratic)

Set the quadratic part of the composite.

classmethod shift(offset, lagrange=None, diag=False, bound=None, quadratic=None)
smooth_objective(x, mode='both', check_feasibility=False)

The zero function.

smoothed(smoothing_quadratic)

Add quadratic smoothing term

solve(quadratic=None, return_optimum=False, **fit_args)
svd_tol = 1e-05
tol = 1e-05

operator_norm

class regreg.affine.factored_matrix.operator_norm(shape, lagrange=None, bound=None, offset=None, quadratic=None, initial=None, initial_rank=10, warm_start=None)

Bases: regreg.atoms.svd_norms.operator_norm

__init__(shape, lagrange=None, bound=None, offset=None, quadratic=None, initial=None, initial_rank=10, warm_start=None)

Initialize self. See help(type(self)) for accurate signature.

classmethod affine(linear_operator, offset, lagrange=None, diag=False, bound=None, quadratic=None)

This is the same as the linear class method but with offset as a positional argument

apply_offset(x)

If self.offset is not None, return x-self.offset, else return x.

property bound
bound_prox(X, bound=None)

Return unique minimizer

\[{B}^{\delta}(\theta) = \text{argmin}_{B \in \mathbb{R}^{{n \times p}}} \frac{1}{2} \|\theta-B\|^2_2 \ \text{s.t.} \ \|B\|_{\text{op}} \leq \delta\]

where \(\delta\) is the bound parameter and \(\theta\) is arg.

If the argument bound is None and the atom is in bound mode, self.bound is used as the bound parameter, else an exception is raised.

The class atom’s bound_prox just returns the appropriate bound parameter for use by the subclasses.

Parameters

arg : np.ndarray(np.float)

Argument of the proximal map.

bound : float (optional)

Bound for the constraint on the seminorm. Defaults to self.bound.

Returns

Z : np.ndarray(np.float)

The proximal map of arg.

static check_subgradient(atom, prox_center)

For a given seminorm, verify the KKT condition for the problem for the proximal problem

\[\text{minimize}_u \frac{1}{2} \|u-z\|^2_2 + h(z)\]

where \(z\) is the prox_center and \(h\) is atom which may be in Lagrange or bound form.

If the atom is in Lagrange form, this function should return two values equal to the seminorm of the minimizer. If it is bound form it should return two values equal to the dual seminorm of the residual, i.e. the prox_center minus the minimizer.

Parameters

atom : seminorm

prox_center : np.ndarray(np.float)

Center for the proximal map.

Returns

v1, v2 : float

Two values that should be equal if the proximal map is correct.

property conjugate

The conjugate of an atom.

constraint(X, bound=None)

Verify \(\|B\|_{\text{op}} \leq \delta\), where \(\delta\) is bound.

If the result is True, returns 0, else returns np.inf.

The class seminorm’s constraint just returns the appropriate bound parameter for use by the subclasses.

property dual
get_bound()

Get method of the bound property.

>>> import regreg.api as rr
>>> constraint = rr.operator_norm((5,4), bound=2.3) 
>>> constraint.bound
2.3
get_conjugate()

Return the conjugate of an given atom.

>>> import regreg.api as rr
>>> penalty = rr.operator_norm((5,4), lagrange=3.4)
>>> penalty.get_conjugate() 
nuclear_norm(..., bound=3.4...)
get_dual()

Return the dual of an atom. This dual is formed by making introducing new variables \(v=Ax\) where \(A\) is self.linear_transform.

>>> import regreg.api as rr
>>> penalty = rr.operator_norm((5,4), lagrange=2.3)
>>> penalty 
operator_norm(..., lagrange=2.3...)
>>> penalty.dual 
(<regreg.affine.identity object at 0x...>, nuclear_norm(..., bound=2.3...))

If there is a linear part to the penalty, the linear_transform may not be identity. For example, the 1D fused LASSO penalty:

>>> D = (np.identity(4) + np.diag(-np.ones(3),1))[:-1]
>>> D
array([[ 1., -1.,  0.,  0.],
       [ 0.,  1., -1.,  0.],
       [ 0.,  0.,  1., -1.]])
>>> linear_atom = rr.l1norm.linear(D, lagrange=2.3)
>>> linear_atom 
affine_atom(l1norm((3,), lagrange=2.3...), array([[ 1., -1.,  0.,  0.],
       [ 0.,  1., -1.,  0.],
       [ 0.,  0.,  1., -1.]]))
>>> linear_atom.dual 
(<regreg.affine.linear_transform object at 0x...>, supnorm((3,), bound=2.3...))
get_lagrange()

Get method of the lagrange property.

>>> import regreg.api as rr
>>> penalty = rr.operator_norm((5,4), lagrange=3.4)
>>> penalty.lagrange
3.4
get_offset()
get_quadratic()

Get the quadratic part of the composite.

property lagrange
lagrange_prox(X, lipschitz=1, lagrange=None)

Return unique minimizer

\[{B}^{\lambda}(\theta) = \text{argmin}_{B \in \mathbb{R}^{{n \times p}}} \frac{L}{2} \|\theta-B\|^2_2 + \lambda \|B\|_{\text{op}} \]

Above, \(\lambda\) is the Lagrange parameter and \(L\) is the Lipschitz parameter and \(\theta\) is arg.

If the argument lagrange is None and the atom is in lagrange mode, self.lagrange is used as the lagrange parameter, else an exception is raised.

The class atom’s lagrange_prox just returns the appropriate lagrange parameter for use by the subclasses.

Parameters

arg : np.ndarray(np.float)

Argument of the proximal map.

lipschitz : float

Coefficient in front of the quadratic.

lagrange : float (optional)

Lagrange factor in front of the seminorm. Defaults to self.lagrange.

Returns

Z : np.ndarray(np.float)

The proximal map of arg.

latexify(var=None, idx='')

Return a LaTeX representation of an object.

>>> import regreg.api as rr
>>> penalty = rr.l1norm(10, lagrange=0.9)
>>> penalty.latexify(var=r'\gamma') 
'\\lambda_{} \\|\\gamma\\|_1'
Parameters

var : string

Argument of the functions

idx : string

Optional subscript index.

Returns

L : string

A LaTeX representation of the atom.

classmethod linear(linear_operator, lagrange=None, diag=False, bound=None, quadratic=None, offset=None)
property linear_transform

The linear transform applied before a penalty is computed. Defaults to regreg.affine.identity

>>> from regreg.api import l1norm
>>> penalty = l1norm(30, lagrange=3.4)
>>> type(penalty.linear_transform)
<class 'regreg.affine.identity'>
nonsmooth_objective(arg, check_feasibility=False)

The nonsmooth objective function of the atom. Includes self.quadratic.objective(arg).

>>> import regreg.api as rr
>>> penalty = rr.l1norm(4, lagrange=2)
>>> penalty.nonsmooth_objective([3, 4, 5, 9])
42.0
>>> 2 * sum([3, 4, 5, 9])
42
Parameters

arg : np.ndarray(np.float)

Argument of the seminorm.

check_feasibility : bool

If True, then return np.inf if appropriate.

Returns

value : np.float

The seminorm of arg.

objective(x, check_feasibility=False)
objective_template = '\\|%(var)s\\|_{\\text{op}}'
objective_vars = {'dualnormklass': 'nuclear_norm', 'initargs': '(5,4)', 'linear': 'D', 'normklass': 'operator_norm', 'offset': '\\alpha', 'shape': '{n \\times p}', 'var': 'B'}
property offset
prox_tol = 1e-05
proximal(quadratic, prox_control=None)

The proximal operator. If the atom is in Lagrange mode, this has the form

\[B^{\lambda}(\theta) = \text{argmin}_{B \in \mathbb{R}^{{n \times p}}} \frac{L}{2} \|\theta-B\|^2_2 + \lambda h(B-\alpha) + \langle B, \eta \rangle\]

where \(\alpha\) is self.offset, \(\eta\) is quadratic.linear_term, \(\theta\) is quadratic.center and

\[h(B) = \|B\|_{\text{op}}\]

If the atom is in bound mode, then this has the form

\[B^{\delta}(\theta) = \text{argmin}_{B \in \mathbb{R}^{{n \times p}}} \frac{L}{2} \|\theta-B\|^2_2 + \langle B, \eta \rangle \ \text{s.t.} \ h(B - \alpha) \leq \delta\]
>>> import regreg.api as rr
>>> penalty = rr.l1norm(4, lagrange=2)
>>> Q = rr.identity_quadratic(1.5, [3, -4, -1, 1], 0, 0)
>>> penalty.proximal(Q) 
array([ 1.6666..., -2.6666..., -0.        ,  0.        ])
Parameters

quadratic : regreg.identity_quadratic.identity_quadratic

A quadratic added to the atom before minimizing.

prox_control : [None, dict]

This argument is ignored for seminorms, but otherwise is passed to regreg.algorithms.FISTA if the atom needs to be solved iteratively.

Returns

Z : np.ndarray(np.float)

The proximal map of the implied center of quadratic.

proximal_optimum(quadratic)
proximal_step(quadratic, prox_control=None)

Compute the proximal optimization

Parameters

prox_control: [None, dict]

If not None, then a dictionary of parameters for the prox procedure

property quadratic

Quadratic part of the object, instance of regreg.identity_quadratic.identity_quadratic.

seminorm(X, check_feasibility=False, lagrange=None)

Return \(\lambda \cdot \|B\|_{\text{op}}\), where \(\lambda\) is lagrange. If check_feasibility is True, and seminorm is unbounded, will return np.inf if appropriate.

The class seminorm’s seminorm just returns the appropriate lagrange parameter for use by the subclasses.

set_bound(bound)

Set method of the bound property.

>>> import regreg.api as rr
>>> constraint = rr.operator_norm((5,4), bound=3.4) 
>>> constraint.bound
3.4
>>> constraint.bound = 2.3
>>> constraint.bound
2.3
>>> penalty = rr.operator_norm((5,4), lagrange=2.3)
>>> penalty.bound = 3.4 
Traceback (most recent call last):
...
AttributeError: atom is in lagrange mode
set_lagrange(lagrange)

Set method of the lagrange property.

>>> import regreg.api as rr
>>> penalty = rr.operator_norm((5,4), lagrange=3.4)
>>> penalty.lagrange
3.4
>>> penalty.lagrange = 2.3
>>> penalty.lagrange
2.3
>>> constraint = rr.operator_norm((5,4), bound=3.4)
>>> constraint.lagrange = 3.4 
Traceback (most recent call last):
...
AttributeError: atom is in bound mode
set_offset(value)
set_quadratic(quadratic)

Set the quadratic part of the composite.

classmethod shift(offset, lagrange=None, diag=False, bound=None, quadratic=None)
smooth_objective(x, mode='both', check_feasibility=False)

The zero function.

smoothed(smoothing_quadratic)

Add quadratic smoothing term

solve(quadratic=None, return_optimum=False, **fit_args)
svd_tol = 0.0001
tol = 1e-05

Functions

regreg.affine.factored_matrix.compute_iterative_svd(transform, initial_rank=None, warm_start=None, min_singular=1e-16, tol=1e-05, debug=False, stopping_rule=None, padding=5, update_rank=<function <lambda>>, max_rank=None)

Compute the SVD of a matrix using partial_svd.

If no initial rank is given, it assumes a rank of size min(n,p) / 10.

Iteratively calls partial_svd() until the singular_values are small enough.

Parameters

transform : [linear_transform, ndarray]

Linear_transform whose SVD is computed. If an ndarray, it is first cast with astransform()

initial_rank : None or int, optional

A guess at the rank of the matrix.

warm_start : np.ndarray(np.float), optional

A guess at the left singular vectors of the matrix. For fat matrices, these should be right singular vectors, while for tall matrices these should be left singular vectors.

min_singular : np.float, optional

Stop when the singular value has this relative tolerance.

tol: np.float, optional

Tolerance at which the norm of the singular values are deemed to have converged.

debug: bool, optional

Print debugging statements.

stopping_rule : None or callable, optional

Function of the singular values D, returning True | False, used to determine whether to stop. Continue while stopping_rule(D) == False, or when stopping_rule is None.

padding : int, optional

How many more singular vectors are found.

update_rank : callable, optional

A rule to update rank, defaults to doubling the rank.

max_rank : None or int, optional

Largest rank considered. Defaults to 2 * min(transform.output_shape[0], transform.input_shape[0]). An exception is raised if algorithm exceeds given value.

Returns

U, D, VT, Ufull : np.ndarray(np.float)

An SVD of the transform. Ufull is the full set of left singular vectors found.

Examples

>>> import regreg.api as rr
>>> np.random.seed(0)
>>> X = np.random.standard_normal((100, 200))
>>> U, D, VT = rr.compute_iterative_svd(X)[:3]
>>> np.linalg.norm(np.dot(U.T, U) - np.identity(100)) < 1.e-6
True
>>> np.linalg.norm(np.dot(VT, VT.T) - np.identity(100)) < 1.e-6
True
regreg.affine.factored_matrix.partial_svd(transform, rank=1, padding=5, max_its=1000, tol=1e-08, warm_start=None, return_full=False, debug=False, stopping_rule=None)

Compute partial SVD of the linear transform transform

Uses the Mazumder/Hastie algorithm in (TODO: CITE)

Parameters

transform : [linear_transform, ndarray]

Linear_transform whose SVD is computed. If an ndarray, it is first cast with astransform()

rank : int, optional

What rank of SVD to compute.

padding : int, optional

Compute a few further singular values / vectors. This results in a better estimator of the rank of interest.

max_its : int, optional

How many iterations of the full cycle to complete.

tol : np.float, optional

Tolerance at which the norm of the singular values are deemed to have converged.

warm_start : np.ndarray(np.float), optional

A guess at the singular vectors of the matrix. For fat matrices, these should be right singular vectors, while for tall matrices these should be left singular vectors.

return_full: bool, optional

Return a singular values / vectors from padding?

debug: bool, optional

Print debugging statements.

stopping_rule : callable

Function of the singular values used to determine whether to stop.

Returns

U, D, VT, Ufull : np.ndarray(np.float)

An SVD up to rank of the transform. Ufull is the full set of left singular vectors found.

Examples

>>> from regreg.affine.factored_matrix import partial_svd
>>> np.random.seed(0)
>>> X = np.random.standard_normal((100, 200))
>>> U, D, VT = partial_svd(X, rank=10)[:3]
>>> assert(np.linalg.norm(np.dot(U.T, U) - np.identity(10)) < 1.e-4)
>>> assert(np.linalg.norm(np.dot(VT, VT.T) - np.identity(10)) < 1.e-4)
>>> U_np, D_np, VT_np = np.linalg.svd(X, full_matrices=False)
>>> assert(np.linalg.norm(U - np.dot(U, np.dot(U_np.T[:10], U_np[:,:10]))) < 1.e-4)
>>> assert(np.linalg.norm(VT - np.dot(VT, np.dot(VT_np[:10].T, VT_np[:10]))) < 1.e-4)