18 std::vector<double> & y,
const double lambda,
const unsigned int s,
19 const unsigned int loop,
const double eps
23 throw std::invalid_argument(
"BaselineArPLS(): the length of y is zero.");
27 throw std::invalid_argument(
"BaselineArPLS(): non-positive lambda value is given.");
31 throw std::invalid_argument(
"BaselineArPLS(): s must be 1, 2 or 3.");
35 throw std::invalid_argument(
"BaselineArPLS(): loop is zero.");
39 throw std::invalid_argument(
"BaselineArPLS(): non-positive eps value is given.");
43 Eigen::VectorXd yy, w, wt, z, d, tmp;
44 Eigen::SparseMatrix<double> I, D, lambdaDTD;
48 const double overflow = std::log(std::numeric_limits<double>::max()) / 2;
50 yy = Eigen::VectorXd::Map(y.data(), m);
57 lambdaDTD = lambda * (D.transpose() * D);
59 for(
unsigned int i = 0; i < loop; i++) {
64 ct = (d.array() < 0).count();
65 mean = (d.array() < 0).select(d, 0).sum() / ct;
66 sd = std::sqrt((d.array() < 0).select((d.array() - mean).matrix(), 0).squaredNorm() / (ct - 1));
68 tmp = ((d.array() + mean - 2 * sd) / sd).matrix();
69 tmp = (tmp.array() >= overflow).select(0, (1.0 / (1 + (2 * tmp).array().exp())).matrix());
71 wt = (d.array() >= 0).select(tmp, 1);
73 if ((w - wt).norm() / w.norm() < eps) {
80 std::vector<double> result(z.size());
82 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).