LARS
An implementation of Least Angle Regression (Stagewise/laSso), also known as LARS.
:- use_module('path/to/.../src/methods/lars/lars.pl').
%% usage example
TrainData = [5.1,3.5,1.4, 4.9,3.0,1.4, 4.7,3.2,1.3, 4.6,3.1,1.5],
TestData = [3,2,0, 5,1,4, 0,0,4, 3,3,5, 0,5,5, 2,5,5],
lars_initAndTrainModel(0, 0.0, 0.0, 1.0e-16, TrainData, 3, [0,1,0,1], 0, _),
lars_predict(TestData, 3, PredictList, 1).
Available Predicates
- lars_initAndTrainModel/9
- lars_activeSet/2
- lars_beta/2
- lars_betaPath/3
- lars_computeError/7
- lars_lambdaPath/2
- lars_matUtriCholFactor/3
- lars_predict/6
lars_initAndTrainModel/9
Only initialize the LARS model.
%% predicate definition
lars_initAndTrainModel(UseCholesky, Lambda1, Lambda2, Tolerance, DataList, DataPointsDim, ResponsesList, RowMajor, Error) :-
Tolerance > 0,
convert_list_to_float_array(DataList, DataPointsDim, array(Xsize, Xrownum, X)),
convert_list_to_float_array(ResponsesList, array(Ysize, Y)),
initAndTrainModelI(UseCholesky, Lambda1, Lambda2, Tolerance, X, Xsize, Xrownum, Y, Ysize, RowMajor, Error).
%% foreign c++ predicate definition
foreign(initAndTrainModel, c, initAndTrainModelI( +integer,
+float32, +float32, +float32,
+pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer, -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 |
data | +matrix | Column-major input data (or row-major input data if rowMajor = true). | - |
responses | +vector | A vector of targets. | - |
rowMajor | +integer(bool) | Set to false if the data is row-major. | (1)true |
error | -float | minimum cost error | - |
lars_activeSet/1
Get the set of active dimensions
%% predicate definition
lars_activeSet(ActiveSetList) :-
activeSetI(Y, Ysize),
convert_float_array_to_list(Y, Ysize, ActiveSetList).
%% foreign c++ predicate definition
foreign(activeSet, c, activeSetI(-pointer(float_array), -integer)).
Parameters
Name | Type | Description | Default |
---|---|---|---|
activeSet | -vector | Get the set of active dimensions | - |
lars_beta/1
Get the solution coefficients.
%% predicate definition
lars_beta(BetaList) :-
betaI(Y, Ysize),
convert_float_array_to_list(Y, Ysize, BetaList).
%% foreign c++ predicate definition
foreign(beta, c, betaI(-pointer(float_array), -integer)).
Parameters
Name | Type | Description | Default |
---|---|---|---|
beta | -vector | Get the solution coefficients. | - |
lars_betaPath/2
Get the set of coefficients after each iteration. The solution is the last element.
%% predicate definition
lars_betaPath(BetaList, XCols) :-
betaPathI(X, XCols, XRows),
convert_float_array_to_2d_list(X, XCols, XRows, BetaList).
%% foreign c++ predicate definition
foreign(betaPath, c, betaPathI(-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. | - |
lars_computeError/5
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.
%% predicate definition
lars_computeError(DataList, DataRows, ResponsesList, RowMajor, Error) :-
convert_list_to_float_array(DataList, DataRows, array(Xsize, Xrownum, X)),
convert_list_to_float_array(ResponsesList, array(Ysize, Y)),
computeErrorI(X, Xsize, Xrownum, Y, Ysize, RowMajor, Error).
%% foreign c++ predicate definition
foreign(computeError, c, computeErrorI( +pointer(float_array), +integer, +integer,
+pointer(float_array), +integer,
+integer,
[-float32])).
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. | - |
lars_lambdaPath/1
Get the set of values for lambda1 after each iteration; the solution is the last element.
%% predicate definition
lars_lambdaPath(LambdaPathList) :-
lambdaPathI(Y, Ysize),
convert_float_array_to_list(Y, Ysize, LambdaPathList).
%% foreign c++ predicate definition
foreign(lambdaPath, c, lambdaPathI(-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. | - |
lars_matUtriCholFactor/2
Get the upper triangular cholesky factor.
%% predicate definition
lars_matUtriCholFactor(FactorList, XCols) :-
matUtriCholFactorI(X, XCols, XRows),
convert_float_array_to_2d_list(X, XCols, XRows, FactorList).
%% foreign c++ predicate definition
foreign(matUtriCholFactor, c, matUtriCholFactorI(-pointer(float_array), -integer, -integer)).
Parameters
Name | Type | Description | Default |
---|---|---|---|
factor | -matrix | Get the upper triangular cholesky factor. | - |
lars_predict/4
Predict y_i for each data point in the given data matrix using the currently-trained LARS model.
%% predicate definition
lars_predict(PointsList, PointsRows, PredicList, RowMajor) :-
convert_list_to_float_array(PointsList, PointsRows, array(Xsize, Xrownum, X)),
predictI(X, Xsize, Xrownum, Y, Ysize, RowMajor),
convert_float_array_to_list(Y, Ysize, PredicList).
%% foreign c++ predicate definition
foreign(predict, c, predictI( +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 |
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.
added some of the links from the python documentation