Libslope is a C++ library for Sorted L-One Penalized Estimation (SLOPE). Its main purpose is to serve as a backend for R and Python packages, but it can also be used as a standalone library in the off-chance that you want to fit your models entirely through C++.
First, we define our model. Let's use logistic regression, by setting the
loss to "logistic"
.
#include "slope.h"
Slope::Model model;
model.setLoss("logistic");
Next, we set the data matrix x
and the response vector y
. Here we use some
toy data.
Eigen::MatrixXd x(3, 2);
Eigen::VectorXd y(3);
x << 1.1, 2.3, 0.2, 1.5, 0.5, 0.2;
y << 0, 1, 0;
Finally, we call the path()
method to fit the full SLOPE path.
auto res = model.path(x, y);
Now we can retrieve the coefficients by calling res.getCoefs()
.
- A C++17 compiler
- CMake 3.15 or later
- Eigen 3.4 or later
- Doxygen
- Catch2