17 std::vector<double> & y,
const double lambda,
const unsigned int s,
18 const unsigned int loop,
const double eps
22 throw std::invalid_argument(
"BaselineAirPLS(): the length of y is zero.");
26 throw std::invalid_argument(
"BaselineAirPLS(): non-positive lambda value is given.");
30 throw std::invalid_argument(
"BaselineAirPLS(): s must be 1, 2 or 3.");
34 throw std::invalid_argument(
"BaselineAirPLS(): loop is zero.");
38 throw std::invalid_argument(
"BaselineAirPLS(): non-positive eps value is given.");
42 Eigen::VectorXd yy, w, z, d;
43 Eigen::SparseMatrix<double> I, D, lambdaDTD;
44 double y_abs_sum, d_sum_abs;
46 yy = Eigen::VectorXd::Map(y.data(), m);
49 y_abs_sum = yy.array().abs().matrix().sum();
54 lambdaDTD = lambda * (D.transpose() * D);
56 for(
unsigned int i = 0; i < loop; i++) {
59 d = (yy.array() >= z.array()).select(0, yy - z);
60 d_sum_abs = std::fabs(d.sum());
62 if (d_sum_abs < eps * y_abs_sum) {
66 w = (yy.array() >= z.array()).select(0, ((loop * d.array().abs()) / d_sum_abs).exp());
67 w(0) = w(w.size() - 1) = std::exp((loop * d.maxCoeff() / d_sum_abs));
70 std::vector<double> result(z.size());
72 Eigen::VectorXd::Map(result.data(), result.size()) = z;
const std::vector< double > BaselineAirPLS(std::vector< double > &y, const double lambda, const unsigned int s, const unsigned int loop, const double eps)
Performs baseline estimation using adaptive iteratively reweighted Penalized Least Squares(airPLS).
const Derived::PlainObject Diff(const Eigen::MatrixBase< Derived > &m0, const int n=1, const Dir dir=Dir::RowWise)
Calculates the n-th discrete difference along the given axis.
const std::vector< double > Whittaker(const std::vector< double > &y, const std::vector< double > &w, const double lambda, const unsigned int s)
Performs Whittaker smoothing (std::vector<double> version, with weights).