slope 0.29.0
Loading...
Searching...
No Matches
kkt_check.cpp
1#include "kkt_check.h"
2#include "math.h"
3#include "utils.h"
4#include <Eigen/Core>
5
6namespace slope {
7
8std::vector<int>
9kktCheck(const Eigen::VectorXd& gradient,
10 const Eigen::VectorXd& beta,
11 const Eigen::ArrayXd& lambda,
12 const std::vector<int>& indices)
13{
14 using namespace Eigen;
15
16 std::vector<int> out;
17
18 int pm = beta.size();
19
20 if (pm == 0) {
21 return out;
22 }
23
24 VectorXd flat_abs_gradient = gradient(indices).cwiseAbs();
25
26 auto ord = sortIndex(flat_abs_gradient, true);
27
28 // TODO: Use dualNorm() instead
29 ArrayXd diff = flat_abs_gradient(ord).array() - lambda.head(indices.size());
30 ArrayXb tmp = cumSum(diff) >= 0.0;
31 inversePermute(tmp, ord);
32
33 auto which_violations = which(tmp);
34
35 for (const auto& ind : which_violations) {
36 out.emplace_back(indices[ind]);
37 }
38
39 return out;
40}
41
42} // namespace slope
Karush-Kuhn-Tucker (KKT) optimality condition checking for SLOPE regression.
Mathematical support functions for the slope package.
Namespace containing SLOPE regression implementation.
Definition clusters.cpp:5
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
Dynamic-size column vector of boolean values Wrapper around Eigen::Array<bool, Eigen::Dynamic,...
Definition kkt_check.h:18
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.
Definition kkt_check.cpp:9
std::vector< int > which(const T &x)
Definition utils.h:60
Eigen::ArrayXd cumSum(const T &x)
Definition math.h:46
std::vector< int > sortIndex(T &v, const bool descending=false)
Definition utils.h:89
void inversePermute(T &values, const std::vector< int > &ind)
Definition utils.h:152
Various utility functions.