mlpack  1.0.12
lars.hpp
Go to the documentation of this file.
1 
26 #ifndef __MLPACK_METHODS_LARS_LARS_HPP
27 #define __MLPACK_METHODS_LARS_LARS_HPP
28 
29 #include <mlpack/core.hpp>
30 
31 namespace mlpack {
32 namespace regression {
33 
34 // beta is the estimator
35 // yHat is the prediction from the current estimator
36 
91 class LARS
92 {
93  public:
104  LARS(const bool useCholesky,
105  const double lambda1 = 0.0,
106  const double lambda2 = 0.0,
107  const double tolerance = 1e-16);
108 
121  LARS(const bool useCholesky,
122  const arma::mat& gramMatrix,
123  const double lambda1 = 0.0,
124  const double lambda2 = 0.0,
125  const double tolerance = 1e-16);
126 
141  void Regress(const arma::mat& data,
142  const arma::vec& responses,
143  arma::vec& beta,
144  const bool transposeData = true);
145 
147  const std::vector<size_t>& ActiveSet() const { return activeSet; }
148 
151  const std::vector<arma::vec>& BetaPath() const { return betaPath; }
152 
155  const std::vector<double>& LambdaPath() const { return lambdaPath; }
156 
158  const arma::mat& MatUtriCholFactor() const { return matUtriCholFactor; }
159 
160  // Returns a string representation of this object.
161  std::string ToString() const;
162 
163  private:
165  arma::mat matGramInternal;
166 
168  const arma::mat& matGram;
169 
171  arma::mat matUtriCholFactor;
172 
175 
177  bool lasso;
179  double lambda1;
180 
184  double lambda2;
185 
187  double tolerance;
188 
190  std::vector<arma::vec> betaPath;
191 
193  std::vector<double> lambdaPath;
194 
196  std::vector<size_t> activeSet;
197 
199  std::vector<bool> isActive;
200 
201  // Set of variables that are ignored (if any).
202 
204  std::vector<size_t> ignoreSet;
205 
207  std::vector<bool> isIgnored;
208 
214  void Deactivate(const size_t activeVarInd);
215 
221  void Activate(const size_t varInd);
222 
228  void Ignore(const size_t varInd);
229 
230  // compute "equiangular" direction in output space
231  void ComputeYHatDirection(const arma::mat& matX,
232  const arma::vec& betaDirection,
233  arma::vec& yHatDirection);
234 
235  // interpolate to compute last solution vector
236  void InterpolateBeta();
237 
238  void CholeskyInsert(const arma::vec& newX, const arma::mat& X);
239 
240  void CholeskyInsert(double sqNormNewX, const arma::vec& newGramCol);
241 
242  void GivensRotate(const arma::vec::fixed<2>& x,
243  arma::vec::fixed<2>& rotatedX,
244  arma::mat& G);
245 
246  void CholeskyDelete(const size_t colToKill);
247 };
248 
249 }; // namespace regression
250 }; // namespace mlpack
251 
252 #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:158
std::vector< bool > isIgnored
Membership indicator for set of ignored variables.
Definition: lars.hpp:207
std::vector< bool > isActive
Active set membership indicator (for each dimension).
Definition: lars.hpp:199
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:168
double tolerance
Tolerance for main loop.
Definition: lars.hpp:187
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
std::vector< double > lambdaPath
Value of lambda_1 for each solution in solution path.
Definition: lars.hpp:193
bool lasso
True if this is the LASSO problem.
Definition: lars.hpp:177
std::string ToString() const
std::vector< size_t > activeSet
Active set of dimensions.
Definition: lars.hpp:196
const std::vector< size_t > & ActiveSet() const
Access the set of active dimensions.
Definition: lars.hpp:147
arma::mat matUtriCholFactor
Upper triangular cholesky factor; initially 0x0 matrix.
Definition: lars.hpp:171
double lambda1
Regularization parameter for l1 penalty.
Definition: lars.hpp:179
void Ignore(const size_t varInd)
Add dimension varInd to ignores set (never removed).
std::vector< arma::vec > betaPath
Solution path.
Definition: lars.hpp:190
std::vector< size_t > ignoreSet
Set of ignored variables (for dimensions in span{active set dimensions}).
Definition: lars.hpp:204
bool elasticNet
True if this is the elastic net problem.
Definition: lars.hpp:182
An implementation of LARS, a stage-wise homotopy-based algorithm for l1-regularized linear regression...
Definition: lars.hpp:91
bool useCholesky
Whether or not to use Cholesky decomposition when solving linear system.
Definition: lars.hpp:174
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:184
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:155
void Deactivate(const size_t activeVarInd)
Remove activeVarInd'th element from active set.
arma::mat matGramInternal
Gram matrix.
Definition: lars.hpp:165
const std::vector< arma::vec > & BetaPath() const
Access the set of coefficients after each iteration; the solution is the last element.
Definition: lars.hpp:151
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.