Loading...
Searching...
No Matches
pappso::CubicSplineModel Class Reference

`#include <cubicsplinemodel.h>`

## Public Member Functions

| CubicSplineModel ()
| CubicSplineModel (const QList< double > &x_values, const QList< double > &y_values)
| CubicSplineModel (const QMap< double, double > &x_y_values_map)
| CubicSplineModel (const CubicSplineModel &other)
CubicSplineModel * | clone (const CubicSplineModel &other)
virtual | ~CubicSplineModel ()
void | setup (const QList< double > &x_values, const QList< double > &y_values)
CubicSplineModel & | operator= (const CubicSplineModel &other)
const QList< double > & | getKnots () const
double | evalSplineAt (double x_value) const
double | derivative (const double x_value) const
double | derivatives (const double x_value, unsigned order) const

## Protected Attributes

QString | m_name = "prova"
QList< double > | m_constCoeffs
QList< double > | m_linearCoeffs
QList< double > | m_quadraticCoeffs
QList< double > | m_cubicCoeffs
QList< double > | m_knots

## Detailed Description

Definition at line 23 of file cubicsplinemodel.h.

## Constructor & Destructor Documentation

## CubicSplineModel() [1/4]

pappso::CubicSplineModel::CubicSplineModel | ( |  | ) |

Definition at line 24 of file cubicsplinemodel.cpp.

{
// qDebug() << "Allocating:" << this;
}

Referenced by CubicSplineModel(), CubicSplineModel(), clone(), and operator=().

## CubicSplineModel() [2/4]

pappso::CubicSplineModel::CubicSplineModel | ( | const QList< double > & | x_values,
|  | const QList< double > & | y_values )

explicit

Definition at line 29 of file cubicsplinemodel.cpp.

{
// qDebug() << "Allocating:" << this;
Q_ASSERT(x_values.size() == y_values.size());
Q_ASSERT(x_values.size() >= 2);
double eps = std::numeric_limits<double>::epsilon();
// Ensure the x_values are sorted increasingly.
Q_ASSERT(std::adjacent_find(
x_values.cbegin(), x_values.cend(), [=](double a, double b) {
return !(b > a + eps);
}) == x_values.cend());
setup(x_values, y_values);
// qDebug() << "Number of knots:" << m_knots.size();
}
pappso::CubicSplineModel::setup
void setup(const QList< double > &x_values, const QList< double > &y_values)
Definition cubicsplinemodel.cpp:89
pappso::PeptideIonNter::a
@ a
Definition peptide.h:77
pappso::PeptideIonNter::b
@ b
Definition peptide.h:74

References pappso::a, pappso::b, and setup().

## CubicSplineModel() [3/4]

pappso::CubicSplineModel::CubicSplineModel | ( | const QMap< double, double > & | x_y_values_map | ) |

explicit

Definition at line 52 of file cubicsplinemodel.cpp.

: CubicSplineModel(x_y_values_map.keys(), x_y_values_map.values())
{
}
pappso::CubicSplineModel::CubicSplineModel
CubicSplineModel()
Definition cubicsplinemodel.cpp:24

References CubicSplineModel().

## CubicSplineModel() [4/4]

pappso::CubicSplineModel::CubicSplineModel | ( | const CubicSplineModel & | other | ) |

Definition at line 57 of file cubicsplinemodel.cpp.

{
// qDebug() << "Allocating:" << this;
m_constCoeffs = other.m_constCoeffs;
m_linearCoeffs = other.m_linearCoeffs;
m_quadraticCoeffs = other.m_quadraticCoeffs;
m_cubicCoeffs = other.m_cubicCoeffs;
m_knots = other.m_knots;
}
pappso::CubicSplineModel::m_quadraticCoeffs
QList< double > m_quadraticCoeffs
Definition cubicsplinemodel.h:51
pappso::CubicSplineModel::m_linearCoeffs
QList< double > m_linearCoeffs
Definition cubicsplinemodel.h:50
pappso::CubicSplineModel::m_cubicCoeffs
QList< double > m_cubicCoeffs
Definition cubicsplinemodel.h:52
pappso::CubicSplineModel::m_constCoeffs
QList< double > m_constCoeffs
Definition cubicsplinemodel.h:49
pappso::CubicSplineModel::m_knots
QList< double > m_knots
Definition cubicsplinemodel.h:53

References CubicSplineModel(), m_constCoeffs, m_cubicCoeffs, m_knots, m_linearCoeffs, and m_quadraticCoeffs.

## ~CubicSplineModel()

pappso::CubicSplineModel::~CubicSplineModel | ( |  | ) |

virtual

Definition at line 83 of file cubicsplinemodel.cpp.

