libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
linearregression.cpp
Go to the documentation of this file.
1
/**
2
* \file trace/linearregression.cpp
3
* \date 17/9/2016
4
* \author Olivier Langella
5
* \brief compute linear regression
6
*/
7
8
/*******************************************************************************
9
* Copyright (c) 2016 Olivier Langella <Olivier.Langella@u-psud.fr>.
10
*
11
* This file is part of peptider.
12
*
13
* peptider is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation, either version 3 of the License, or
16
* (at your option) any later version.
17
*
18
* peptider is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License
24
* along with peptider. If not, see <http://www.gnu.org/licenses/>.
25
*
26
******************************************************************************/
27
#include "
linearregression.h
"
28
#include <numeric>
29
#include <cmath>
30
31
using namespace
pappso
;
32
33
pappso::LinearRegression::LinearRegression
(
const
pappso::LinearRegression
&other)
34
:
m_slope
(other.
m_slope
),
m_intercept
(other.
m_intercept
),
m_data
(other.
m_data
)
35
{
36
}
37
38
39
LinearRegression::LinearRegression
(
const
Trace
&data)
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
53
pappso::pappso_double
sx = 0;
54
pappso::pappso_double
sxy = 0;
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
}
65
66
std::size_t
67
pappso::LinearRegression::getSize
()
const
68
{
69
return
m_data
.size();
70
}
71
72
73
pappso::pappso_double
74
LinearRegression::getIntercept
()
const
75
{
76
return
m_intercept
;
77
}
78
pappso::pappso_double
79
LinearRegression::getSlope
()
const
80
{
81
return
m_slope
;
82
}
83
pappso::pappso_double
84
LinearRegression::getYfromX
(
pappso::pappso_double
x
)
const
85
{
86
return
(
m_slope
*
x
+
m_intercept
);
87
}
88
89
double
90
LinearRegression::getRmsd
()
const
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
}
106
107
double
108
LinearRegression::getNrmsd
()
const
109
{
110
return
(
getRmsd
() / (
maxYDataPoint
(
m_data
.begin(),
m_data
.end())->y -
111
minYDataPoint
(
m_data
.begin(),
m_data
.end())->y));
112
}
113
114
double
115
LinearRegression::getCoefficientOfDetermination
()
const
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
}
pappso::LinearRegression
Definition
linearregression.h:33
pappso::LinearRegression::getIntercept
double getIntercept() const
Definition
linearregression.cpp:74
pappso::LinearRegression::getSize
std::size_t getSize() const
get data size
Definition
linearregression.cpp:67
pappso::LinearRegression::m_data
Trace m_data
Definition
linearregression.h:60
pappso::LinearRegression::m_slope
double m_slope
Definition
linearregression.h:58
pappso::LinearRegression::getYfromX
double getYfromX(double score) const
Definition
linearregression.cpp:84
pappso::LinearRegression::m_intercept
double m_intercept
Definition
linearregression.h:59
pappso::LinearRegression::getRmsd
double getRmsd() const
get Root-Mean-Square Deviation
Definition
linearregression.cpp:90
pappso::LinearRegression::getNrmsd
double getNrmsd() const
get Normalized Root-Mean-Square Deviation
Definition
linearregression.cpp:108
pappso::LinearRegression::getSlope
double getSlope() const
Definition
linearregression.cpp:79
pappso::LinearRegression::LinearRegression
LinearRegression(const Trace &data)
Definition
linearregression.cpp:39
pappso::LinearRegression::getCoefficientOfDetermination
double getCoefficientOfDetermination() const
get Coefficient of determination (R2)
Definition
linearregression.cpp:115
pappso::Trace
A simple container of DataPoint instances.
Definition
trace.h:152
linearregression.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition
trace.cpp:169
pappso::PeptideIonNter::a
@ a
Definition
peptide.h:77
pappso::PeptideIonNter::b
@ b
Definition
peptide.h:74
pappso::PeptideIonCter::y
@ y
Definition
peptide.h:87
pappso::PeptideIonCter::x
@ x
Definition
peptide.h:92
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition
types.h:60
pappso::meanYTrace
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
pappso::sumYTrace
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
pappso::minYDataPoint
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition
trace.cpp:152
pappso::DataPoint
Definition
datapoint.h:22
pappsomspp
core
trace
linearregression.cpp
Generated on
for libpappsomspp by
1.17.0