MLPACK  1.0.7
lars.hpp
Go to the documentation of this file.
1 
34 #ifndef __MLPACK_METHODS_LARS_LARS_HPP
35 #define __MLPACK_METHODS_LARS_LARS_HPP
36 
37 #include <armadillo>
38 #include <mlpack/core.hpp>
39 
40 namespace mlpack {
41 namespace regression {
42 
43 // beta is the estimator
44 // yHat is the prediction from the current estimator
45 
100 class LARS
101 {
102  public:
113  LARS(const bool useCholesky,
114  const double lambda1 = 0.0,
115  const double lambda2 = 0.0,
116  const double tolerance = 1e-16);
117 
130  LARS(const bool useCholesky,
131  const arma::mat& gramMatrix,
132  const double lambda1 = 0.0,
133  const double lambda2 = 0.0,
134  const double tolerance = 1e-16);
135 
150  void Regress(const arma::mat& data,
151  const arma::vec& responses,
152  arma::vec& beta,
153  const bool transposeData = true);
154 
156  const std::vector<size_t>& ActiveSet() const { return activeSet; }
157 
160  const std::vector<arma::vec>& BetaPath() const { return betaPath; }
161 
164  const std::vector<double>& LambdaPath() const { return lambdaPath; }
165 
167  const arma::mat& MatUtriCholFactor() const { return matUtriCholFactor; }
168 
169 private:
171  arma::mat matGramInternal;
172 
174  const arma::mat& matGram;
175 
177  arma::mat matUtriCholFactor;
178 
181 
183  bool lasso;
185  double lambda1;
186 
190  double lambda2;
191 
193  double tolerance;
194 
196  std::vector<arma::vec> betaPath;
197 
199  std::vector<double> lambdaPath;
200 
202  std::vector<size_t> activeSet;
203 
205  std::vector<bool> isActive;
206 
212  void Deactivate(const size_t activeVarInd);
213 
219  void Activate(const size_t varInd);
220 
221  // compute "equiangular" direction in output space
222  void ComputeYHatDirection(const arma::mat& matX,
223  const arma::vec& betaDirection,
224  arma::vec& yHatDirection);
225 
226  // interpolate to compute last solution vector
227  void InterpolateBeta();
228 
229  void CholeskyInsert(const arma::vec& newX, const arma::mat& X);
230 
231  void CholeskyInsert(double sqNormNewX, const arma::vec& newGramCol);
232 
233  void GivensRotate(const arma::vec::fixed<2>& x,
234  arma::vec::fixed<2>& rotatedX,
235  arma::mat& G);
236 
237  void CholeskyDelete(const size_t colToKill);
238 };
239 
240 }; // namespace regression
241 }; // namespace mlpack
242 
243 #endif
void ComputeYHatDirection(const arma::mat &matX, const arma::vec &betaDirection, arma::vec &yHatDirection)
const arma::mat & MatUtriCholFactor() const
Access the upper triangular cholesky factor.
Definition: lars.hpp:167
std::vector< bool > isActive
Active set membership indicator (for each dimension).
Definition: lars.hpp:205
void Regress(const arma::mat &data, const arma::vec &responses, arma::vec &beta, const bool transposeData=true)
Run LARS.
const arma::mat & matGram
Reference to the Gram matrix we will use.
Definition: lars.hpp:174
double tolerance
Tolerance for main loop.
Definition: lars.hpp:193
std::vector< double > lambdaPath
Value of lambda_1 for each solution in solution path.
Definition: lars.hpp:199
bool lasso
True if this is the LASSO problem.
Definition: lars.hpp:183
std::vector< size_t > activeSet
Active set of dimensions.
Definition: lars.hpp:202
const std::vector< size_t > & ActiveSet() const
Access the set of active dimensions.
Definition: lars.hpp:156
arma::mat matUtriCholFactor
Upper triangular cholesky factor; initially 0x0 matrix.
Definition: lars.hpp:177
double lambda1
Regularization parameter for l1 penalty.
Definition: lars.hpp:185
std::vector< arma::vec > betaPath
Solution path.
Definition: lars.hpp:196
bool elasticNet
True if this is the elastic net problem.
Definition: lars.hpp:188
An implementation of LARS, a stage-wise homotopy-based algorithm for l1-regularized linear regression...
Definition: lars.hpp:100
bool useCholesky
Whether or not to use Cholesky decomposition when solving linear system.
Definition: lars.hpp:180
void CholeskyInsert(const arma::vec &newX, const arma::mat &X)
void CholeskyDelete(const size_t colToKill)
double lambda2
Regularization parameter for l2 penalty.
Definition: lars.hpp:190
void Activate(const size_t varInd)
Add dimension varInd to active set.
const std::vector< double > & LambdaPath() const
Access the set of values for lambda1 after each iteration; the solution is the last element...
Definition: lars.hpp:164
void Deactivate(const size_t activeVarInd)
Remove activeVarInd&#39;th element from active set.
arma::mat matGramInternal
Gram matrix.
Definition: lars.hpp:171
const std::vector< arma::vec > & BetaPath() const
Access the set of coefficients after each iteration; the solution is the last element.
Definition: lars.hpp:160
void GivensRotate(const arma::vec::fixed< 2 > &x, arma::vec::fixed< 2 > &rotatedX, arma::mat &G)
LARS(const bool useCholesky, const double lambda1=0.0, const double lambda2=0.0, const double tolerance=1e-16)
Set the parameters to LARS.