10#include <Eigen/SparseCore>
33computeCenters(Eigen::VectorXd& x_centers,
const T& x,
const std::string& type)
37 if (type ==
"manual") {
38 if (x_centers.size() != p) {
39 throw std::invalid_argument(
"Invalid dimensions in centers");
42 if (!x_centers.allFinite()) {
43 throw std::invalid_argument(
"Centers must be finite");
46 }
else if (type ==
"mean") {
48 }
else if (type ==
"min") {
50 }
else if (type !=
"none") {
51 throw std::invalid_argument(
"Invalid centering type");
74computeScales(Eigen::VectorXd& x_scales,
const T& x,
const std::string& type)
78 if (type ==
"manual") {
79 if (x_scales.size() != p) {
80 throw std::invalid_argument(
"Invalid dimensions in scales");
82 if (!x_scales.allFinite()) {
83 throw std::invalid_argument(
"Scales must be finite");
85 }
else if (type ==
"sd") {
87 }
else if (type ==
"l1") {
89 }
else if (type ==
"l2") {
91 }
else if (type ==
"max_abs") {
93 }
else if (type ==
"range") {
95 }
else if (type !=
"none") {
96 throw std::invalid_argument(
"Invalid scaling type");
124 Eigen::VectorXd& x_centers,
125 Eigen::VectorXd& x_scales,
126 const std::string& centering_type,
127 const std::string& scaling_type,
130 const int p = x.cols();
137 if (scaling_type !=
"none" && scaling_type !=
"manual") {
138 for (
int j = 0; j < p; ++j) {
139 if (std::abs(x_scales(j)) == 0.0) {
145 bool center = centering_type !=
"none";
146 bool scale = scaling_type !=
"none";
147 bool center_jit = center && !modify_x;
148 bool scale_jit = scale && !modify_x;
152 if (center_jit && scale_jit) {
154 }
else if (center_jit) {
156 }
else if (scale_jit) {
162 if (modify_x && (center || scale)) {
163 for (
int j = 0; j < p; ++j) {
165 x.col(j).array() -= x_centers(j);
168 x.col(j).array() /= x_scales(j);
173 return jit_normalization;
200 Eigen::VectorXd& x_centers,
201 Eigen::VectorXd& x_scales,
202 const std::string& centering_type,
203 const std::string& scaling_type,
211 const int p = x.cols();
212 if (scaling_type !=
"none" && scaling_type !=
"manual") {
213 for (
int j = 0; j < p; ++j) {
214 if (std::abs(x_scales(j)) == 0.0) {
220 bool center = centering_type !=
"none";
221 bool scale = scaling_type !=
"none";
222 bool center_jit = center;
223 bool scale_jit = scale;
227 if (center_jit && scale_jit) {
229 }
else if (center_jit) {
231 }
else if (scale_jit) {
246 return jit_normalization;
269std::tuple<Eigen::VectorXd, Eigen::MatrixXd>
271 const Eigen::SparseMatrix<double>& beta,
272 const Eigen::VectorXd& x_centers,
273 const Eigen::VectorXd& x_scales,
274 const bool intercept);
Enums to control predictor standardization behavior.
Mathematical support functions for the slope package.
Namespace containing SLOPE regression implementation.
Eigen::VectorXd means(const Eigen::SparseMatrixBase< T > &x)
Computes the arithmetic mean for each column of a sparse matrix.
Eigen::VectorXd l1Norms(const T &x)
Computes the L1 (Manhattan) norms for each column of a matrix.
JitNormalization
Enums to control predictor standardization behavior.
@ None
No JIT normalization.
Eigen::VectorXd ranges(const Eigen::SparseMatrixBase< T > &x)
Computes the range (max - min) for each column of a matrix.
std::tuple< Eigen::VectorXd, Eigen::MatrixXd > rescaleCoefficients(const Eigen::VectorXd &beta0, const Eigen::SparseMatrix< double > &beta, const Eigen::VectorXd &x_centers, const Eigen::VectorXd &x_scales, const bool intercept)
Rescales the coefficients using the given parameters.
Eigen::VectorXd mins(const Eigen::SparseMatrixBase< T > &x)
Computes the minimum value for each column of a sparse matrix.
void computeScales(Eigen::VectorXd &x_scales, const T &x, const std::string &type)
Eigen::VectorXd stdDevs(const Eigen::SparseMatrixBase< T > &x)
Computes the standard deviation for each column of a matrix.
Eigen::VectorXd l2Norms(const Eigen::SparseMatrixBase< T > &x)
Computes the L2 (Euclidean) norms for each column of a sparse matrix.
JitNormalization normalize(Eigen::MatrixBase< T > &x, Eigen::VectorXd &x_centers, Eigen::VectorXd &x_scales, const std::string ¢ering_type, const std::string &scaling_type, const bool modify_x)
Eigen::VectorXd maxAbs(const Eigen::SparseMatrixBase< T > &x)
Computes the maximum absolute value for each column of a matrix.
void computeCenters(Eigen::VectorXd &x_centers, const T &x, const std::string &type)