randomized.randomization¶
Module: randomized.randomization¶
Inheritance diagram for selectinf.randomized.randomization:
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_funcClass 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_funcClass 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_atomtake 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.
-
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
-
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.
-
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.
-
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)¶
-