{
// qDebug() << "Destructing the cubic spline model";
}

## Member Function Documentation

## clone()

CubicSplineModel * pappso::CubicSplineModel::clone | ( | const CubicSplineModel & | other | ) |

Definition at line 68 of file cubicsplinemodel.cpp.

{
// qDebug() << "Cloning.";
CubicSplineModel *copy_p = new CubicSplineModel();
copy_p->m_name = other.m_name;
copy_p->m_constCoeffs = other.m_constCoeffs;
copy_p->m_linearCoeffs = other.m_linearCoeffs;
copy_p->m_quadraticCoeffs = other.m_quadraticCoeffs;
copy_p->m_cubicCoeffs = other.m_cubicCoeffs;
copy_p->m_knots = other.m_knots;
return copy_p;
}

References CubicSplineModel(), m_constCoeffs, m_cubicCoeffs, m_knots, m_linearCoeffs, m_name, and m_quadraticCoeffs.

## derivative()

double pappso::CubicSplineModel::derivative | ( | const double | x_value | ) | const

Definition at line 197 of file cubicsplinemodel.cpp.

{
return derivatives(x_value, 1);
}
pappso::CubicSplineModel::derivatives
double derivatives(const double x_value, unsigned order) const
Definition cubicsplinemodel.cpp:203

References derivatives().

Referenced by pappso::spline_bisection().

## derivatives()

double pappso::CubicSplineModel::derivatives | ( | const double | x_value,
|  | unsigned | order ) const

Definition at line 203 of file cubicsplinemodel.cpp.

{
// qDebug() << "Size of m_knots:" << m_knots.size();
Q_ASSERT(x_value >= m_knots.front() && x_value <= m_knots.back());
Q_ASSERT(order >= 1 && order <= 3);
// determine index of closest node left of (or exactly at) x_value
unsigned i = static_cast<unsigned>(
std::lower_bound(m_knots.begin(), m_knots.end(), x_value) -
m_knots.begin());
if(m_knots[i] > x_value ||
m_knots.back() ==
x_value) // also, i must not point to last index in 'm_knots',
// since all other vectors are one element shorter
{
--i;
}
const double delta_x = x_value - m_knots[i];
if(order == 1)
{
return m_linearCoeffs[i] + 2 * m_quadraticCoeffs[i] * delta_x +
3 * m_cubicCoeffs[i] * delta_x * delta_x;
}
else if(order == 2)
{
return 2 * m_quadraticCoeffs[i] + 6 * m_cubicCoeffs[i] * delta_x;
}
else
{
return 6 * m_cubicCoeffs[i];
}
}

References m_cubicCoeffs, m_knots, m_linearCoeffs, and m_quadraticCoeffs.

Referenced by derivative().

## evalSplineAt()

double pappso::CubicSplineModel::evalSplineAt | ( | double | x_value | ) | const

Definition at line 169 of file cubicsplinemodel.cpp.

{
Q_ASSERT(x_value >= m_knots.front() || x_value <= m_knots.back());
// What is the index of the closest knot left of x_value (or the same).
unsigned i = static_cast<unsigned>(
std::lower_bound(m_knots.begin(), m_knots.end(), x_value) -
m_knots.begin());
if(m_knots[i] > x_value || m_knots.back() == x_value)
{
--i;
}
const double delta_x = x_value - m_knots[i];
double eval_value =
((m_cubicCoeffs[i] * delta_x + m_quadraticCoeffs[i]) * delta_x +
m_linearCoeffs[i]) *
delta_x +
m_constCoeffs[i];
// qDebug() << "Now returning evaluation value:" << eval_value;
return eval_value;
}

References m_constCoeffs, m_cubicCoeffs, m_knots, m_linearCoeffs, and m_quadraticCoeffs.

Referenced by pappso::spline_bisection().

## getKnots()

const QList< double > & pappso::CubicSplineModel::getKnots | ( |  | ) | const

Definition at line 163 of file cubicsplinemodel.cpp.

{
return m_knots;
}

References m_knots.

## operator=()

CubicSplineModel & pappso::CubicSplineModel::operator= | ( | const CubicSplineModel & | other | ) |

Definition at line 147 of file cubicsplinemodel.cpp.

{
if(&other == this)
return *this;
m_name = other.m_name;
m_constCoeffs = other.m_constCoeffs;
m_linearCoeffs = other.m_linearCoeffs;
m_quadraticCoeffs = other.m_quadraticCoeffs;
m_cubicCoeffs = other.m_cubicCoeffs;
m_knots = other.m_knots;
return *this;
}
pappso::CubicSplineModel::m_name
QString m_name
Definition cubicsplinemodel.h:48

