30 const QList<double> &y_values)
34 Q_ASSERT(x_values.size() == y_values.size());
35 Q_ASSERT(x_values.size() >= 2);
37 double eps = std::numeric_limits<double>::epsilon();
41 Q_ASSERT(std::adjacent_find(
42 x_values.cbegin(), x_values.cend(), [=](
double a,
double b) {
43 return !(b > a + eps);
44 }) == x_values.cend());
46 setup(x_values, y_values);
90 const QList<double> &y_values)
94 Q_ASSERT(x_values.size() == y_values.size());
96 const size_t n = x_values.size() - 1;
98 std::vector<double> h;
103 h.push_back(x_values[1] - x_values[0]);
104 m_knots.push_back(x_values[0]);
107 std::vector<double> mu(n, 0.0);
108 std::vector<double>
z(n, 0.0);
109 for(
unsigned i = 1; i < n; ++i)
111 h.push_back(x_values[i + 1] - x_values[i]);
113 2 * (x_values[i + 1] - x_values[i - 1]) - h[i - 1] * mu[i - 1];
116 (y_values[i + 1] * h[i - 1] -
117 y_values[i] * (x_values[i + 1] - x_values[i - 1]) +
118 y_values[i - 1] * h[i]) /
120 h[i - 1] *
z[i - 1]) /
123 m_knots.push_back(x_values[i]);
128 m_knots.push_back(x_values[n]);
134 for(
int j =
static_cast<int>(n) - 1; j >= 0; --j)
138 (y_values[j + 1] - y_values[j]) / h[j] -
171 Q_ASSERT(x_value >=
m_knots.front() || x_value <=
m_knots.back());
174 unsigned i =
static_cast<unsigned>(
183 const double delta_x = x_value -
m_knots[i];
207 Q_ASSERT(x_value >=
m_knots.front() && x_value <=
m_knots.back());
209 Q_ASSERT(order >= 1 && order <= 3);
212 unsigned i =
static_cast<unsigned>(
224 const double delta_x = x_value -
m_knots[i];
242 double const mz_at_left,
243 double const mz_at_right,
244 double ¢er_peak_mz,
245 double ¢er_peak_intensity,
246 double const threshold)
252 double lefthand = mz_at_left;
253 double righthand = mz_at_right;
255 bool lefthand_sign =
true;
256 double eps = std::numeric_limits<double>::epsilon();
261 double mid = (lefthand + righthand) / 2.0;
262 double midpoint_deriv_val = spline_model.
derivative(mid);
265 if(!(std::fabs(midpoint_deriv_val) > eps))
270 bool midpoint_sign = (midpoint_deriv_val < 0.0) ?
false :
true;
272 if(lefthand_sign ^ midpoint_sign)
281 while(righthand - lefthand > threshold);
283 center_peak_mz = (lefthand + righthand) / 2;
285 center_peak_intensity = spline_model.
evalSplineAt(center_peak_mz);
QList< double > m_quadraticCoeffs
void setup(const QList< double > &x_values, const QList< double > &y_values)
virtual ~CubicSplineModel()
CubicSplineModel & operator=(const CubicSplineModel &other)
QList< double > m_linearCoeffs
double derivatives(const double x_value, unsigned order) const
double derivative(const double x_value) const
const QList< double > & getKnots() const
QList< double > m_cubicCoeffs
QList< double > m_constCoeffs
CubicSplineModel * clone(const CubicSplineModel &other)
double evalSplineAt(double x_value) const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
void spline_bisection(const CubicSplineModel &spline_model, double const mz_at_left, double const mz_at_right, double ¢er_peak_mz, double ¢er_peak_intensity, double const threshold)