19 std::vector<double> & y,
const double lambda,
const unsigned int s,
20 const unsigned int loop,
const double eps
24 throw std::invalid_argument(
"BaselineArPLS(): the length of y is zero.");
28 throw std::invalid_argument(
"BaselineArPLS(): non-positive lambda value is given.");
32 throw std::invalid_argument(
"BaselineArPLS(): s must be 1, 2 or 3.");
36 throw std::invalid_argument(
"BaselineArPLS(): loop is zero.");
40 throw std::invalid_argument(
"BaselineArPLS(): non-positive eps value is given.");
44 Eigen::VectorXd yy, w, wt, z, d, tmp;
45 Eigen::SparseMatrix<double> I, D, lambdaDTD;
49 auto logistic = [](
const double xx) {
51 double t = std::exp(xx);
55 return 1 / (1 + std::exp(-xx));
59 yy = Eigen::VectorXd::Map(y.data(), m);
66 lambdaDTD = lambda * (D.transpose() * D);
68 for(
unsigned int i = 0; i < loop; i++) {
73 ct = (d.array() < 0).count();
74 mean = (d.array() < 0).select(d, 0).sum() / ct;
75 sd = std::sqrt((d.array() < 0).select((d.array() - mean).matrix(), 0).squaredNorm() / (ct - 1));
77 tmp = (-2 * (d.array() + mean - 2 * sd) / sd).matrix().unaryExpr(logistic);
78 wt = (d.array() >= 0).select(tmp, 1);
80 if ((w - wt).norm() / w.norm() < eps) {
87 std::vector<double> result(z.size());
88 Eigen::VectorXd::Map(result.data(), result.size()) = z;
const std::vector< double > BaselineArPLS(std::vector< double > &y, const double lambda, const unsigned int s, const unsigned int loop, const double eps)
Performs baseline estimation using asymmetrically reweighted Penalized Least Squares(arPLS).
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).