cctw  0.2.1
Public Slots | Public Member Functions | Private Attributes | List of all members
CctwLinearFitter Class Reference

#include <cctwlinearfitter.h>

Inheritance diagram for CctwLinearFitter:
Inheritance graph
Collaboration diagram for CctwLinearFitter:
Collaboration graph

Public Slots

void startNewFit ()
 
void appendPoint (double x, double y)
 
void performFit (int skipStart, int skipEnd)
 
double slope ()
 
double intercept ()
 
double rSquared ()
 
- Public Slots inherited from CctwObject
virtual void printLine (QString line)
 
virtual void printMessage (QString msg, QDateTime dt=QDateTime::currentDateTime())
 
virtual QString settingsScript ()
 
QString scriptValueLiteral (QVariant v)
 

Public Member Functions

 CctwLinearFitter (QString name, QObject *parent=0)
 
- Public Member Functions inherited from CctwObject
 CctwObject (QString name, QObject *parent=0)
 
virtual void writeSettings (QSettings *set, QString section)
 
virtual void readSettings (QSettings *set, QString section)
 

Private Attributes

QVector< double > m_XData
 
QVector< double > m_YData
 
double m_Slope
 
double m_Intercept
 
double m_RSquared
 

Additional Inherited Members

- Properties inherited from CctwObject
QString name
 

Detailed Description

Definition at line 6 of file cctwlinearfitter.h.

Constructor & Destructor Documentation

CctwLinearFitter::CctwLinearFitter ( QString  name,
QObject *  parent = 0 
)
explicit

Definition at line 3 of file cctwlinearfitter.cpp.

References startNewFit().

3  :
4  CctwObject(name, parent)
5 {
6  startNewFit();
7 }
QString name
Definition: cctwobject.h:32
CctwObject(QString name, QObject *parent=0)
Definition: cctwobject.cpp:7

Member Function Documentation

void CctwLinearFitter::appendPoint ( double  x,
double  y 
)
slot

Definition at line 18 of file cctwlinearfitter.cpp.

References m_XData, and m_YData.

19 {
20  m_XData.append(x);
21  m_YData.append(y);
22 }
QVector< double > m_YData
QVector< double > m_XData
double CctwLinearFitter::intercept ( )
slot

Definition at line 64 of file cctwlinearfitter.cpp.

References m_Intercept.

65 {
66  return m_Intercept;
67 }
void CctwLinearFitter::performFit ( int  skipStart,
int  skipEnd 
)
slot

Definition at line 24 of file cctwlinearfitter.cpp.

References m_Intercept, m_RSquared, m_Slope, m_XData, and m_YData.

25 {
26  int start = skipStart, end = m_XData.count()-skipEnd;
27 
28  double n = 0, meanx = 0, meany = 0;
29 
30  for (int i=start; i<end; i++) {
31  n += 1;
32  meanx += m_XData[i];
33  meany += m_YData[i];
34  }
35 
36  meanx /= n;
37  meany /= n;
38 
39  double ssxx = 0, ssyy = 0, ssxy = 0;
40 
41  for (int i=start; i<end; i++) {
42  double x = m_XData[i] - meanx;
43  double y = m_YData[i] - meany;
44 
45  ssxx += x*x;
46  ssyy += y*y;
47  ssxy += x*y;
48  }
49 
50  ssxx /= n;
51  ssyy /= n;
52  ssxy /= n;
53 
54  m_Slope = ssxy / ssxx;
55  m_Intercept = meany - m_Slope*meanx;
56  m_RSquared = (ssxy*ssxy)/(ssxx*ssyy);
57 }
QVector< double > m_YData
QVector< double > m_XData
double CctwLinearFitter::rSquared ( )
slot

Definition at line 69 of file cctwlinearfitter.cpp.

References m_RSquared.

70 {
71  return m_RSquared;
72 }
double CctwLinearFitter::slope ( )
slot

Definition at line 59 of file cctwlinearfitter.cpp.

References m_Slope.

60 {
61  return m_Slope;
62 }
void CctwLinearFitter::startNewFit ( )
slot

Definition at line 9 of file cctwlinearfitter.cpp.

References m_Intercept, m_RSquared, m_Slope, m_XData, and m_YData.

Referenced by CctwLinearFitter().

10 {
11  m_XData.resize(0);
12  m_YData.resize(0);
13  m_Slope = 0;
14  m_Intercept = 0;
15  m_RSquared = 0;
16 }
QVector< double > m_YData
QVector< double > m_XData

Member Data Documentation

double CctwLinearFitter::m_Intercept
private

Definition at line 26 of file cctwlinearfitter.h.

Referenced by intercept(), performFit(), and startNewFit().

double CctwLinearFitter::m_RSquared
private

Definition at line 27 of file cctwlinearfitter.h.

Referenced by performFit(), rSquared(), and startNewFit().

double CctwLinearFitter::m_Slope
private

Definition at line 25 of file cctwlinearfitter.h.

Referenced by performFit(), slope(), and startNewFit().

QVector<double> CctwLinearFitter::m_XData
private

Definition at line 23 of file cctwlinearfitter.h.

Referenced by appendPoint(), performFit(), and startNewFit().

QVector<double> CctwLinearFitter::m_YData
private

Definition at line 24 of file cctwlinearfitter.h.

Referenced by appendPoint(), performFit(), and startNewFit().


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