slope 6.6.0
Loading...
Searching...
No Matches
slope_path.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include "slope_fit.h"
14#include <Eigen/Dense>
15#include <Eigen/SparseCore>
16#include <cassert>
17
18namespace slope {
19
32{
33private:
34 std::vector<SlopeFit> fits;
35
36public:
40 SlopePath() = default;
41
48 SlopePath(const std::vector<SlopeFit>& fits)
49 : fits{ fits }
50 {
51 }
52
59 const SlopeFit& operator()(const size_t step) const
60 {
61 assert(step < fits.size());
62
63 return fits[step];
64 }
65
75 std::vector<Eigen::VectorXd> getIntercepts(
76 const bool original_scale = true) const
77 {
78 std::vector<Eigen::VectorXd> intercepts;
79
80 for (const auto& fit : fits) {
81 intercepts.emplace_back(fit.getIntercepts(original_scale));
82 }
83
84 return intercepts;
85 }
86
97 std::vector<Eigen::SparseMatrix<double>> getCoefs(
98 const bool original_scale = true) const
99 {
100 std::vector<Eigen::SparseMatrix<double>> coefs;
101
102 for (const auto& fit : fits) {
103 coefs.emplace_back(fit.getCoefs(original_scale));
104 }
105
106 return coefs;
107 }
108
114 std::vector<Clusters> getClusters() const
115 {
116 std::vector<Clusters> clusters;
117
118 for (const auto& fit : fits) {
119 clusters.emplace_back(fit.getClusters());
120 }
121
122 return clusters;
123 }
124
129 Eigen::ArrayXd getAlpha() const
130 {
131
132 Eigen::ArrayXd alphas(fits.size());
133
134 for (size_t i = 0; i < fits.size(); i++) {
135 alphas(i) = fits[i].getAlpha();
136 }
137
138 return alphas;
139 }
140
144 const Eigen::ArrayXd& getLambda() const { return fits.front().getLambda(); }
145
149 std::vector<double> getDeviance() const
150 {
151 std::vector<double> deviances;
152
153 for (const auto& fit : fits) {
154 deviances.emplace_back(fit.getDeviance());
155 }
156
157 return deviances;
158 }
159
163 double getNullDeviance() const { return fits.front().getNullDeviance(); }
164
168 std::vector<std::vector<double>> getPrimals() const
169 {
170 std::vector<std::vector<double>> primals;
171
172 for (const auto& fit : fits) {
173 primals.emplace_back(fit.getPrimals());
174 }
175
176 return primals;
177 }
178
182 std::vector<std::vector<double>> getDuals() const
183 {
184 std::vector<std::vector<double>> duals;
185
186 for (const auto& fit : fits) {
187 duals.emplace_back(fit.getDuals());
188 }
189
190 return duals;
191 }
192
196 std::vector<std::vector<double>> getTime() const
197 {
198 std::vector<std::vector<double>> time;
199
200 for (const auto& fit : fits) {
201 time.emplace_back(fit.getTime());
202 }
203
204 return time;
205 }
206
210 std::vector<int> getPasses() const
211 {
212 std::vector<int> passes;
213
214 for (const auto& fit : fits) {
215 passes.emplace_back(fit.getPasses());
216 }
217
218 return passes;
219 }
220
226 const std::vector<double> getDevianceRatios() const
227 {
228 std::vector<double> ratios;
229
230 for (const auto& fit : fits) {
231 ratios.emplace_back(fit.getDevianceRatio());
232 }
233
234 return ratios;
235 }
236
242 std::vector<std::vector<double>> getGaps() const
243 {
244 std::vector<std::vector<double>> gaps;
245
246 for (const auto& fit : fits) {
247 gaps.emplace_back(fit.getGaps());
248 }
249
250 return gaps;
251 }
252
257 std::size_t size() const { return fits.size(); }
258};
259
260} // namespace slope
A class representing the results of SLOPE (Sorted L1 Penalized Estimation) fitting.
Definition slope_fit.h:27
std::vector< Eigen::VectorXd > getIntercepts(const bool original_scale=true) const
Returns the vector of intercept terms for each solution in the path.
Definition slope_path.h:75
std::vector< double > getDeviance() const
Gets the deviance values for each solution.
Definition slope_path.h:149
const SlopeFit & operator()(const size_t step) const
Get one of the coefficients along the path.
Definition slope_path.h:59
std::vector< std::vector< double > > getGaps() const
Computes the duality gaps (primal - dual objectives) for each solution.
Definition slope_path.h:242
std::vector< std::vector< double > > getDuals() const
Gets the dual objective values during optimization.
Definition slope_path.h:182
std::vector< int > getPasses() const
Gets the number of iterations for each solution.
Definition slope_path.h:210
std::vector< std::vector< double > > getPrimals() const
Gets the primal objective values during optimization.
Definition slope_path.h:168
std::vector< std::vector< double > > getTime() const
Gets the computation times for each solution.
Definition slope_path.h:196
const std::vector< double > getDevianceRatios() const
Computes the deviance ratio (explained deviance) for each solution.
Definition slope_path.h:226
SlopePath()=default
Constructs an empty SlopePath object.
const Eigen::ArrayXd & getLambda() const
Gets the lambda (regularization) weights.
Definition slope_path.h:144
Eigen::ArrayXd getAlpha() const
Gets the absolute alpha penalty scales, including when the input alphas were relative to alpha_max.
Definition slope_path.h:129
std::size_t size() const
Gets the number of solutions in the path.
Definition slope_path.h:257
std::vector< Clusters > getClusters() const
Returns the clusters for each solution in the path.
Definition slope_path.h:114
std::vector< Eigen::SparseMatrix< double > > getCoefs(const bool original_scale=true) const
Returns the vector of coefficient matrices for each solution in the path.
Definition slope_path.h:97
SlopePath(const std::vector< SlopeFit > &fits)
Constructs a SlopePath object containing SLOPE regression solution path data.
Definition slope_path.h:48
double getNullDeviance() const
Gets the null model deviance.
Definition slope_path.h:163
Namespace containing SLOPE regression implementation.
Definition clusters.h:11
SLOPE (Sorted L-One Penalized Estimation) fitting results.