15typedef Eigen::Array<bool, Eigen::Dynamic, 1>
ArrayXb;
16typedef Eigen::Array<bool, Eigen::Dynamic, Eigen::Dynamic>
ArrayXXb;
21 ArrayXb active = beta.array() != 0.0;
28 const Eigen::ArrayXd& lambda,
29 const Eigen::ArrayXd& lambda_prev)
31 using Eigen::VectorXd;
32 using Eigen::VectorXi;
34 int pm = gradient_prev.size();
36 assert(lambda_prev.size() == lambda.size() &&
37 "lambda_prev and lambda must have the same length");
38 assert((lambda <= lambda_prev).all() &&
39 "New lambda values must be smaller than or equal to previous values");
41 const VectorXd abs_grad = gradient_prev.reshaped().cwiseAbs();
42 std::vector<int> ord =
sortIndex(abs_grad,
true);
44 assert(abs_grad.size() == lambda.size());
47 abs_grad(ord).array().eval() + lambda_prev - 2.0 * lambda;
66 ArrayXb active_set = ArrayXb::Zero(pm);
67 active_set.head(k).setOnes();
72 return which(active_set);
84 const Eigen::ArrayXd&,
85 const Eigen::ArrayXd&,
86 const Eigen::VectorXd&,
87 const std::vector<int>& full_set)
95 const Eigen::VectorXd&,
96 const Eigen::ArrayXd&,
98 const Eigen::MatrixXd&,
99 const Eigen::MatrixXd&,
100 const Eigen::VectorXd&,
101 const Eigen::VectorXd&,
103 const std::vector<int>&)
110 const Eigen::VectorXd&,
111 const Eigen::ArrayXd&,
113 const Eigen::SparseMatrix<double>&,
114 const Eigen::MatrixXd&,
115 const Eigen::VectorXd&,
116 const Eigen::VectorXd&,
118 const std::vector<int>&)
133 return { alpha_max_ind };
138 const Eigen::ArrayXd& lambda_curr,
139 const Eigen::ArrayXd& lambda_prev,
140 const Eigen::VectorXd& beta,
141 const std::vector<int>&)
143 std::vector<int> active_set =
activeSet(beta);
151template<
typename MatrixType>
153StrongScreening::checkKktViolationsImpl(Eigen::VectorXd& gradient,
154 const Eigen::VectorXd& beta,
155 const Eigen::ArrayXd& lambda_curr,
156 std::vector<int>& working_set,
158 const Eigen::MatrixXd& residual,
159 const Eigen::VectorXd& x_centers,
160 const Eigen::VectorXd& x_scales,
162 const std::vector<int>& full_set)
171 Eigen::VectorXd::Ones(x.rows()),
177 if (violations.empty()) {
185 Eigen::VectorXd::Ones(x.rows()),
191 if (violations.empty()) {
197 working_set =
setUnion(working_set, violations);
203 const Eigen::VectorXd& beta,
204 const Eigen::ArrayXd& lambda_curr,
205 std::vector<int>& working_set,
206 const Eigen::MatrixXd& x,
207 const Eigen::MatrixXd& residual,
208 const Eigen::VectorXd& x_centers,
209 const Eigen::VectorXd& x_scales,
211 const std::vector<int>& full_set)
213 return checkKktViolationsImpl(gradient,
227 const Eigen::VectorXd& beta,
228 const Eigen::ArrayXd& lambda_curr,
229 std::vector<int>& working_set,
230 const Eigen::SparseMatrix<double>& x,
231 const Eigen::MatrixXd& residual,
232 const Eigen::VectorXd& x_centers,
233 const Eigen::VectorXd& x_scales,
235 const std::vector<int>& full_set)
237 return checkKktViolationsImpl(gradient,
256std::unique_ptr<ScreeningRule>
259 if (screening_type ==
"none") {
260 return std::make_unique<NoScreening>();
261 }
else if (screening_type ==
"strong") {
262 return std::make_unique<StrongScreening>();
264 throw std::invalid_argument(
"Unknown screening type: " + screening_type);
std::vector< int > initialize(const std::vector< int > &full_set, int alpha_max_ind) override
Initialize the screening rule at the start of the path algorithm.
std::vector< int > screen(Eigen::VectorXd &gradient, const Eigen::ArrayXd &lambda_curr, const Eigen::ArrayXd &lambda_prev, const Eigen::VectorXd &beta, const std::vector< int > &full_set) override
Screen for the next path step.
std::string toString() const override
Get string representation of the screening rule.
bool checkKktViolations(Eigen::VectorXd &gradient, const Eigen::VectorXd &beta, const Eigen::ArrayXd &lambda_curr, std::vector< int > &working_set, const Eigen::MatrixXd &x, const Eigen::MatrixXd &residual, const Eigen::VectorXd &x_centers, const Eigen::VectorXd &x_scales, JitNormalization jit_normalization, const std::vector< int > &full_set) override
Check for KKT violations and update working set if necessary.
std::vector< int > strong_set
Strong set of variables.
std::vector< int > screen(Eigen::VectorXd &gradient, const Eigen::ArrayXd &lambda_curr, const Eigen::ArrayXd &lambda_prev, const Eigen::VectorXd &beta, const std::vector< int > &full_set) override
Screen for the next path step.
std::vector< int > initialize(const std::vector< int > &full_set, int alpha_max_ind) override
Initialize the screening rule at the start of the path algorithm.
std::string toString() const override
Get string representation of the screening rule.
bool checkKktViolations(Eigen::VectorXd &gradient, const Eigen::VectorXd &beta, const Eigen::ArrayXd &lambda_curr, std::vector< int > &working_set, const Eigen::MatrixXd &x, const Eigen::MatrixXd &residual, const Eigen::VectorXd &x_centers, const Eigen::VectorXd &x_scales, JitNormalization jit_normalization, const std::vector< int > &full_set) override
Check for KKT violations and update working set if necessary.
Karush-Kuhn-Tucker (KKT) optimality condition checking for SLOPE regression.
Mathematical support functions for the slope package.
Namespace containing SLOPE regression implementation.
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
Dynamic-size column vector of boolean values Wrapper around Eigen::Array<bool, Eigen::Dynamic,...
std::vector< int > kktCheck(const Eigen::VectorXd &gradient, const Eigen::VectorXd &beta, const Eigen::ArrayXd &lambda, const std::vector< int > &indices)
Checks KKT conditions for SLOPE optimization.
std::vector< int > which(const T &x)
std::unique_ptr< ScreeningRule > createScreeningRule(const std::string &screening_type)
Creates a screening rule based on the provided type.
JitNormalization
Enums to control predictor standardization behavior.
std::vector< int > setDiff(const std::vector< int > &a, const std::vector< int > &b)
Computes the set difference of two sorted integer vectors.
Eigen::Array< bool, Eigen::Dynamic, Eigen::Dynamic > ArrayXXb
Dynamic-size matrix of boolean values Wrapper around Eigen::Array<bool, Eigen::Dynamic,...
std::vector< int > setUnion(const std::vector< int > &a, const std::vector< int > &b)
Computes the union of two sorted integer vectors.
std::vector< int > strongSet(const Eigen::VectorXd &gradient_prev, const Eigen::ArrayXd &lambda, const Eigen::ArrayXd &lambda_prev)
Determines the strong set using sequential strong rules.
std::vector< int > sortIndex(T &v, const bool descending=false)
void updateGradient(Eigen::VectorXd &gradient, const T &x, const Eigen::MatrixXd &residual, const std::vector< int > &active_set, const Eigen::VectorXd &x_centers, const Eigen::VectorXd &x_scales, const Eigen::VectorXd &w, const JitNormalization jit_normalization)
std::vector< int > activeSet(const Eigen::VectorXd &beta)
Identifies previously active variables.
int whichMax(const T &x)
Returns the index of the maximum element in a container.
void inversePermute(T &values, const std::vector< int > &ind)
Screening rules for SLOPE regression optimization.
Various utility functions.