From 3bd4567bdfbbfe5cbb29bcb76d5c1ef88dc13d1a Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Fri, 5 Mar 2021 09:29:29 -0500 Subject: [PATCH] Add functions to access and modify parameters for training. --- src/mlpack/methods/lars/lars.cpp | 4 ++++ src/mlpack/methods/lars/lars.hpp | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/mlpack/methods/lars/lars.cpp b/src/mlpack/methods/lars/lars.cpp index 03612406fc..16bfa64124 100644 --- a/src/mlpack/methods/lars/lars.cpp +++ b/src/mlpack/methods/lars/lars.cpp @@ -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. diff --git a/src/mlpack/methods/lars/lars.hpp b/src/mlpack/methods/lars/lars.hpp index 8989d13e55..d019fec900 100644 --- a/src/mlpack/methods/lars/lars.hpp +++ b/src/mlpack/methods/lars/lars.hpp @@ -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& ActiveSet() const { return activeSet; }