MLPACK  1.0.11
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 <mlpack/core.hpp>
38 
39 namespace mlpack {
40 namespace regression {
41 
42 // beta is the estimator
43 // yHat is the prediction from the current estimator
44 
99 class LARS
100 {
101  public:
112  LARS(const bool useCholesky,
113  const double lambda1 = 0.0,
114  const double lambda2 = 0.0,
115  const double tolerance = 1e-16);
116 
129  LARS(const bool useCholesky,
130  const arma::mat& gramMatrix,
131  const double lambda1 = 0.0,
132  const double lambda2 = 0.0,
133  const double tolerance = 1e-16);
134 
149  void Regress(const arma::mat& data,
150  const arma::vec& responses,
151  arma::vec& beta,
152  const bool transposeData = true);
153 
155  const std::vector<size_t>& ActiveSet() const { return activeSet; }
156 
159  const std::vector<arma::vec>& BetaPath() const { return betaPath; }
160 
163  const std::vector<double>& LambdaPath() const { return lambdaPath; }
164 
166  const arma::mat& MatUtriCholFactor() const { return matUtriCholFactor; }
167 
168  // Returns a string representation of this object.
169  std::string ToString() const;
170 
171  private:
173  arma::mat matGramInternal;
174 
176  const arma::mat& matGram;
177 
179  arma::mat matUtriCholFactor;
180 
183 
185  bool lasso;
187  double lambda1;
188 
192  double lambda2;
193 
195  double tolerance;
196 
198  std::vector<arma::vec> betaPath;
199 
201  std::vector<double> lambdaPath;
202 
204  std::vector<size_t> activeSet;
205 
207  std::vector<bool> isActive;
208 
209  // Set of variables that are ignored (if any).
210 
212  std::vector<size_t> ignoreSet;
213 
215  std::vector<bool> isIgnored;
216 
222  void Deactivate(const size_t activeVarInd);
223 
229  void Activate(const size_t varInd);
230 
236  void Ignore(const size_t varInd);
237 
238  // compute "equiangular" direction in output space
239  void ComputeYHatDirection(const arma::mat& matX,
240  const arma::vec& betaDirection,
241  arma::vec& yHatDirection);
242 
243  // interpolate to compute last solution vector
244  void InterpolateBeta();
245 
246  void CholeskyInsert(const arma::vec& newX, const arma::mat& X);
247 
248  void CholeskyInsert(double sqNormNewX, const arma::vec& newGramCol);
249 
250  void GivensRotate(const arma::vec::fixed<2>& x,
251  arma::vec::fixed<2>& rotatedX,
252  arma::mat& G);
253 
254  void CholeskyDelete(const size_t colToKill);
255 };
256 
257 }; // namespace regression
258 }; // namespace mlpack
259 
260 #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:166
std::vector< bool > isIgnored
Membership indicator for set of ignored variables.
Definition: lars.hpp:215
std::vector< bool > isActive
Active set membership indicator (for each dimension).
Definition: lars.hpp:207
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:176
double tolerance
Tolerance for main loop.
Definition: lars.hpp:195
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
std::vector< double > lambdaPath
Value of lambda_1 for each solution in solution path.
Definition: lars.hpp:201
bool lasso
True if this is the LASSO problem.
Definition: lars.hpp:185
std::string ToString() const
std::vector< size_t > activeSet
Active set of dimensions.
Definition: lars.hpp:204
const std::vector< size_t > & ActiveSet() const
Access the set of active dimensions.
Definition: lars.hpp:155
arma::mat matUtriCholFactor
Upper triangular cholesky factor; initially 0x0 matrix.
Definition: lars.hpp:179
double lambda1
Regularization parameter for l1 penalty.
Definition: lars.hpp:187
void Ignore(const size_t varInd)
Add dimension varInd to ignores set (never removed).
std::vector< arma::vec > betaPath
Solution path.
Definition: lars.hpp:198
std::vector< size_t > ignoreSet
Set of ignored variables (for dimensions in span{active set dimensions}).
Definition: lars.hpp:212
bool elasticNet
True if this is the elastic net problem.
Definition: lars.hpp:190
An implementation of LARS, a stage-wise homotopy-based algorithm for l1-regularized linear regression...
Definition: lars.hpp:99
bool useCholesky
Whether or not to use Cholesky decomposition when solving linear system.
Definition: lars.hpp:182
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:192
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:163
void Deactivate(const size_t activeVarInd)
Remove activeVarInd'th element from active set.
arma::mat matGramInternal
Gram matrix.
Definition: lars.hpp:173
const std::vector< arma::vec > & BetaPath() const
Access the set of coefficients after each iteration; the solution is the last element.
Definition: lars.hpp:159
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.