|
|
# LARS
|
|
|
|
|
|
An implementation of Least Angle Regression (Stagewise/laSso), also known as LARS.
|
|
|
|
|
|
# Available Predicates
|
|
|
|
|
|
* [initModelNoDataNoGram/4](/PrologMethods/Regression/lars#initmodelnodatanogram4)
|
|
|
* [initModelNoDataWithGram/7](/PrologMethods/Regression/lars#initmodelnodatawithgram7)
|
|
|
* [initModelWithDataNoGram/10](/PrologMethods/Regression/lars#initmodelwithdatanogram10)
|
|
|
* [initModelWithDataWithGram/13](/PrologMethods/Regression/lars#initmodelwithdatawithgram13)
|
|
|
* [activeSet/2](/PrologMethods/Regression/lars#activeset2)
|
|
|
* [beta/2](/PrologMethods/Regression/lars#beta2)
|
|
|
* [betaPath/3](/PrologMethods/Regression/lars#betapath3)
|
|
|
* [computeError/7](/PrologMethods/Regression/lars#computeerror7)
|
|
|
* [lambdaPath/2](/PrologMethods/Regression/lars#lambdapath2)
|
|
|
* [matUtriCholFactor/3](/PrologMethods/Regression/lars#matutricholfactor3)
|
|
|
* [predict/6](/PrologMethods/Regression/lars#predict6)
|
|
|
* [train/9](/PrologMethods/Regression/lars#train9)
|
|
|
|
|
|
---
|
|
|
|
|
|
[links/resources](/PrologMethods/Regression/lars#connected-linksresources)
|
|
|
|
|
|
## **_initModelNoDataNoGram/4_**
|
|
|
|
|
|
Only initialize the LARS model.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initModelNoDataNoGram( +integer,
|
|
|
+float32, +float32, +float32).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| useCholesky | +integer(bool) | Whether or not to use Cholesky decomposition when solving linear system (as opposed to using the full Gram matrix). | (0)false |
|
|
|
| lambda1 | +float | Regularization parameter for l1-norm penalty. | 0.0 |
|
|
|
| lambda2 | +float | Regularization parameter for l2-norm penalty. | 0.0 |
|
|
|
| tolerance | +float | Run until the maximum correlation of elements in (X^T y) is less than this. | 1e-16 |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_initModelNoDataWithGram/7_**
|
|
|
|
|
|
Initialize LARS model, and pass in a precalculated Gram matrix but dont train the model.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initModelNoDataWithGram( +integer,
|
|
|
+pointer(float_array), +integer, +integer,
|
|
|
+float32, +float32, +float32).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| useCholesky | +integer(bool) | Whether or not to use Cholesky decomposition when solving linear system (as opposed to using the full Gram matrix). | (0)false |
|
|
|
| gramMatrix | +matrix | Gram matrix. | - |
|
|
|
| lambda1 | +float | Regularization parameter for l1-norm penalty. | 0.0 |
|
|
|
| lambda2 | +float | Regularization parameter for l2-norm penalty. | 0.0 |
|
|
|
| tolerance | +float | Run until the maximum correlation of elements in (X^T y) is less than this. | 1e-16 |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_initModelWithDataNoGram/10_**
|
|
|
|
|
|
Initialize LARS model, and train the model.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initModelWithDataNoGram( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer,
|
|
|
+integer,
|
|
|
+float32, +float32, +float32).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| data | +matrix | Input data. | - |
|
|
|
| responses | +vector | A vector of targets. | - |
|
|
|
| transposeData | +integer(bool) | Should be true if the input data is column-major and false otherwise. | (1)true |
|
|
|
| useCholesky | +integer(bool) | Whether or not to use Cholesky decomposition when solving linear system (as opposed to using the full Gram matrix). | (0)false |
|
|
|
| lambda1 | +float | Regularization parameter for l1-norm penalty. | 0.0 |
|
|
|
| lambda2 | +float | Regularization parameter for l2-norm penalty. | 0.0 |
|
|
|
| tolerance | +float | Run until the maximum correlation of elements in (X^T y) is less than this. | 1e-16 |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_initModelWithDataWithGram/13_**
|
|
|
|
|
|
Initialize LARS model, pass in a precalculated Gram matrix and train the model.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
initModelWithDataWithGram( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer,
|
|
|
+integer,
|
|
|
+pointer(float_array), +integer, +integer,
|
|
|
+float32, +float32, +float32).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| data | +matrix | Input data. | - |
|
|
|
| responses | +vector | A vector of targets. | - |
|
|
|
| transposeData | +integer(bool) | Should be true if the input data is column-major and false otherwise. | (1)true |
|
|
|
| useCholesky | +integer(bool) | Whether or not to use Cholesky decomposition when solving linear system (as opposed to using the full Gram matrix). | (0)false |
|
|
|
| gramMatrix | +matrix | Gram matrix. | - |
|
|
|
| lambda1 | +float | Regularization parameter for l1-norm penalty. | 0.0 |
|
|
|
| lambda2 | +float | Regularization parameter for l2-norm penalty. | 0.0 |
|
|
|
| tolerance | +float | Run until the maximum correlation of elements in (X^T y) is less than this. | 1e-16 |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_activeSet/2_**
|
|
|
|
|
|
Get the set of active dimensions
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
activeSet(-pointer(float_array), -integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| activeSet | -vector | Get the set of active dimensions | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_beta/2_**
|
|
|
|
|
|
Get the solution coefficients.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
beta(-pointer(float_array), -integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| beta | -vector | Get the solution coefficients. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_betaPath/3_**
|
|
|
|
|
|
Get the set of coefficients after each iteration. The solution is the last element.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
betaPath(-pointer(float_array), -integer, -integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| betaPath | -matrix | Get the set of coefficients after each iteration. The solution is the last element. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_computeError/7_**
|
|
|
|
|
|
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.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
computeError( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
+integer,
|
|
|
[-integer]).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| matX | +matrix | Column-major input data (or row-major input data if rowMajor = true). | - |
|
|
|
| y | +vector | responses A vector of targets. | - |
|
|
|
| rowMajor | +integer(bool) | Should be true if the data points matrix is row-major and false otherwise. | (0)false |
|
|
|
| error | -float | The minimum cost error. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_lambdaPath/2_**
|
|
|
|
|
|
Get the set of values for lambda1 after each iteration; the solution is the last element.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
lambdaPath(-pointer(float_array), -integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| lambdaPath | -vector | Get the set of values for lambda1 after each iteration; the solution is the last element. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_matUtriCholFactor/3_**
|
|
|
|
|
|
Get the upper triangular cholesky factor.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
matUtriCholFactor(-pointer(float_array), -integer, -integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| factor | -matrix | Get the upper triangular cholesky factor. | - |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_predict/6_**
|
|
|
|
|
|
Predict y_i for each data point in the given data matrix using the currently-trained LARS model.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
predict( +pointer(float_array), +integer, +integer,
|
|
|
-pointer(float_array), -integer,
|
|
|
+integer).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| points | +matrix | The data points to regress on. | - |
|
|
|
| predictions | -vector | y, which will contained calculated values on completion. | - |
|
|
|
| rowMajor | +integer(bool) | Should be true if the data points matrix is row-major and false otherwise. | (0)false |
|
|
|
|
|
|
---
|
|
|
|
|
|
## **_train/9_**
|
|
|
|
|
|
Train the LARS model with the given data.
|
|
|
|
|
|
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.
|
|
|
|
|
|
```prolog
|
|
|
%% part of the predicate definition
|
|
|
train( +pointer(float_array), +integer, +integer,
|
|
|
+pointer(float_array), +integer,
|
|
|
-pointer(float_array), -integer,
|
|
|
+integer,
|
|
|
[-integer]).
|
|
|
```
|
|
|
|
|
|
### Parameters
|
|
|
| Name | Type | Description | Default |
|
|
|
|------|------|-------------|---------|
|
|
|
| data | +matrix | Column-major input data (or row-major input data if rowMajor = true). | - |
|
|
|
| responses | +vector | A vector of targets. | - |
|
|
|
| beta | -vector | Vector to store the solution (the coefficients) in. | - |
|
|
|
| transposeData | +integer(bool) | Set to false if the data is row-major. | (1)true |
|
|
|
| error | -float | minimum cost error( | |
|
|
|
|
|
|
---
|
|
|
|
|
|
# Connected Links/Resources
|
|
|
|
|
|
If you want a more detailed explanation, then go to the python documentation. There is most of the time a good explanation on how the methods work and what the parameters do.
|
|
|
|
|
|
* [MLpack::lars_C++\_documentation](https://www.mlpack.org/doc/stable/doxygen/classmlpack_1_1regression_1_1LARS.html)
|
|
|
* [MLpack::lars_Python_documentation](https://www.mlpack.org/doc/stable/python_documentation.html#lars)
|
|
|
|
|
|
added some of the links from the python documentation
|
|
|
|
|
|
* linear_regression
|
|
|
* [Least angle regression (pdf)](http://mlpack.org/papers/lars.pdf) |
|
|
\ No newline at end of file |