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 40 of file linearregression.cpp.

41{
42
43 m_data = data;
44 std::size_t size = data.size();
45 if(size > 2)
46 {
47 pappso::pappso_double x_vec_mean =
48
49 (std::accumulate(data.begin(),
50 data.end(),
51 0,
52 [](double a, const DataPoint &b) { return a + b.x; }) /
53 size);
54 pappso::pappso_double y_vec_mean =
55 (sumYTrace(data.begin(), data.end(), 0) / size);
56
59 for(size_t i = 0; i < size; i++)
60 {
61 sx += std::pow((data[i].x - x_vec_mean), 2);
62 sxy += (data[i].x - x_vec_mean) * (data[i].y - y_vec_mean);
63 }
64 m_slope = sxy / sx;
65
66 m_intercept = y_vec_mean - (m_slope * x_vec_mean);
67 }
68}
double pappso_double
A type definition for doubles.
Definition types.h:50
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:244

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.

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

Member Function Documentation

◆ getCoefficientOfDetermination()

double LinearRegression::getCoefficientOfDetermination ( ) const

get Coefficient of determination (R2)

Definition at line 120 of file linearregression.cpp.

121{
122 std::size_t size = m_data.size();
123 if(size > 2)
124 {
125 double meanY = meanYTrace(m_data.begin(), m_data.end());
126 pappso::pappso_double sum_square_deviation = 0;
127 for(size_t i = 0; i < size; i++)
128 {
129 sum_square_deviation +=
130 std::pow((m_data[i].y - getYfromX(m_data[i].x)), 2);
131 }
132 pappso::pappso_double sum_square_total = 0;
133 for(size_t i = 0; i < size; i++)
134 {
135 sum_square_total += std::pow((m_data[i].y - meanY), 2);
136 }
137 return ((double)1.0 - (sum_square_deviation / sum_square_total));
138 }
139 return 0;
140}
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:253

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

Referenced by pappso::IonIsotopeRatioScore::IonIsotopeRatioScore().

◆ getIntercept()

pappso::pappso_double LinearRegression::getIntercept ( ) const

Definition at line 78 of file linearregression.cpp.

79{
80 return m_intercept;
81}

References m_intercept.

◆ getNrmsd()

double LinearRegression::getNrmsd ( ) const

get Normalized Root-Mean-Square Deviation

Definition at line 113 of file linearregression.cpp.

114{
115 return (getRmsd() / (maxYDataPoint(m_data.begin(), m_data.end())->y -
116 minYDataPoint(m_data.begin(), m_data.end())->y));
117}
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:180
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:158

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

◆ getRmsd()

double LinearRegression::getRmsd ( ) const

get Root-Mean-Square Deviation

Definition at line 94 of file linearregression.cpp.

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

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 71 of file linearregression.cpp.

72{
73 return m_data.size();
74}

◆ getSlope()

pappso::pappso_double LinearRegression::getSlope ( ) const

Definition at line 83 of file linearregression.cpp.

84{
85 return m_slope;
86}

References m_slope.

◆ getYfromX()

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

Definition at line 88 of file linearregression.cpp.

89{
90 return (m_slope * x + m_intercept);
91}

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(), getIntercept(), and getYfromX().

◆ m_slope

double pappso::LinearRegression::m_slope = 0
private

Definition at line 58 of file linearregression.h.

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


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