Changeset 4489
- Timestamp:
- 08/04/04 16:45:38 (20 years ago)
- Location:
- trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/linearregression.cpp
r3401 r4489 18 18 #include "linearregression.h" 19 19 #include <math.h> 20 #include <qstring.h> 20 21 21 22 LinearRegression::LinearRegression() … … 33 34 m_dSXX = 0.0; 34 35 m_dSY = 0.0; 36 m_dSYY = 0.0; 35 37 m_dSXY = 0.0; 36 38 m_iNum = 0; 39 m_zReversed = false; 37 40 } 38 41 … … 45 48 void LinearRegression::addPoint( double p_dX, double p_dY ) 46 49 { 50 if( p_dX < 0. && p_dY < 0. ) 51 return; 52 53 if( m_iNum == 0) 54 qDebug( "Befor first point fit has Axis: %f Slope: %f with %d points", getAxis(), getSlope(), m_iNum ); 55 qDebug( "Adding Point %f %f", p_dX, p_dY ); 47 56 m_dSX += p_dX; 48 57 m_dSXX += ( p_dX * p_dX ); 49 58 m_dSY += p_dY; 59 m_dSYY += ( p_dY * p_dY ); 50 60 m_dSXY += ( p_dX * p_dY ); 51 61 m_iNum++; 62 qDebug( "Fit has Axis: %f Slope: %f with %d points", getAxis(), getSlope(), m_iNum ); 52 63 } 53 64 54 double LinearRegression::getAxis( )65 double LinearRegression::getAxis( ) 55 66 { 56 if( m_iNum > 0 ) 57 return ( (m_dSY / m_iNum) - getSlope() * (m_dSX / m_iNum) ); 67 if( m_iNum > 1 ) 68 { 69 if( m_zReversed ) 70 return ( (m_dSX - getSlope() * m_dSY) / m_iNum ); 71 else 72 return ( (m_dSY - getSlope() * m_dSX) / m_iNum ); 73 } 58 74 else 59 75 return 0.0; … … 63 79 { 64 80 double dSlope; 65 if( m_iNum > 0)81 if( m_iNum > 1 ) 66 82 { 67 dSlope = m_dSXY - ( m_dSX * m_dSY ) / m_iNum; 68 dSlope /= m_dSXX - ( m_dSX * m_dSX / m_iNum ); 83 double help1 = ((double) m_iNum) * m_dSXY - m_dSX * m_dSY; 84 double help2 = ((double) m_iNum) * m_dSXX - m_dSX * m_dSX; 85 double help3 = ((double) m_iNum) * m_dSYY - m_dSY * m_dSY; 86 87 dSlope = help1 / help2; 88 if( m_zReversed ) 89 dSlope = help1 / help3; 69 90 } 70 91 else … … 72 93 return dSlope; 73 94 } 95 96 double LinearRegression::getR() 97 { 98 double dR; 99 if( m_iNum > 1 ) 100 { 101 double help1 = ((double) m_iNum) * m_dSXY - m_dSX * m_dSY; 102 double help2 = ((double) m_iNum) * m_dSXX - m_dSX * m_dSX; 103 double help3 = ((double) m_iNum) * m_dSYY - m_dSY * m_dSY; 104 105 dR = help1 / sqrt( help2 * help3 ); 106 } 107 else 108 dR = 0.0; 109 return dR; 110 } -
trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/linearregression.h
r3401 r4489 35 35 double getAxis(); 36 36 double getSlope(); 37 double getR(); 38 const bool getReversed () const { return m_zReversed; } 39 void setReversed ( bool p_zReversed ) { m_zReversed = p_zReversed; } 37 40 38 41 private: … … 41 44 double m_dSXY; // Sum over all X * Y 42 45 double m_dSXX; // Sum over all X^2 46 double m_dSYY; // Sum over all Y^2 43 47 int m_iNum; 48 bool m_zReversed; 44 49 }; 45 50
Note:
See TracChangeset
for help on using the changeset viewer.