randomized.randomization

Module: randomized.randomization

Inheritance diagram for selectinf.randomized.randomization:

digraph inheritance025d2958e9 { rankdir=LR; size="8.0, 12.0"; "problems.composite.composite" [fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",tooltip="A generic way to specify a problem in composite form."]; "problems.composite.smooth" [fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",tooltip="A composite subclass that has 0 as "]; "problems.composite.composite" -> "problems.composite.smooth" [arrowsize=0.5,style="setlinewidth(0.5)"]; "randomized.randomization.cumulant" [URL="#selectinf.randomized.randomization.cumulant",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Class for CGF."]; "randomized.randomization.from_grad_func" -> "randomized.randomization.cumulant" [arrowsize=0.5,style="setlinewidth(0.5)"]; "randomized.randomization.cumulant_conjugate" [URL="#selectinf.randomized.randomization.cumulant_conjugate",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Class for conjugate of a CGF."]; "randomized.randomization.from_grad_func" -> "randomized.randomization.cumulant_conjugate" [arrowsize=0.5,style="setlinewidth(0.5)"]; "randomized.randomization.from_grad_func" [URL="#selectinf.randomized.randomization.from_grad_func",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="take a (func, grad) pair and make a smooth_objective"]; "regreg.smooth.smooth_atom" -> "randomized.randomization.from_grad_func" [arrowsize=0.5,style="setlinewidth(0.5)"]; "randomized.randomization.randomization" [URL="#selectinf.randomized.randomization.randomization",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "regreg.smooth.smooth_atom" -> "randomized.randomization.randomization" [arrowsize=0.5,style="setlinewidth(0.5)"]; "randomized.randomization.split" [URL="#selectinf.randomized.randomization.split",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "randomized.randomization.randomization" -> "randomized.randomization.split" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.smooth.smooth_atom" [fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",tooltip="A class for representing a smooth function and its gradient"]; "problems.composite.smooth" -> "regreg.smooth.smooth_atom" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Different randomization options for selective sampler. Main method used in selective sampler is the gradient method which should be a gradient of the negative of the log-density. For a Gaussian density, this will be a convex function, not a concave function.

Classes

cumulant

class selectinf.randomized.randomization.cumulant(shape, func, grad, coef=1.0, offset=None, initial=None, quadratic=None)[source]

Bases: selectinf.randomized.randomization.from_grad_func

Class for CGF.

__init__(shape, func, grad, coef=1.0, offset=None, initial=None, quadratic=None)

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

classmethod affine(linear_operator, offset, coef=1, diag=False, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

apply_offset(x)

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

property conjugate
get_conjugate()
get_lipschitz()
get_offset()
get_quadratic()

Get the quadratic part of the composite.

latexify(var=None, idx='')
classmethod linear(linear_operator, coef=1, diag=False, offset=None, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

property lipschitz
nonsmooth_objective(x, check_feasibility=False)
objective(x, check_feasibility=False)
objective_template = 'f(%(var)s)'
objective_vars = {'coef': 'C', 'offset': '\\alpha+', 'shape': 'p', 'var': '\\beta'}
property offset
proximal(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.

scale(obj, copy=False)
set_lipschitz(value)
set_offset(value)
set_quadratic(quadratic)

Set the quadratic part of the composite.

classmethod shift(offset, coef=1, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

smooth_objective(param, mode='both', check_feasibility=False)

Evaluate the smooth objective, computing its value, gradient or both. Parameters ———- mean_param : ndarray

The current parameter values.

modestr

One of [‘func’, ‘grad’, ‘both’].

check_feasibilitybool

If True, return np.inf when point is not feasible, i.e. when mean_param is not in the domain.

If mode is ‘func’ returns just the objective value at mean_param, else if mode is ‘grad’ returns the gradient else returns both.

smoothed(smoothing_quadratic)

Add quadratic smoothing term

solve(quadratic=None, return_optimum=False, **fit_args)

cumulant_conjugate

class selectinf.randomized.randomization.cumulant_conjugate(shape, func, grad, coef=1.0, offset=None, initial=None, quadratic=None)[source]

Bases: selectinf.randomized.randomization.from_grad_func

Class for conjugate of a CGF.

__init__(shape, func, grad, coef=1.0, offset=None, initial=None, quadratic=None)

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

classmethod affine(linear_operator, offset, coef=1, diag=False, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

apply_offset(x)

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

property conjugate
get_conjugate()
get_lipschitz()
get_offset()
get_quadratic()

Get the quadratic part of the composite.

latexify(var=None, idx='')
classmethod linear(linear_operator, coef=1, diag=False, offset=None, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

property lipschitz
nonsmooth_objective(x, check_feasibility=False)
objective(x, check_feasibility=False)
objective_template = 'f(%(var)s)'
objective_vars = {'coef': 'C', 'offset': '\\alpha+', 'shape': 'p', 'var': '\\beta'}
property offset
proximal(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.

scale(obj, copy=False)
set_lipschitz(value)
set_offset(value)
set_quadratic(quadratic)

Set the quadratic part of the composite.

classmethod shift(offset, coef=1, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

smooth_objective(param, mode='both', check_feasibility=False)

Evaluate the smooth objective, computing its value, gradient or both. Parameters ———- mean_param : ndarray

The current parameter values.

modestr

One of [‘func’, ‘grad’, ‘both’].

check_feasibilitybool

If True, return np.inf when point is not feasible, i.e. when mean_param is not in the domain.

If mode is ‘func’ returns just the objective value at mean_param, else if mode is ‘grad’ returns the gradient else returns both.

smoothed(smoothing_quadratic)

Add quadratic smoothing term

solve(quadratic=None, return_optimum=False, **fit_args)

from_grad_func

class selectinf.randomized.randomization.from_grad_func(shape, func, grad, coef=1.0, offset=None, initial=None, quadratic=None)[source]

Bases: regreg.smooth.smooth_atom

take a (func, grad) pair and make a smooth_objective

__init__(shape, func, grad, coef=1.0, offset=None, initial=None, quadratic=None)[source]

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

smooth_objective(param, mode='both', check_feasibility=False)[source]

Evaluate the smooth objective, computing its value, gradient or both. Parameters ———- mean_param : ndarray

The current parameter values.

modestr

One of [‘func’, ‘grad’, ‘both’].

check_feasibilitybool

If True, return np.inf when point is not feasible, i.e. when mean_param is not in the domain.

If mode is ‘func’ returns just the objective value at mean_param, else if mode is ‘grad’ returns the gradient else returns both.

classmethod affine(linear_operator, offset, coef=1, diag=False, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

apply_offset(x)

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

property conjugate
get_conjugate()
get_lipschitz()
get_offset()
get_quadratic()

Get the quadratic part of the composite.

latexify(var=None, idx='')
classmethod linear(linear_operator, coef=1, diag=False, offset=None, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

property lipschitz
nonsmooth_objective(x, check_feasibility=False)
objective(x, check_feasibility=False)
objective_template = 'f(%(var)s)'
objective_vars = {'coef': 'C', 'offset': '\\alpha+', 'shape': 'p', 'var': '\\beta'}
property offset
proximal(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.

scale(obj, copy=False)
set_lipschitz(value)
set_offset(value)
set_quadratic(quadratic)

Set the quadratic part of the composite.

classmethod shift(offset, coef=1, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

smoothed(smoothing_quadratic)

Add quadratic smoothing term

solve(quadratic=None, return_optimum=False, **fit_args)

randomization

class selectinf.randomized.randomization.randomization(shape, density, cdf, pdf, derivative_log_density, grad_negative_log_density, sampler, lipschitz=1, log_density=None, CGF=None, CGF_conjugate=None, cov_prec=None)[source]

Bases: regreg.smooth.smooth_atom

__init__(shape, density, cdf, pdf, derivative_log_density, grad_negative_log_density, sampler, lipschitz=1, log_density=None, CGF=None, CGF_conjugate=None, cov_prec=None)[source]

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

property lipschitz
smooth_objective(perturbation, mode='both', check_feasibility=False)[source]

Compute the negative log-density and its gradient.

sample(size=())[source]
gradient(perturbation)[source]

Evaluate the gradient of the log-density. Parameters ———- perturbation : np.float Returns ——- gradient : np.float

log_density(perturbation)[source]

Evaluate the log-density. Parameters ———- perturbation : np.float Returns ——- value : float

randomize(loss, epsilon=0, perturb=None)[source]

Randomize the loss.

static isotropic_gaussian(shape, scale)[source]

Isotropic Gaussian with SD scale. Parameters ———- shape : tuple

Shape of noise.

scalefloat

SD of noise.

static gaussian(covariance)[source]

Gaussian noise with a given covariance. Parameters ———- covariance : np.float((,))

Positive definite covariance matrix. Non-negative definite will raise an error.

static laplace(shape, scale)[source]

Standard Laplace noise multiplied by scale Parameters ———- shape : tuple

Shape of noise.

scalefloat

Scale of noise.

static logistic(shape, scale)[source]

Standard logistic noise multiplied by scale Parameters ———- shape : tuple

Shape of noise.

scalefloat

Scale of noise.

classmethod affine(linear_operator, offset, coef=1, diag=False, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

apply_offset(x)

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

property conjugate
get_conjugate()
get_lipschitz()
get_offset()
get_quadratic()

Get the quadratic part of the composite.

latexify(var=None, idx='')
classmethod linear(linear_operator, coef=1, diag=False, offset=None, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

nonsmooth_objective(x, check_feasibility=False)
objective(x, check_feasibility=False)
objective_template = 'f(%(var)s)'
objective_vars = {'coef': 'C', 'offset': '\\alpha+', 'shape': 'p', 'var': '\\beta'}
property offset
proximal(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.

scale(obj, copy=False)
set_lipschitz(value)
set_offset(value)
set_quadratic(quadratic)

Set the quadratic part of the composite.

classmethod shift(offset, coef=1, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

smoothed(smoothing_quadratic)

Add quadratic smoothing term

solve(quadratic=None, return_optimum=False, **fit_args)

split

class selectinf.randomized.randomization.split(shape, subsample_size, total_size)[source]

Bases: selectinf.randomized.randomization.randomization

__init__(shape, subsample_size, total_size)[source]

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

get_covariance()[source]
set_covariance(covariance)[source]

Once covariance has been set, then the usual API of randomization will work.

property covariance
property cov_prec
smooth_objective(perturbation, mode='both', check_feasibility=False)[source]

Compute the negative log-density and its gradient.

sample(size=())[source]
gradient(perturbation)[source]

Evaluate the gradient of the log-density. Parameters ———- perturbation : np.float Returns ——- gradient : np.float

randomize(loss, epsilon)[source]
Parameters

loss : rr.glm

A glm loss with a subsample method.

epsilon : float

Coefficient in front of quadratic term

Returns

——-

Subsampled loss multiplied by `n / m` where

m is the subsample size out of a total

sample size of n.

The quadratic term is not multiplied by `n / m`

classmethod affine(linear_operator, offset, coef=1, diag=False, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

apply_offset(x)

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

property conjugate
static gaussian(covariance)

Gaussian noise with a given covariance. Parameters ———- covariance : np.float((,))

Positive definite covariance matrix. Non-negative definite will raise an error.

get_conjugate()
get_lipschitz()
get_offset()
get_quadratic()

Get the quadratic part of the composite.

static isotropic_gaussian(shape, scale)

Isotropic Gaussian with SD scale. Parameters ———- shape : tuple

Shape of noise.

scalefloat

SD of noise.

static laplace(shape, scale)

Standard Laplace noise multiplied by scale Parameters ———- shape : tuple

Shape of noise.

scalefloat

Scale of noise.

latexify(var=None, idx='')
classmethod linear(linear_operator, coef=1, diag=False, offset=None, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

property lipschitz
log_density(perturbation)

Evaluate the log-density. Parameters ———- perturbation : np.float Returns ——- value : float

static logistic(shape, scale)

Standard logistic noise multiplied by scale Parameters ———- shape : tuple

Shape of noise.

scalefloat

Scale of noise.

nonsmooth_objective(x, check_feasibility=False)
objective(x, check_feasibility=False)
objective_template = 'f(%(var)s)'
objective_vars = {'coef': 'C', 'offset': '\\alpha+', 'shape': 'p', 'var': '\\beta'}
property offset
proximal(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.

scale(obj, copy=False)
set_lipschitz(value)
set_offset(value)
set_quadratic(quadratic)

Set the quadratic part of the composite.

classmethod shift(offset, coef=1, quadratic=None, **kws)

Keywords given in kws are passed to cls constructor along with other arguments

smoothed(smoothing_quadratic)

Add quadratic smoothing term

solve(quadratic=None, return_optimum=False, **fit_args)

Functions

selectinf.randomized.randomization.isotropic_gaussian_CGF(shape, scale)[source]
selectinf.randomized.randomization.isotropic_gaussian_CGF_conjugate(shape, scale)[source]
selectinf.randomized.randomization.laplace_CGF(shape, scale)[source]
selectinf.randomized.randomization.laplace_CGF_conjugate(shape, scale)[source]