References CubicSplineModel(), m_constCoeffs, m_cubicCoeffs, m_knots, m_linearCoeffs, m_name, and m_quadraticCoeffs.

## setup()

void pappso::CubicSplineModel::setup | ( | const QList< double > & | x_values,
|  | const QList< double > & | y_values )

Definition at line 89 of file cubicsplinemodel.cpp.

{
// qDebug() << "Setting up with x_values size:" << x_values.size();
Q_ASSERT(x_values.size() == y_values.size());
const size_t n = x_values.size() - 1;
std::vector<double> h;
h.reserve(n);
m_constCoeffs.reserve(n);
m_knots.reserve(n + 1);
// do the 0'th element manually, since the loop below only starts at 1
h.push_back(x_values[1] - x_values[0]);
m_knots.push_back(x_values[0]);
m_constCoeffs.push_back(y_values[0]);
std::vector<double> mu(n, 0.0);
std::vector<double> z(n, 0.0);
for(unsigned i = 1; i < n; ++i)
{
h.push_back(x_values[i + 1] - x_values[i]);
const double l =
2 * (x_values[i + 1] - x_values[i - 1]) - h[i - 1] * mu[i - 1];
mu[i] = h[i] / l;
z[i] = (3 *
(y_values[i + 1] * h[i - 1] -
y_values[i] * (x_values[i + 1] - x_values[i - 1]) +
y_values[i - 1] * h[i]) /
(h[i - 1] * h[i]) -
h[i - 1] * z[i - 1]) /
l;
// store x,y -- required for evaluation later on
m_knots.push_back(x_values[i]);
m_constCoeffs.push_back(y_values[i]);
}
// 'm_knots' needs to be full length (all other member vectors (except
// m_quadraticCoeffs) are one element shorter)
m_knots.push_back(x_values[n]);
m_linearCoeffs.resize(n);
m_cubicCoeffs.resize(n);
m_quadraticCoeffs.resize(n + 1);
m_quadraticCoeffs.back() = 0;
for(int j = static_cast<int>(n) - 1; j >= 0; --j)
{
m_quadraticCoeffs[j] = z[j] - mu[j] * m_quadraticCoeffs[j + 1];
m_linearCoeffs[j] =
(y_values[j + 1] - y_values[j]) / h[j] -
h[j] * (m_quadraticCoeffs[j + 1] + 2 * m_quadraticCoeffs[j]) / 3;
m_cubicCoeffs[j] =
(m_quadraticCoeffs[j + 1] - m_quadraticCoeffs[j]) / (3 * h[j]);
}
// qDebug() << "m_knots size:" << m_knots.size();
}
pappso::Enums::TimeUnit::h
@ h
Definition types.h:88
pappso::PeptideIonCter::z
@ z
Definition peptide.h:90

References m_constCoeffs, m_cubicCoeffs, m_knots, m_linearCoeffs, m_quadraticCoeffs, and pappso::z.

Referenced by CubicSplineModel().

## Member Data Documentation

## m_constCoeffs

QList<double> pappso::CubicSplineModel::m_constCoeffs

protected

Definition at line 49 of file cubicsplinemodel.h.

Referenced by CubicSplineModel(), clone(), evalSplineAt(), operator=(), and setup().

## m_cubicCoeffs

QList<double> pappso::CubicSplineModel::m_cubicCoeffs

protected

Definition at line 52 of file cubicsplinemodel.h.

Referenced by CubicSplineModel(), clone(), derivatives(), evalSplineAt(), operator=(), and setup().

## m_knots

QList<double> pappso::CubicSplineModel::m_knots

protected

Definition at line 53 of file cubicsplinemodel.h.

Referenced by CubicSplineModel(), clone(), derivatives(), evalSplineAt(), getKnots(), operator=(), and setup().

## m_linearCoeffs

QList<double> pappso::CubicSplineModel::m_linearCoeffs

protected

Definition at line 50 of file cubicsplinemodel.h.

Referenced by CubicSplineModel(), clone(), derivatives(), evalSplineAt(), operator=(), and setup().

## m_name

QString pappso::CubicSplineModel::m_name = "prova"

protected

Definition at line 48 of file cubicsplinemodel.h.

Referenced by clone(), and operator=().

## m_quadraticCoeffs

QList<double> pappso::CubicSplineModel::m_quadraticCoeffs

protected

Definition at line 51 of file cubicsplinemodel.h.

Referenced by CubicSplineModel(), clone(), derivatives(), evalSplineAt(), operator=(), and setup().

The documentation for this class was generated from the following files:

- pappsomspp/core/processing/detection/cubicsplinemodel.h
- pappsomspp/core/processing/detection/cubicsplinemodel.cpp