Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions to modify parameters for LARS #2861

Merged
merged 2 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
* `NegativeLogLikelihood<>` now expects classes in the range `0` to
`numClasses - 1` (#2534).

* Add `Lambda1()`, `Lambda2()`, `UseCholesky()`, and `Tolerance()` members to
`LARS` so parameters for training can be modified (#2861).

### mlpack 3.4.2
###### 2020-10-26
* Added Mean Absolute Percentage Error.
Expand Down
4 changes: 4 additions & 0 deletions src/mlpack/methods/lars/lars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ double LARS::Train(const arma::mat& matX,
isIgnored.clear();
matUtriCholFactor.reset();

// Update values in case lambda1 or lambda2 changed.
lasso = (lambda1 != 0);
elasticNet = (lambda1 != 0 && lambda2 != 0);

// This matrix may end up holding the transpose -- if necessary.
arma::mat dataTrans;
// dataRef is row-major.
Expand Down
20 changes: 20 additions & 0 deletions src/mlpack/methods/lars/lars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,26 @@ class LARS
arma::rowvec& predictions,
const bool rowMajor = false) const;

//! Get the L1 regularization coefficient.
double Lambda1() const { return lambda1; }
//! Modify the L1 regularization coefficient.
double& Lambda1() { return lambda1; }

//! Get the L2 regularization coefficient.
double Lambda2() const { return lambda2; }
//! Modify the L2 regularization coefficient.
double& Lambda2() { return lambda2; }

//! Get whether to use the Cholesky decomposition.
bool UseCholesky() const { return useCholesky; }
//! Modify whether to use the Cholesky decomposition.
bool& UseCholesky() { return useCholesky; }

//! Get the tolerance for maximum correlation during training.
double Tolerance() const { return tolerance; }
//! Modify the tolerance for maximum correlation during training.
double& Tolerance() { return tolerance; }

//! Access the set of active dimensions.
const std::vector<size_t>& ActiveSet() const { return activeSet; }

Expand Down