libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::LinearRegression Class Reference

#include <linearregression.h>

Public Member Functions

 LinearRegression (const Trace &data)
 LinearRegression (const LinearRegression &other)
double getYfromX (double score) const
double getIntercept () const
double getSlope () const
double getRmsd () const
 get Root-Mean-Square Deviation
double getNrmsd () const
 get Normalized Root-Mean-Square Deviation
double getCoefficientOfDetermination () const
 get Coefficient of determination (R2)
std::size_t getSize () const
 get data size

Private Attributes

double m_slope = 0
double m_intercept = 0
Trace m_data

Detailed Description

Definition at line 32 of file linearregression.h.

Constructor & Destructor Documentation

◆ LinearRegression() [1/2]

LinearRegression::LinearRegression ( const Trace & data)

Definition at line 39 of file linearregression.cpp.

40{
41
42 m_data = data;
43 std::size_t size = data.size();
44 if(size > 2)
45 {
46 pappso::pappso_double x_vec_mean =
47
48 (std::accumulate(
49 data.begin(), data.end(), 0, [](double a, const DataPoint &b) { return a + b.x; }) /
50 size);
51 pappso::pappso_double y_vec_mean = (sumYTrace(data.begin(), data.end(), 0) / size);
52
55 for(size_t i = 0; i < size; i++)
56 {
57 sx += std::pow((data[i].x - x_vec_mean), 2);
58 sxy += (data[i].x - x_vec_mean) * (data[i].y - y_vec_mean);
59 }
60 m_slope = sxy / sx;
61
62 m_intercept = y_vec_mean - (m_slope * x_vec_mean);
63 }
64}
double pappso_double
A type definition for doubles.
Definition types.h:60
double sumYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double init)
calculate the sum of y value of a trace
Definition trace.cpp:226

References pappso::a, pappso::b, m_data, m_intercept, m_slope, pappso::sumYTrace(), pappso::x, and pappso::y.

◆ LinearRegression() [2/2]

pappso::LinearRegression::LinearRegression ( const LinearRegression & other)

Definition at line 33 of file linearregression.cpp.

34 : m_slope(other.m_slope), m_intercept(other.m_intercept), m_data(other.m_data)
35{
36}

References m_data, m_intercept, and m_slope.

Member Function Documentation

◆ getCoefficientOfDetermination()

double LinearRegression::getCoefficientOfDetermination ( ) const

get Coefficient of determination (R2)

Definition at line 115 of file linearregression.cpp.

116{
117 std::size_t size = m_data.size();
118 if(size > 2)
119 {
120 double meanY = meanYTrace(m_data.begin(), m_data.end());
121 pappso::pappso_double sum_square_deviation = 0;
122 for(size_t i = 0; i < size; i++)
123 {
124 sum_square_deviation += std::pow((m_data[i].y - getYfromX(m_data[i].x)), 2);
125 }
126 pappso::pappso_double sum_square_total = 0;
127 for(size_t i = 0; i < size; i++)
128 {
129 sum_square_total += std::pow((m_data[i].y - meanY), 2);
130 }
131 return ((double)1.0 - (sum_square_deviation / sum_square_total));
132 }
133 return 0;
134}
double getYfromX(double score) const
double meanYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the mean of y value of a trace
Definition trace.cpp:234

References getYfromX(), m_data, pappso::meanYTrace(), pappso::x, and pappso::y.

Referenced by pappso::IonIsotopeRatioScore::IonIsotopeRatioScore(), and pappso::cbor::psm::PsmFeaturesScan::process().

◆ getIntercept()

pappso::pappso_double LinearRegression::getIntercept ( ) const

Definition at line 74 of file linearregression.cpp.

75{
76 return m_intercept;
77}

References m_intercept.

◆ getNrmsd()

double LinearRegression::getNrmsd ( ) const

get Normalized Root-Mean-Square Deviation

Definition at line 108 of file linearregression.cpp.

109{
110 return (getRmsd() / (maxYDataPoint(m_data.begin(), m_data.end())->y -
111 minYDataPoint(m_data.begin(), m_data.end())->y));
112}
double getRmsd() const
get Root-Mean-Square Deviation
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:169
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:152

References getRmsd(), m_data, pappso::maxYDataPoint(), and pappso::minYDataPoint().

◆ getRmsd()

double LinearRegression::getRmsd ( ) const

get Root-Mean-Square Deviation

Definition at line 90 of file linearregression.cpp.

91{
92
93 std::size_t size = m_data.size();
94 if(size > 2)
95 {
96
97 pappso::pappso_double sum_square_deviation = 0;
98 for(size_t i = 0; i < size; i++)
99 {
100 sum_square_deviation += std::pow((m_data[i].y - getYfromX(m_data[i].x)), 2);
101 }
102 return sqrt(sum_square_deviation / (double)size);
103 }
104 return 0;
105}

References getYfromX(), m_data, pappso::x, and pappso::y.

Referenced by getNrmsd().

◆ getSize()

std::size_t pappso::LinearRegression::getSize ( ) const

get data size

Definition at line 67 of file linearregression.cpp.

68{
69 return m_data.size();
70}

References m_data.

Referenced by pappso::cbor::psm::PsmFeaturesScan::process().

◆ getSlope()

pappso::pappso_double LinearRegression::getSlope ( ) const

Definition at line 79 of file linearregression.cpp.

80{
81 return m_slope;
82}

References m_slope.

◆ getYfromX()

pappso::pappso_double LinearRegression::getYfromX ( double score) const

Definition at line 84 of file linearregression.cpp.

85{
86 return (m_slope * x + m_intercept);
87}

References m_intercept, m_slope, and pappso::x.

Referenced by getCoefficientOfDetermination(), and getRmsd().

Member Data Documentation

◆ m_data

Trace pappso::LinearRegression::m_data
private

◆ m_intercept

double pappso::LinearRegression::m_intercept = 0
private

Definition at line 59 of file linearregression.h.

Referenced by LinearRegression(), LinearRegression(), getIntercept(), and getYfromX().

◆ m_slope

double pappso::LinearRegression::m_slope = 0
private

Definition at line 58 of file linearregression.h.

Referenced by LinearRegression(), LinearRegression(), getSlope(), and getYfromX().


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