Class LassoCoordinateDescent
source code
object --+
|
bases.BaseAlgorithm --+
|
bases.ImplicitAlgorithm --+
|
object --+ |
| |
bases.IterativeAlgorithm --+
|
object --+ |
| |
bases.InformationAlgorithm --+
|
LassoCoordinateDescent
A coordinate descent algorithm for the lasso.
This algorithm is very similar to the ShootingAlgorithm, but uses soft
thresholding instead of splitting the cases of the subgradient of L1.
It seems ShootingAlgorithm is slightly faster.
Parameters
----------
l : Non-negative float. The Lagrange multiplier, or regularisation
constant, of the Lasso.
mean : Boolean. Whether to compute the squared loss or the mean squared
loss. Default is True, the mean squared loss.
penalty_start : Non-negative integer. The number of columns, variables
etc., to be exempt from penalisation. Equivalently, the first index
to be penalised. Default is 0, all columns are included.
eps : Positive float. Tolerance for the stopping criterion.
info : List or tuple of utils.Info. What, if any, extra run information
should be stored. Default is an empty list, which means that no
run information is computed nor returned.
max_iter : Non-negative integer. Maximum allowed number of iterations.
Default is 10000.
min_iter : Non-negative integer less than or equal to max_iter. Minimum
number of iterations that must be performed. Default is 1.
Examples
--------
>>> from parsimony.algorithms.coordinate import LassoCoordinateDescent
>>> import parsimony.functions as functions
>>> import parsimony.functions.penalties as penalties
>>> import numpy as np
>>> np.random.seed(42)
>>> X = np.random.rand(100, 50)
>>> beta_star = np.random.rand(50, 1)
>>> beta_star[beta_star < 0.5] = 0.0
>>> y = np.dot(X, beta_star) + 0.001 * np.random.randn(100, 1)
>>> l = 0.0618
>>> alg = LassoCoordinateDescent(l)
>>> function = functions.CombinedFunction()
>>> function.add_function(functions.losses.LinearRegression(X, y,
... mean=False))
>>> function.add_prox(penalties.L1(l=l))
>>> beta = alg.run(X, y)
>>> round(np.linalg.norm(beta_star - beta), 14)
0.34655181469595
|
__init__(self,
l,
mean=True,
penalty_start=0,
start_vector=start_vectors.RandomStartVector(limits=(-1.0,1.0)),
eps=5e-08,
info=[ ] ,
max_iter=10000,
min_iter=1)
x.__init__(...) initializes x; see help(type(x)) for signature |
source code
|
|
|
|
|
run(self,
function,
*args,
**kwargs)
Find the minimiser of the associated function, starting at beta. |
source code
|
|
Inherited from bases.BaseAlgorithm :
get_params ,
set_params
Inherited from bases.IterativeAlgorithm :
iter_reset
Inherited from bases.InformationAlgorithm :
check_info_compatibility ,
info_copy ,
info_get ,
info_provided ,
info_requested ,
info_reset ,
info_set
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
|
INFO_PROVIDED = [ ' ok ' , ' num_iter ' , ' time ' , ' fvalue ' , ' converged ' ]
|
|
__abstractmethods__ = frozenset([ ])
|
|
_abc_negative_cache_version = 14
|
Inherited from bases.ImplicitAlgorithm :
__metaclass__
|
Inherited from object :
__class__
|
__init__(self,
l,
mean=True,
penalty_start=0,
start_vector=start_vectors.RandomStartVector(limits=(-1.0,1.0)),
eps=5e-08,
info=[ ] ,
max_iter=10000,
min_iter=1)
(Constructor)
| source code
|
x.__init__(...) initializes x; see help(type(x)) for signature
- Overrides:
object.__init__
- (inherited documentation)
|
Find the minimiser of the associated function, starting at beta.
Parameters
----------
X : Numpy array, shape n-by-p. The matrix X with independent
variables.
y : Numpy array, shape n-by-1. The response variable y.
beta : Numpy array. Optional starting point.
- Decorators:
- Overrides:
bases.ImplicitAlgorithm.run
|