![]() |
slope 6.0.1
|
The SLOPE model. More...
#include <slope.h>
Public Member Functions | |
| Slope ()=default | |
| void | setSolver (const std::string &solver) |
| Sets the numerical solver used to fit the model. | |
| void | setIntercept (bool intercept) |
| Sets the intercept flag. | |
| void | setNormalization (const std::string &type) |
| Sets normalization type for the design matrix. | |
| void | setUpdateClusters (bool update_clusters) |
| Sets the update clusters flag. | |
| void | setReturnClusters (const bool return_clusters) |
| Sets the return clusters flag. | |
| void | setAlphaMinRatio (double alpha_min_ratio) |
| Sets the alpha min ratio. | |
| void | setAlphaType (const std::string &alpha_type) |
| Sets the alpha type. | |
| void | setLearningRateDecr (double learning_rate_decr) |
| Sets the learning rate decrement. | |
| void | setQ (double q) |
| Sets the q value. | |
| void | setOscarParameters (const double theta1, const double theta2) |
| Sets OSCAR parameters. | |
| void | setTol (double tol) |
| Sets the tolerance value. | |
| void | setRelaxTol (double tol) |
| Sets the tolerance value for the relaxed SLOPE solver. | |
| void | setRelaxMaxOuterIterations (int max_it) |
| Sets the maximum number of outer (IRLS) iterations for the relaxed solver. | |
| void | setRelaxMaxInnerIterations (int max_it) |
| Sets the maximum number of inner iterations for the relaxed solver. | |
| void | setMaxIterations (int max_it) |
| Sets the maximum number of iterations. | |
| void | setPathLength (int path_length) |
| Sets the path length. | |
| void | setHybridCdIterations (int cd_iterations) |
| Sets the frequence of proximal gradient descent steps. | |
| void | setHybridCdType (const std::string &cd_type) |
| Sets the frequence of proximal gradient descent steps. | |
| void | setLambdaType (const std::string &lambda_type) |
| Sets the lambda type for regularization weights. | |
| void | setLoss (const std::string &loss_type) |
| Sets the loss function type. | |
| void | setScreening (const std::string &screening_type) |
| Sets the type of feature screening used, which discards predictors that are unlikely to be active. | |
| void | setModifyX (const bool modify_x) |
Controls if x should be modified-in-place. | |
| void | setDevChangeTol (const double dev_change_tol) |
| Sets tolerance in deviance change for early stopping. | |
| void | setDevRatioTol (const double dev_ratio_tol) |
| Sets tolerance in deviance change for early stopping. | |
| void | setMaxClusters (const int max_clusters) |
| Sets the maximum number of clusters. | |
| void | setCentering (const std::string &type) |
| Sets the center points for feature normalization. | |
| void | setCentering (const Eigen::VectorXd &x_centers) |
| Sets the center points for feature normalization. | |
| void | setScaling (const std::string &type) |
| Sets the scaling type. | |
| void | setDiagnostics (const bool collect_diagnostics) |
| Toggles collection of diagnostics. | |
| void | setScaling (const Eigen::VectorXd &x_scales) |
| Sets the scaling factors for feature normalization. | |
| void | setAlphaEstimationMaxIterations (const int alpha_est_maxit) |
| Sets the maximum number of iterations for the alpha estimation procedure. | |
| void | setRandomSeed (const int seed) |
| Sets the random seed. | |
| void | setRandomSeed (std::optional< int > seed) |
| Sets the random seed. | |
| bool | hasRandomSeed () const |
| Checks if a random seed is set. | |
| int | getRandomSeed () const |
| Gets the random seed. | |
| int | getAlphaEstimationMaxIterations () const |
| Gets the maximum number of iterations allowed for the alpha estimation procedure. | |
| bool | getFitIntercept () const |
| Returns the intercept flag. | |
| const std::string & | getLossType () |
| Get currently defined loss type. | |
| template<typename T > | |
| SlopePath | path (Eigen::EigenBase< T > &x, const Eigen::MatrixXd &y_in, Eigen::ArrayXd alpha=Eigen::ArrayXd::Zero(0), Eigen::ArrayXd lambda=Eigen::ArrayXd::Zero(0)) |
| Computes SLOPE regression solution path for multiple alpha and lambda values. | |
| template<typename T > | |
| SlopeFit | fit (Eigen::EigenBase< T > &x, const Eigen::MatrixXd &y_in, const double alpha=1.0, Eigen::ArrayXd lambda=Eigen::ArrayXd::Zero(0)) |
| Fits a single SLOPE regression model for given alpha and lambda values. | |
| template<typename T > | |
| SlopePath | estimateAlpha (Eigen::EigenBase< T > &x, Eigen::MatrixXd &y) |
| Estimates the regularization parameter alpha for SLOPE regression. | |
| template<typename T > | |
| SlopeFit | relax (const SlopeFit &fit, T &x, const Eigen::VectorXd &y_in, const double gamma=0.0, Eigen::VectorXd beta0=Eigen::VectorXd(0), Eigen::VectorXd beta=Eigen::VectorXd(0)) |
| Relaxes a fitted SLOPE model. | |
| template<typename T > | |
| SlopePath | relax (const SlopePath &path, T &x, const Eigen::VectorXd &y, const double gamma=0.0) |
| Relaxes a fitted SLOPE path. | |
The SLOPE model.
This class implements the SLOPE algorithm for regularized regression problems. It supports different loss functions (quadratic, logistic, poisson) and provides functionality for fitting models with sorted L1 regularization along a path of regularization parameters.
|
default |
|
inline |
Estimates the regularization parameter alpha for SLOPE regression.
This function implements an algorithm to estimate an appropriate regularization parameter (alpha) for SLOPE, which is a generalization of the lasso. When n >= p + 30, it directly estimates alpha from OLS residuals. Otherwise, it uses an iterative procedure that alternates between estimating alpha and fitting the SLOPE model.
The iterative procedure works by:
| MatrixType | The type of matrix used to store the design matrix |
| x | Design matrix with n observations and p predictors |
| y | Response matrix |
| std::runtime_error | If maximum iterations reached or if too many variables selected |
|
inline |
Fits a single SLOPE regression model for given alpha and lambda values.
| T | Matrix type for feature input (supports dense or sparse matrices) |
| x | Feature matrix of size n x p |
| y_in | Response matrix of size n x m |
| alpha | Mixing parameter for elastic net regularization |
| lambda | Vector of regularization parameters (if empty, computed automatically) |
Fits a single SLOPE model with specified regularization parameters, returning coefficients and optimization details in a SlopeFit object.
| const std::string & slope::Slope::getLossType | ( | ) |
Get currently defined loss type.
|
inline |
Computes SLOPE regression solution path for multiple alpha and lambda values.
| T | Matrix type for feature input (supports dense or sparse matrices) |
| x | Feature matrix of size n x p |
| y_in | Response matrix of size n x m |
| alpha | Sequence of mixing parameters for elastic net regularization |
| lambda | Sequence of regularization parameters (if empty, computed automatically) |
Fits SLOPE models for each combination of alpha and lambda values, storing all solutions and optimization metrics in a SlopePath object.
|
inline |
Relaxes a fitted SLOPE model.
| T | Matrix type for feature input (supports dense or sparse matrices) |
| fit | Previously fitted SLOPE model containing coefficient estimates |
| x | Feature matrix of size n x p |
| y_in | Response vector of size n |
| gamma | Relaxation parameter, proportion of SLOPE-penalized fit. Must be between 0 and 1. Default is 0.0 which means fully relaxed. |
| beta0 | Warm start intercept values (optional) |
| beta | Warm start coefficient values (optional) |
|
inline |
Relaxes a fitted SLOPE path.
| T | Matrix type for feature input (supports dense or sparse matrices) |
| path | Previously fitted SLOPE path |
| x | Feature matrix of size n x p |
| y | Response vector of size n |
| gamma | Relaxation parameter, proportion of SLOPE-penalized fit. Must be between 0 and 1. Default is 0.0 which means fully relaxed. |
| void slope::Slope::setAlphaEstimationMaxIterations | ( | const int | alpha_est_maxit | ) |
Sets the maximum number of iterations for the alpha estimation procedure.
The current stopping criterion for this solver is that the sets of selected features between two consecutive iterations is identical, but users have experienced instances where these sets will cycle back on forth between two sets, which would make the algorithm fail to converge.
| alpha_est_maxit | The maximum number of allowed iterations |
| void slope::Slope::setAlphaMinRatio | ( | double | alpha_min_ratio | ) |
Sets the alpha min ratio.
| alpha_min_ratio | The value to set for the alpha min ratio. A negative value means that the program automatically chooses 1e-4 if the number of observations is larger than the number of features and 1e-2 otherwise. |
| void slope::Slope::setAlphaType | ( | const std::string & | alpha_type | ) |
Sets the alpha type.
If "path", values of "alpha" are automatically selected to span a range from completele penalization to the almost-unpenalized case: the SLOPE path. If "estimate", which is only available for the quadratic loss, the alpha value is estimated by using the scaled L2 norm of the residuals vector from an OLS fit. In case the number of features exceeds the number of observations plus 30, then this is done iteratively starting at the null (or intercept-only) models, and proceeding by refitting slope with these estimations until the set of selected features no longer changes.
| alpha_type | The type of alpha, one of "path" and "estimate". |
| void slope::Slope::setCentering | ( | const Eigen::VectorXd & | x_centers | ) |
Sets the center points for feature normalization.
| x_centers | Vector containing center values for each feature Used in feature normalization: x_normalized = (x - center) / scale |
| void slope::Slope::setCentering | ( | const std::string & | type | ) |
Sets the center points for feature normalization.
| type | Type of centering, one of: "mean", "none" |
| void slope::Slope::setDevChangeTol | ( | const double | dev_change_tol | ) |
Sets tolerance in deviance change for early stopping.
| dev_change_tol | The tolerance for the change in deviance. |
| void slope::Slope::setDevRatioTol | ( | const double | dev_ratio_tol | ) |
Sets tolerance in deviance change for early stopping.
| dev_ratio_tol | The tolerance for the dev ratio. If the deviance exceeds this value, the path will terminate. |
| void slope::Slope::setDiagnostics | ( | const bool | collect_diagnostics | ) |
| void slope::Slope::setHybridCdIterations | ( | int | cd_iterations | ) |
Sets the frequence of proximal gradient descent steps.
| cd_iterations | Number of inner coordinate descent iterations to perform in each iteration of the hybrid solver. If set to 0, the solver will resolve into pure PGD. |
| void slope::Slope::setHybridCdType | ( | const std::string & | cd_type | ) |
Sets the frequence of proximal gradient descent steps.
| cd_type | The type of coordinate descent to use in the hybrid solver. |
| void slope::Slope::setIntercept | ( | bool | intercept | ) |
Sets the intercept flag.
| intercept | Should an intercept be fitted? |
| void slope::Slope::setLambdaType | ( | const std::string & | lambda_type | ) |
Sets the lambda type for regularization weights.
| lambda_type | The method used to compute regularization weights. Currently "bh" (Benjamini-Hochberg), "quadratic", "oscar", and "lasso" are supported. |
| void slope::Slope::setLearningRateDecr | ( | double | learning_rate_decr | ) |
Sets the learning rate decrement.
| learning_rate_decr | The value to set for the learning rate decrement for the proximal gradient descent step. |
| void slope::Slope::setLoss | ( | const std::string & | loss_type | ) |
Sets the loss function type.
| loss_type | The type of loss function to use. Supported values are:
|
| void slope::Slope::setMaxClusters | ( | const int | max_clusters | ) |
Sets the maximum number of clusters.
| max_clusters | The maximum number of clusters. SLOPE can (theoretically) select at most min(n, p) clusters (unique non-zero betas). By default, this is set to -1, which means that the number of clusters will be automatically set to the number of observations + 1. |
| void slope::Slope::setMaxIterations | ( | int | max_it | ) |
Sets the maximum number of iterations.
| max_it | The value to set for the maximum number of iterations. Must be positive. If negative (the default), then the value will be decided by the solver. |
| void slope::Slope::setModifyX | ( | const bool | modify_x | ) |
Controls if x should be modified-in-place.
If true, then x will be modified in place if it is normalized. In case when x is dense, it will be both centered and scaled. If x is sparse, it will be only scaled.
| modify_x | Whether to modfiy x in place or not |
| void slope::Slope::setNormalization | ( | const std::string & | type | ) |
Sets normalization type for the design matrix.
| type | Type of normalization: one of "standardization" or "none". |
| void slope::Slope::setOscarParameters | ( | const double | theta1, |
| const double | theta2 | ||
| ) |
Sets OSCAR parameters.
| theta1 | Parameter for OSCAR. |
| theta2 | Parameter for OSCAR. |
| void slope::Slope::setPathLength | ( | int | path_length | ) |
Sets the path length.
| path_length | The value to set for the path length. |
| void slope::Slope::setQ | ( | double | q | ) |
Sets the q value.
| q | The value to set for the q value for use in automatically generating the lambda sequence. values between 0 and 1 are allowed.. |
| void slope::Slope::setRandomSeed | ( | const int | seed | ) |
Sets the random seed.
| seed | The value to set for the path length. |
| void slope::Slope::setRandomSeed | ( | std::optional< int > | seed | ) |
Sets the random seed.
| seed | The value to set for the path length. |
| void slope::Slope::setRelaxMaxInnerIterations | ( | int | max_it | ) |
Sets the maximum number of inner iterations for the relaxed solver.
| max_it | The value to set for the maximum number of iterations. Must be positive. |
| void slope::Slope::setRelaxMaxOuterIterations | ( | int | max_it | ) |
Sets the maximum number of outer (IRLS) iterations for the relaxed solver.
| max_it | The value to set for the maximum number of iterations. Must be positive. |
| void slope::Slope::setRelaxTol | ( | double | tol | ) |
Sets the tolerance value for the relaxed SLOPE solver.
| tol | The value to set for the tolerance value. Must be positive. |
| void slope::Slope::setReturnClusters | ( | const bool | return_clusters | ) |
Sets the return clusters flag.
| return_clusters | Selects whether the fitted model should return cluster information. |
| void slope::Slope::setScaling | ( | const Eigen::VectorXd & | x_scales | ) |
Sets the scaling factors for feature normalization.
| x_scales | Vector containing scale values for each feature Used in feature normalization: x_normalized = (x - center) / scale |
| void slope::Slope::setScaling | ( | const std::string & | type | ) |
Sets the scaling type.
| type | Type of scaling, one of: "sd", "l1", "none" |
| void slope::Slope::setScreening | ( | const std::string & | screening_type | ) |
Sets the type of feature screening used, which discards predictors that are unlikely to be active.
| screening_type | Type of screening. Supported values are: are:
|
| void slope::Slope::setSolver | ( | const std::string & | solver | ) |
Sets the numerical solver used to fit the model.
| solver | One of "auto", "pgd", "fista", or "hybrid". In the first case (the default), the solver is automatically selected based on availability of the hybrid solver, which currently means that the hybrid solver is used everywhere except for the multinomial loss. |
| void slope::Slope::setTol | ( | double | tol | ) |
Sets the tolerance value.
| tol | The value to set for the tolerance value. Must be positive. |
| void slope::Slope::setUpdateClusters | ( | bool | update_clusters | ) |
Sets the update clusters flag.
| update_clusters | Selects whether the coordinate descent keeps the clusters updated. |