problems.simple¶
Module: problems.simple
¶
Inheritance diagram for regreg.problems.simple
:
This module has a class for specifying a problem from just a smooth function and a single penalty.
Class¶
simple_problem
¶
-
class
regreg.problems.simple.
simple_problem
(smooth_atom, proximal_atom)¶ Bases:
regreg.problems.composite.composite
-
__init__
(smooth_atom, proximal_atom)¶ Initialize self. See help(type(self)) for accurate signature.
-
apply_offset
(x)¶ If self.offset is not None, return x-self.offset, else return x.
-
get_offset
()¶
-
get_quadratic
()¶ Get the quadratic part of the composite.
-
latexify
(var=None)¶
-
static
nonsmooth
(proximal_atom)¶ A problem with no nonsmooth part except possibly the quadratic of smooth_atom.
The proximal function is (almost) a nullop.
-
nonsmooth_objective
(x, check_feasibility=False)¶
-
objective
(x, check_feasibility=False)¶
-
objective_template
= 'f(%(var)s)'¶
-
objective_vars
= {'offset': '\\alpha', 'shape': 'p', 'var': '\\beta'}¶
-
property
offset
¶
-
proximal
(proxq)¶
-
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.
-
static
smooth
(smooth_atom)¶ A problem with no nonsmooth part except possibly the quadratic of smooth_atom.
The proximal function is (almost) a nullop.
-
smooth_objective
(x, mode='both', check_feasibility=False)¶ This class explicitly assumes that the proximal_atom has 0 for smooth_objective.
-
smoothed
(smoothing_quadratic)¶ Add quadratic smoothing term
-
solve
(quadratic=None, return_optimum=False, **fit_args)¶
-
Functions¶
-
regreg.problems.simple.
gengrad
(simple_problem, lipschitz, tol=1e-08, max_its=1000, debug=False, coef_stop=False)¶ A simple generalized gradient solver
-
regreg.problems.simple.
nesta
(smooth_atom, proximal_atom, conjugate_atom, epsilon=None, tol=1e-06, max_iters=100, min_iters=5, coef_tol=1e-06, initial_primal=None, initial_dual=None, coef_stop=False, quadratic=None)¶ - Parameters
smooth_atom: smooth_composite
A smooth function, i.e. having a smooth_objective method.
proximal_atom:
An atom with a proximal method.
conjugate_atom:
An atom that will be smoothed, by adding a quadratic to its conjugate.
epsilon: np.array
A decreasing array of positive constants for Moreau-Yosida smoothing.
tol : np.float
Tolerance to which each problem is solved is max(tol, epsilon)
max_iter s: int
Maximum number of iterations. If epsilon is not supplied, it is taken to be [1]*max_iters
initial_primal, initial_dual : np.ndarray(np.float)
Initial conditions for both primal and dual variables.
coef_tol : float
Tolerance for assessing convergence of coefficients.
quadratic : regreg.identity_quadratic
A quadratic term that is added to the total objective.
- Returns
primal: np.array
Primal coefficients.
dual: np.array
Dual coefficients.
-
regreg.problems.simple.
tfocs
(primal_atom, transform, dual_proximal_atom, epsilon=None, tol=1e-06, max_iters=100, coef_tol=1e-06, quadratic=None)¶ This function is based on the setup of problems described in TFOCS. Generally speaking, these are the same type of problems that nesta can handle, though without the additional smooth part.
This solver is suited to solving problems of the form
minimize_v f(v) + h(Dv+a)
when both f and h (and hence f^* and h^*) have simple proximal operators.
Here is an example for minimum \(\ell_1\) norm reconstruction.
>>> import numpy as np, regreg.api as rr >>> np.random.seed(0) >>> n, p = 200, 5000
The problem assumes Y=np.dot(X,beta) for some sparse beta.
>>> X = np.random.standard_normal((n, p)) >>> beta = np.zeros(p) >>> beta[:10] = np.arange(10)+1 >>> Y = np.dot(X, beta) >>>
The problem is formally,
minimize_v np.fabs(v).sum() subject to Y=np.dot(X,v)
The \(\ell_1\) norm is described as:
>>> l1 = rr.l1norm(p, lagrange=1)
The constraint is specified as
>>> constraint = rr.zero_constraint.affine(X,-Y)
>>> transform, zero = constraint.dual >>> epsilon = [0.01]*50 + [0.001]*20 >>> primal_tfocs, dual_tfocs = rr.tfocs(l1, transform, zero, epsilon=epsilon) >>> np.linalg.norm(primal_tfocs - beta) < 1.e-3 * np.linalg.norm(beta) True
>>> np.linalg.norm(primal_tfocs[10:]) < 1.e-3 * np.linalg.norm(primal_tfocs) True
- Parameters
primal_atom: atom
An atom that will be smoothed, then composed with the transform.
transform : affine_transform
An affine transform for the composition.
dual_proximal_atom: atom
An atom with a proximal method.
epsilon: np.array
A decreasing array of positive constants for Moreau-Yosida smoothing.
tol: np.float
Tolerance to which each problem is solved is max(tol, epsilon)
max_iters: int
Maximum number of iterations. If epsilon is not supplied, it is taken to be [1]*max_iters
initial_primal, initial_dual : np.ndarray(np.float)
Initial conditions for both primal and dual variables.
coef_tol : float
Tolerance for assessing convergence of coefficients.
quadratic : regreg.identity_quadratic
A quadratic term that is added to the total objective.
- Returns
primal: np.array
Primal coefficients.
dual: np.array
Dual coefficients.