17 std::vector<double> & y,
const double lambda,
const double p,
const unsigned int s,
18 const unsigned int loop,
const double eps
22 throw std::invalid_argument(
"BaselineAsLS(): the length of y is zero.");
26 throw std::invalid_argument(
"BaselineAsLS(): non-positive lambda value is given.");
30 throw std::invalid_argument(
"BaselineAsLS(): non-positive p value is given.");
34 throw std::invalid_argument(
"BaselineAsLS(): s must be 1, 2 or 3.");
38 throw std::invalid_argument(
"BaselineAsLS(): loop is zero.");
42 throw std::invalid_argument(
"BaselineAsLS(): non-positive eps value is given.");
46 Eigen::VectorXd yy, w, w_old, z, pv(m), npv;
47 Eigen::SparseMatrix<double> I, D, lambdaDTD;
49 yy = Eigen::VectorXd::Map(y.data(), m);
54 npv = (1 - pv.array()).matrix();
59 lambdaDTD = lambda * (D.transpose() * D);
61 for(
unsigned int i = 0; i < loop; i++) {
63 w = (yy.array() > z.array()).select(pv, npv);
65 if(((w.array() - w_old.array()).abs() < eps).all()) {
72 std::vector<double> result(z.size());
73 Eigen::VectorXd::Map(result.data(), result.size()) = z;
const std::vector< double > BaselineAsLS(std::vector< double > &y, const double lambda, const double p, const unsigned int s, const unsigned int loop, const double eps)
Performs baseline estimation using Asymmetric Least Squares Smoothing (AsLS).
Baseline estimation using Asymmetric Least Squares Smoothing(AsLS).
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).
Smoothing using Whittaker smoother.