slope 0.29.0
Loading...
Searching...
No Matches
hybrid.h
Go to the documentation of this file.
1
7#pragma once
8
9#include "../clusters.h"
10#include "../losses/loss.h"
11#include "../sorted_l1_norm.h"
12#include "hybrid_cd.h"
13#include "pgd.h"
14#include "solver.h"
15#include <memory>
16
17namespace slope {
18
35class Hybrid : public SolverBase
36{
37public:
46 bool intercept,
47 bool update_clusters,
48 int cd_iterations)
50 , update_clusters(update_clusters)
51 , cd_iterations(cd_iterations)
52 {
53 }
54
56 void run(Eigen::VectorXd& beta0,
57 Eigen::VectorXd& beta,
58 Eigen::MatrixXd& eta,
59 const Eigen::ArrayXd& lambda,
60 const std::unique_ptr<Loss>& loss,
61 const SortedL1Norm& penalty,
62 const Eigen::VectorXd& gradient,
63 const std::vector<int>& working_set,
64 const Eigen::MatrixXd& x,
65 const Eigen::VectorXd& x_centers,
66 const Eigen::VectorXd& x_scales,
67 const Eigen::MatrixXd& y) override;
68
70 void run(Eigen::VectorXd& beta0,
71 Eigen::VectorXd& beta,
72 Eigen::MatrixXd& eta,
73 const Eigen::ArrayXd& lambda,
74 const std::unique_ptr<Loss>& loss,
75 const SortedL1Norm& penalty,
76 const Eigen::VectorXd& gradient,
77 const std::vector<int>& working_set,
78 const Eigen::SparseMatrix<double>& x,
79 const Eigen::VectorXd& x_centers,
80 const Eigen::VectorXd& x_scales,
81 const Eigen::MatrixXd& y) override;
82
83private:
98 template<typename MatrixType>
99 void runImpl(Eigen::VectorXd& beta0,
100 Eigen::VectorXd& beta,
101 Eigen::MatrixXd& eta,
102 const Eigen::ArrayXd& lambda,
103 const std::unique_ptr<Loss>& loss,
104 const SortedL1Norm& penalty,
105 const Eigen::VectorXd& gradient_in,
106 const std::vector<int>& working_set,
107 const MatrixType& x,
108 const Eigen::VectorXd& x_centers,
109 const Eigen::VectorXd& x_scales,
110 const Eigen::VectorXd& y)
111 {
112 using Eigen::MatrixXd;
113 using Eigen::VectorXd;
114
115 const int n = x.rows();
116
117 PGD pgd_solver(jit_normalization, intercept, "pgd");
118
119 // Run proximal gradient descent
120 pgd_solver.run(beta0,
121 beta,
122 eta,
123 lambda,
124 loss,
125 penalty,
126 gradient_in,
127 working_set,
128 x,
129 x_centers,
130 x_scales,
131 y);
132
133 Clusters clusters(beta);
134
135 VectorXd w = VectorXd::Ones(n);
136 VectorXd z = y;
137 loss->updateWeightsAndWorkingResponse(w, z, eta, y);
138
139 VectorXd residual = eta - z;
140
141 for (int it = 0; it < this->cd_iterations; ++it) {
142 coordinateDescent(beta0,
143 beta,
144 residual,
145 clusters,
146 lambda,
147 x,
148 w,
149 x_centers,
150 x_scales,
151 this->intercept,
152 this->jit_normalization,
153 this->update_clusters);
154 }
155
156 // The residual is kept up to date, but not eta. So we need to compute
157 // it here.
158 eta = residual + z;
159 // TODO: register convergence status
160 }
161
162 double pgd_learning_rate =
163 1.0;
164 double pgd_learning_rate_decr =
165 0.5;
166 bool update_clusters = false;
167 int cd_iterations = 10;
168};
169
170} // namespace slope
Representation of the clusters in SLOPE.
Definition clusters.h:18
Hybrid CD-PGD solver for SLOPE.
Definition hybrid.h:36
Hybrid(JitNormalization jit_normalization, bool intercept, bool update_clusters, int cd_iterations)
Constructs Hybrid solver for SLOPE optimization.
Definition hybrid.h:45
void run(Eigen::VectorXd &beta0, Eigen::VectorXd &beta, Eigen::MatrixXd &eta, const Eigen::ArrayXd &lambda, const std::unique_ptr< Loss > &loss, const SortedL1Norm &penalty, const Eigen::VectorXd &gradient, const std::vector< int > &working_set, const Eigen::MatrixXd &x, const Eigen::VectorXd &x_centers, const Eigen::VectorXd &x_scales, const Eigen::MatrixXd &y) override
Pure virtual function defining the solver's optimization routine.
Definition hybrid.cpp:17
Proximal Gradient Descent solver for SLOPE optimization.
Definition pgd.h:26
Abstract base class for SLOPE optimization solvers.
Definition solver.h:30
JitNormalization jit_normalization
JIT feature normalization strategy.
Definition solver.h:107
bool intercept
If true, fits intercept term.
Definition solver.h:108
Class representing the Sorted L1 Norm.
An implementation of the coordinate descent step in the hybrid algorithm for solving SLOPE.
Namespace containing SLOPE regression implementation.
Definition clusters.cpp:5
JitNormalization
Enums to control predictor standardization behavior.
void coordinateDescent(Eigen::VectorXd &beta0, Eigen::VectorXd &beta, Eigen::VectorXd &residual, Clusters &clusters, const Eigen::ArrayXd &lambda, const T &x, const Eigen::VectorXd &w, const Eigen::VectorXd &x_centers, const Eigen::VectorXd &x_scales, const bool intercept, const JitNormalization jit_normalization, const bool update_clusters)
Definition hybrid_cd.h:188
Proximal Gradient Descent solver implementation for SLOPE.
Numerical solver class for SLOPE (Sorted L-One Penalized Estimation)