Least Absolute Deviations¶
-
lad.lad.
lad
(X, y, yerr=None, l1_regularizer=0.0, cov=False, maxiter=50, rtol=0.0001, eps=0.0001, session=None)[source]¶ Linear least absolute deviations with L1 norm regularization using Majorization-Minimization. See [1] for a similar mathematical derivation.
Parameters: X : (n, m)-matrix
Design matrix.
y : (n, 1) matrix
Vector of observations.
yerr : (n, 1) matrix
Vector of standard deviations on the observations.
l1_regularizer : float
Factor to control the importance of the L1 regularization.
cov : boolean
Whether or not to return the covariance matrix of the best fitted coefficients. Standard errors on the coefficients can be computed as the square root of the diagonal of the covariance matrix.
maxiter : int
Maximum number of iterations of the majorization-minimization algorithm. If maxiter equals zero, then this function returns the Weighted Least-Squares coefficients.
rtol : float
Relative tolerance on the coefficients used as an early stopping criterion. If |x_{k+1} - x_{k}|/max(1, |x_{k}|) < rtol, where |x| is the L1-norm of x, the algorithm stops.
eps : float
Increase this value if tensorflow raises an exception saying that the Cholesky decomposition was not successful.
session : tf.Session object
A tensorflow.Session object.
Returns: x : (m, 1) matrix
Vector of coefficients that minimizes the least absolute deviations with L1 regularization.
cov : (m, m) matrix
Covariance matrix of
x
.References
[1] Phillips, R. F. Least absolute deviations estimation via the EM algorithm. Statistics and Computing, 12, 281-285, 2002.
-
lad.lad.
lad_polyfit
(x, y, order=1, **kwargs)[source]¶ Least absolute deviations polynomial fitting.
Fit a polynomial
p(x) = p[0] + ... + p[order] * x**order
of degreeorder
to points (x, y). Returns a vector of coefficientsp
that minimises the absolute error.Parameters: x : (n, 1)-matrix
x-coordinate of the observations.
y : (n, 1) matrix
Vector of observations.
order : int
Degree of the fitting polynomial.
**kwargs : dict
See the docstrings of
lad
.Returns: p : (m, 1) matrix
Vector of coefficients that minimizes the least absolute deviations with L1 regularization.