atoms.linear_constraints¶
Module: atoms.linear_constraints
¶
Inheritance diagram for regreg.atoms.linear_constraints
:
Classes¶
linear_constraint
¶
-
class
regreg.atoms.linear_constraints.
linear_constraint
(shape, basis, offset=None, initial=None, quadratic=None)¶ Bases:
regreg.atoms.cones.cone
This class allows specifications of linear constraints of the form \(x \in ext{row}(L)\) by specifying an orthonormal basis for the rowspace of \(L\).
If the constraint is of the form \(Ax=0\), then this linear constraint can be created using the linear classmethod of the zero cone in regreg.cones.
-
__init__
(shape, basis, offset=None, initial=None, quadratic=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
classmethod
affine
(linear_operator, offset, diag=False, quadratic=None)¶
-
apply_offset
(x)¶ If self.offset is not None, return x-self.offset, else return x.
-
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.
This should return two values that are 0, one is the inner product of the minimizer and the residual, the other is just 0.
- Parameters
atom : cone
A cone instance with a proximal method.
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.
-
cone_prox
(x)¶ Return (unique) minimizer
\[\beta^{\lambda}(u) = \text{argmin}_{\beta \in \mathbb{R}^p} \frac{1}{2} \|\beta-u\|^2_2 + \|\beta\|\]
-
property
conjugate
¶
-
constraint
(x)¶ The constraint
\[\|\beta\|\]
-
property
dual
¶
-
get_conjugate
()¶ Return the conjugate of an given atom.
>>> import regreg.api as rr >>> penalty = rr.projection((4,), [[1,0,0,0],[0,1,0,0]]) >>> penalty.get_conjugate() projection_complement((4,), [[1,0,0,0],[0,1,0,0]], offset=None)
-
get_dual
()¶ Return the dual of an atom. This dual is formed by making the substitution \(v=Ax\) where \(A\) is the self.linear_transform.
>>> import regreg.api as rr >>> penalty = rr.nonnegative((30,)) >>> penalty nonnegative((30,), offset=None) >>> penalty.dual (<regreg.affine.identity object at 0x...>, nonpositive((30,), offset=None))
If there is a linear part to the penalty, the linear_transform may not be identity:
>>> 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.nonnegative.linear(D) >>> linear_atom affine_cone(nonnegative((3,), offset=None), array([[ 1., -1., 0., 0.], [ 0., 1., -1., 0.], [ 0., 0., 1., -1.]])) >>> linear_atom.dual (<regreg.affine.linear_transform object at 0x...>, nonpositive((3,), offset=None))
-
get_offset
()¶
-
get_quadratic
()¶ Get the quadratic part of the composite.
-
latexify
(var=None, idx='')¶
-
classmethod
linear
(linear_operator, basis, diag=False, linear_term=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
(x, check_feasibility=False)¶ >>> import regreg.api as rr >>> cone = rr.nonnegative(4) >>> cone.nonsmooth_objective([3, 4, 5, 9]) 0.0
-
objective
(x, check_feasibility=False)¶
-
objective_template
= '\\|%(var)s\\|'¶
-
objective_vars
= {'coneklass': 'projection', 'dualconeklass': 'projection_complement', 'initargs': '(4,), [[1,0,0,0],[0,1,0,0]]', 'linear': 'D', 'offset': '\\alpha', 'shape': 'p', 'var': '\\beta'}¶
-
property
offset
¶
-
proximal
(quadratic, prox_control=None)¶ The proximal operator.
\[v^{\lambda}(x) = \text{argmin}_{v \in \mathbb{R}^{p}} \frac{L}{2} \|x-\alpha - v\|^2_2 + \|\beta\| + \langle v, \eta \rangle\]where \(\alpha\) is self.offset, \(\eta\) is quadratic.linear_term.
>>> import regreg.api as rr >>> cone = rr.nonnegative((4,)) >>> Q = rr.identity_quadratic(1.5, [3, -4, -1, 1], 0, 0) >>> np.allclose(cone.proximal(Q), [3, 0, 0, 1]) True
- 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.
-
set_offset
(value)¶
-
set_quadratic
(quadratic)¶ Set the quadratic part of the composite.
-
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)¶
-
tol
= 1e-05¶
-
projection
¶
-
class
regreg.atoms.linear_constraints.
projection
(shape, basis, offset=None, initial=None, quadratic=None)¶ Bases:
regreg.atoms.linear_constraints.linear_constraint
-
__init__
(shape, basis, offset=None, initial=None, quadratic=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
classmethod
affine
(linear_operator, offset, diag=False, quadratic=None)¶
-
apply_offset
(x)¶ If self.offset is not None, return x-self.offset, else return x.
-
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.
This should return two values that are 0, one is the inner product of the minimizer and the residual, the other is just 0.
- Parameters
atom : cone
A cone instance with a proximal method.
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.
-
cone_prox
(x, lipschitz=1)¶ Return (unique) minimizer
\[\beta^{\lambda}(u) = \text{argmin}_{\beta \in \mathbb{R}^p} \frac{1}{2} \|\beta-u\|^2_2 + \|\beta\|\]
-
property
conjugate
¶
-
constraint
(x)¶ The constraint
\[\|\beta\|\]
-
property
dual
¶
-
get_conjugate
()¶ Return the conjugate of an given atom.
>>> import regreg.api as rr >>> penalty = rr.projection((4,), [[1,0,0,0],[0,1,0,0]]) >>> penalty.get_conjugate() projection_complement((4,), [[1,0,0,0],[0,1,0,0]], offset=None)
-
get_dual
()¶ Return the dual of an atom. This dual is formed by making the substitution \(v=Ax\) where \(A\) is the self.linear_transform.
>>> import regreg.api as rr >>> penalty = rr.projection((4,), [[1,0,0,0],[0,1,0,0]]) >>> penalty projection((4,), [[1,0,0,0],[0,1,0,0]], offset=None) >>> penalty.dual (<regreg.affine.identity object at 0x...>, projection_complement((4,), [[1,0,0,0],[0,1,0,0]], offset=None))
If there is a linear part to the penalty, the linear_transform may not be identity:
>>> 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.nonnegative.linear(D) >>> linear_atom affine_cone(nonnegative((3,), offset=None), array([[ 1., -1., 0., 0.], [ 0., 1., -1., 0.], [ 0., 0., 1., -1.]])) >>> linear_atom.dual (<regreg.affine.linear_transform object at 0x...>, nonpositive((3,), offset=None))
-
get_offset
()¶
-
get_quadratic
()¶ Get the quadratic part of the composite.
-
latexify
(var=None, idx='')¶
-
classmethod
linear
(linear_operator, basis, diag=False, linear_term=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
(x, check_feasibility=False)¶ >>> import regreg.api as rr >>> cone = rr.nonnegative(4) >>> cone.nonsmooth_objective([3, 4, 5, 9]) 0.0
-
objective
(x, check_feasibility=False)¶
-
objective_template
= '\\|%(var)s\\|'¶
-
objective_vars
= {'coneklass': 'projection', 'dualconeklass': 'projection_complement', 'initargs': '(4,), [[1,0,0,0],[0,1,0,0]]', 'linear': 'D', 'offset': '\\alpha', 'shape': 'p', 'var': '\\beta'}¶
-
property
offset
¶
-
proximal
(proxq, prox_control=None)¶ The proximal operator.
\[v^{\lambda}(x) = \text{argmin}_{v \in \mathbb{R}^{p}} \frac{L}{2} \|x-\alpha - v\|^2_2 + \|\beta\| + \langle v, \eta \rangle\]where \(\alpha\) is self.offset, \(\eta\) is quadratic.linear_term.
>>> import regreg.api as rr >>> cone = rr.nonnegative((4,)) >>> Q = rr.identity_quadratic(1.5, [3, -4, -1, 1], 0, 0) >>> np.allclose(cone.proximal(Q), [3, 0, 0, 1]) True
- 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.
-
set_offset
(value)¶
-
set_quadratic
(quadratic)¶ Set the quadratic part of the composite.
-
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)¶
-
tol
= 1e-05¶
-
projection_complement
¶
-
class
regreg.atoms.linear_constraints.
projection_complement
(shape, basis, offset=None, initial=None, quadratic=None)¶ Bases:
regreg.atoms.linear_constraints.linear_constraint
An atom representing a linear constraint. The orthogonal complement of projection, it is specified with an orthonormal basis for the complement
-
__init__
(shape, basis, offset=None, initial=None, quadratic=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
classmethod
affine
(linear_operator, offset, diag=False, quadratic=None)¶
-
apply_offset
(x)¶ If self.offset is not None, return x-self.offset, else return x.
-
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.
This should return two values that are 0, one is the inner product of the minimizer and the residual, the other is just 0.
- Parameters
atom : cone
A cone instance with a proximal method.
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.
-
cone_prox
(x, lipschitz=1)¶ Return (unique) minimizer
\[\beta^{\lambda}(u) = \text{argmin}_{\beta \in \mathbb{R}^p} \frac{1}{2} \|\beta-u\|^2_2 + \|\beta\|\]
-
property
conjugate
¶
-
constraint
(x)¶ The constraint
\[\|\beta\|\]
-
property
dual
¶
-
get_conjugate
()¶ Return the conjugate of an given atom.
>>> import regreg.api as rr >>> penalty = rr.projection_complement((4,), [[1,0,0,0],[0,1,0,0]]) >>> penalty.get_conjugate() projection((4,), [[1,0,0,0],[0,1,0,0]], offset=None)
-
get_dual
()¶ Return the dual of an atom. This dual is formed by making the substitution \(v=Ax\) where \(A\) is the self.linear_transform.
>>> import regreg.api as rr >>> penalty = rr.projection_complement((4,), [[1,0,0,0],[0,1,0,0]]) >>> penalty projection_complement((4,), [[1,0,0,0],[0,1,0,0]], offset=None) >>> penalty.dual (<regreg.affine.identity object at 0x...>, projection((4,), [[1,0,0,0],[0,1,0,0]], offset=None))
If there is a linear part to the penalty, the linear_transform may not be identity:
>>> 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.nonnegative.linear(D) >>> linear_atom affine_cone(nonnegative((3,), offset=None), array([[ 1., -1., 0., 0.], [ 0., 1., -1., 0.], [ 0., 0., 1., -1.]])) >>> linear_atom.dual (<regreg.affine.linear_transform object at 0x...>, nonpositive((3,), offset=None))
-
get_offset
()¶
-
get_quadratic
()¶ Get the quadratic part of the composite.
-
latexify
(var=None, idx='')¶
-
classmethod
linear
(linear_operator, basis, diag=False, linear_term=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
(x, check_feasibility=False)¶ >>> import regreg.api as rr >>> cone = rr.nonnegative(4) >>> cone.nonsmooth_objective([3, 4, 5, 9]) 0.0
-
objective
(x, check_feasibility=False)¶
-
objective_template
= '\\|%(var)s\\|'¶
-
objective_vars
= {'coneklass': 'projection_complement', 'dualconeklass': 'projection', 'initargs': '(4,), [[1,0,0,0],[0,1,0,0]]', 'linear': 'D', 'offset': '\\alpha', 'shape': 'p', 'var': '\\beta'}¶
-
property
offset
¶
-
proximal
(proxq, prox_control=None)¶ The proximal operator.
\[v^{\lambda}(x) = \text{argmin}_{v \in \mathbb{R}^{p}} \frac{L}{2} \|x-\alpha - v\|^2_2 + \|\beta\| + \langle v, \eta \rangle\]where \(\alpha\) is self.offset, \(\eta\) is quadratic.linear_term.
>>> import regreg.api as rr >>> cone = rr.nonnegative((4,)) >>> Q = rr.identity_quadratic(1.5, [3, -4, -1, 1], 0, 0) >>> np.allclose(cone.proximal(Q), [3, 0, 0, 1]) True
- 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.
-
set_offset
(value)¶
-
set_quadratic
(quadratic)¶ Set the quadratic part of the composite.
-
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)¶
-
tol
= 1e-05¶
-