MLPACK  1.0.8
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