libpappsomspp
Library for mass spectrometry
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
31using namespace pappso;
32
37
38
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}
65
66std::size_t
68{
69 return m_data.size();
70}
71
72
80{
81 return m_slope;
82}
88
89double
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
107double
109{
110 return (getRmsd() / (maxYDataPoint(m_data.begin(), m_data.end())->y -
111 minYDataPoint(m_data.begin(), m_data.end())->y));
112}
113
114double
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}
std::size_t getSize() const
get data size
double getYfromX(double score) const
double getRmsd() const
get Root-Mean-Square Deviation
double getNrmsd() const
get Normalized Root-Mean-Square Deviation
LinearRegression(const Trace &data)
double getCoefficientOfDetermination() const
get Coefficient of determination (R2)
A simple container of DataPoint instances.
Definition trace.h:152
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:169
double pappso_double
A type definition for doubles.
Definition types.h:60
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
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
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:152