|
mlpack
|
An implementation of LARS, a stage-wise homotopy-based algorithm for l1-regularized linear regression (LASSO) and l1+l2 regularized linear regression (Elastic Net). More...
#include <lars.hpp>
Public Member Functions | |
| LARS (const bool useCholesky=false, const double lambda1=0.0, const double lambda2=0.0, const double tolerance=1e-16) | |
| Set the parameters to LARS. More... | |
| LARS (const bool useCholesky, const arma::mat &gramMatrix, const double lambda1=0.0, const double lambda2=0.0, const double tolerance=1e-16) | |
| Set the parameters to LARS, and pass in a precalculated Gram matrix. More... | |
| LARS (const arma::mat &data, const arma::rowvec &responses, const bool transposeData=true, const bool useCholesky=false, const double lambda1=0.0, const double lambda2=0.0, const double tolerance=1e-16) | |
| Set the parameters to LARS and run training. More... | |
| LARS (const arma::mat &data, const arma::rowvec &responses, const bool transposeData, const bool useCholesky, const arma::mat &gramMatrix, const double lambda1=0.0, const double lambda2=0.0, const double tolerance=1e-16) | |
| Set the parameters to LARS, pass in a precalculated Gram matrix, and run training. More... | |
| LARS (const LARS &other) | |
| Construct the LARS object by copying the given LARS object. More... | |
| LARS (LARS &&other) | |
| Construct the LARS object by taking ownership of the given LARS object. More... | |
| LARS & | operator= (const LARS &other) |
| Copy the given LARS object. More... | |
| LARS & | operator= (LARS &&other) |
| Take ownership of the given LARS object. More... | |
| double | Train (const arma::mat &data, const arma::rowvec &responses, arma::vec &beta, const bool transposeData=true) |
| Run LARS. More... | |
| double | Train (const arma::mat &data, const arma::rowvec &responses, const bool transposeData=true) |
| Run LARS. More... | |
| void | Predict (const arma::mat &points, arma::rowvec &predictions, const bool rowMajor=false) const |
| Predict y_i for each data point in the given data matrix using the currently-trained LARS model. More... | |
| double | Lambda1 () const |
| Get the L1 regularization coefficient. | |
| double & | Lambda1 () |
| Modify the L1 regularization coefficient. | |
| double | Lambda2 () const |
| Get the L2 regularization coefficient. | |
| double & | Lambda2 () |
| Modify the L2 regularization coefficient. | |
| bool | UseCholesky () const |
| Get whether to use the Cholesky decomposition. | |
| bool & | UseCholesky () |
| Modify whether to use the Cholesky decomposition. | |
| double | Tolerance () const |
| Get the tolerance for maximum correlation during training. | |
| double & | Tolerance () |
| Modify the tolerance for maximum correlation during training. | |
| const std::vector< size_t > & | ActiveSet () const |
| Access the set of active dimensions. | |
| const std::vector< arma::vec > & | BetaPath () const |
| Access the set of coefficients after each iteration; the solution is the last element. More... | |
| const arma::vec & | Beta () const |
| Access the solution coefficients. | |
| const std::vector< double > & | LambdaPath () const |
| Access the set of values for lambda1 after each iteration; the solution is the last element. More... | |
| const arma::mat & | MatUtriCholFactor () const |
| Access the upper triangular cholesky factor. | |
| template<typename Archive > | |
| void | serialize (Archive &ar, const uint32_t) |
| Serialize the LARS model. | |
| double | ComputeError (const arma::mat &matX, const arma::rowvec &y, const bool rowMajor=false) |
| Compute cost error of the given data matrix using the currently-trained LARS model. More... | |
An implementation of LARS, a stage-wise homotopy-based algorithm for l1-regularized linear regression (LASSO) and l1+l2 regularized linear regression (Elastic Net).
Let \( X \) be a matrix where each row is a point and each column is a dimension and let \( y \) be a vector of responses.
The Elastic Net problem is to solve
\[ \min_{\beta} 0.5 || X \beta - y ||_2^2 + \lambda_1 || \beta ||_1 + 0.5 \lambda_2 || \beta ||_2^2 \]
where \( \beta \) is the vector of regression coefficients.
If \( \lambda_1 > 0 \) and \( \lambda_2 = 0 \), the problem is the LASSO. If \( \lambda_1 > 0 \) and \( \lambda_2 > 0 \), the problem is the elastic net. If \( \lambda_1 = 0 \) and \( \lambda_2 > 0 \), the problem is ridge regression. If \( \lambda_1 = 0 \) and \( \lambda_2 = 0 \), the problem is unregularized linear regression.
Note: This algorithm is not recommended for use (in terms of efficiency) when \( \lambda_1 \) = 0.
For more details, see the following papers:
| LARS::LARS | ( | const bool | useCholesky = false, |
| const double | lambda1 = 0.0, |
||
| const double | lambda2 = 0.0, |
||
| const double | tolerance = 1e-16 |
||
| ) |
Set the parameters to LARS.
Both lambda1 and lambda2 default to 0.
| useCholesky | Whether or not to use Cholesky decomposition when solving linear system (as opposed to using the full Gram matrix). |
| lambda1 | Regularization parameter for l1-norm penalty. |
| lambda2 | Regularization parameter for l2-norm penalty. |
| tolerance | Run until the maximum correlation of elements in (X^T y) is less than this. |
| LARS::LARS | ( | const bool | useCholesky, |
| const arma::mat & | gramMatrix, | ||
| const double | lambda1 = 0.0, |
||
| const double | lambda2 = 0.0, |
||
| const double | tolerance = 1e-16 |
||
| ) |
Set the parameters to LARS, and pass in a precalculated Gram matrix.
Both lambda1 and lambda2 default to 0.
| useCholesky | Whether or not to use Cholesky decomposition when solving linear system (as opposed to using the full Gram matrix). |
| gramMatrix | Gram matrix. |
| lambda1 | Regularization parameter for l1-norm penalty. |
| lambda2 | Regularization parameter for l2-norm penalty. |
| tolerance | Run until the maximum correlation of elements in (X^T y) is less than this. |
| LARS::LARS | ( | const arma::mat & | data, |
| const arma::rowvec & | responses, | ||
| const bool | transposeData = true, |
||
| const bool | useCholesky = false, |
||
| const double | lambda1 = 0.0, |
||
| const double | lambda2 = 0.0, |
||
| const double | tolerance = 1e-16 |
||
| ) |
Set the parameters to LARS and run training.
Both lambda1 and lambda2 are set by default to 0.
| data | Input data. |
| responses | A vector of targets. |
| transposeData | Should be true if the input data is column-major and false otherwise. |
| useCholesky | Whether or not to use Cholesky decomposition when solving linear system (as opposed to using the full Gram matrix). |
| lambda1 | Regularization parameter for l1-norm penalty. |
| lambda2 | Regularization parameter for l2-norm penalty. |
| tolerance | Run until the maximum correlation of elements in (X^T y) is less than this. |
| LARS::LARS | ( | const arma::mat & | data, |
| const arma::rowvec & | responses, | ||
| const bool | transposeData, | ||
| const bool | useCholesky, | ||
| const arma::mat & | gramMatrix, | ||
| const double | lambda1 = 0.0, |
||
| const double | lambda2 = 0.0, |
||
| const double | tolerance = 1e-16 |
||
| ) |
Set the parameters to LARS, pass in a precalculated Gram matrix, and run training.
Both lambda1 and lambda2 are set by default to 0.
| data | Input data. |
| responses | A vector of targets. |
| transposeData | Should be true if the input data is column-major and false otherwise. |
| useCholesky | Whether or not to use Cholesky decomposition when solving linear system (as opposed to using the full Gram matrix). |
| gramMatrix | Gram matrix. |
| lambda1 | Regularization parameter for l1-norm penalty. |
| lambda2 | Regularization parameter for l2-norm penalty. |
| tolerance | Run until the maximum correlation of elements in (X^T y) is less than this. |
| LARS::LARS | ( | const LARS & | other | ) |
| LARS::LARS | ( | LARS && | other | ) |
|
inline |
Access the set of coefficients after each iteration; the solution is the last element.
| double LARS::ComputeError | ( | const arma::mat & | matX, |
| const arma::rowvec & | y, | ||
| const bool | rowMajor = false |
||
| ) |
Compute cost error of the given data matrix using the currently-trained LARS model.
Only ||y-beta*X||2 is used to calculate cost error.
| matX | Column-major input data (or row-major input data if rowMajor = true). |
| y | responses A vector of targets. |
| rowMajor | Should be true if the data points matrix is row-major and false otherwise. |
|
inline |
Access the set of values for lambda1 after each iteration; the solution is the last element.
| void LARS::Predict | ( | const arma::mat & | points, |
| arma::rowvec & | predictions, | ||
| const bool | rowMajor = false |
||
| ) | const |
Predict y_i for each data point in the given data matrix using the currently-trained LARS model.
| points | The data points to regress on. |
| predictions | y, which will contained calculated values on completion. |
| rowMajor | Should be true if the data points matrix is row-major and false otherwise. |
| double LARS::Train | ( | const arma::mat & | data, |
| const arma::rowvec & | responses, | ||
| arma::vec & | beta, | ||
| const bool | transposeData = true |
||
| ) |
Run LARS.
The input matrix (like all mlpack matrices) should be column-major – each column is an observation and each row is a dimension. However, because LARS is more efficient on a row-major matrix, this method will (internally) transpose the matrix. If this transposition is not necessary (i.e., you want to pass in a row-major matrix), pass 'false' for the transposeData parameter.
| data | Column-major input data (or row-major input data if rowMajor = true). |
| responses | A vector of targets. |
| beta | Vector to store the solution (the coefficients) in. |
| transposeData | Set to false if the data is row-major. |
Note that: R^T R % S^T % S = (R % S)^T (R % S) Now, for 1 the ones vector: inv( (R % S)^T (R % S) ) 1 = inv(R % S) inv((R % S)^T) 1 = inv(R % S) Solve((R % S)^T, 1) = inv(R % S) Solve(R^T, s) = Solve(R % S, Solve(R^T, s) = s % Solve(R, Solve(R^T, s))
| double LARS::Train | ( | const arma::mat & | data, |
| const arma::rowvec & | responses, | ||
| const bool | transposeData = true |
||
| ) |
Run LARS.
The input matrix (like all mlpack matrices) should be column-major – each column is an observation and each row is a dimension. However, because LARS is more efficient on a row-major matrix, this method will (internally) transpose the matrix. If this transposition is not necessary (i.e., you want to pass in a row-major matrix), pass 'false' for the transposeData parameter.
| data | Input data. |
| responses | A vector of targets. |
| transposeData | Should be true if the input data is column-major and false otherwise. |
1.8.13