Changeset 4489


Ignore:
Timestamp:
08/04/04 16:45:38 (20 years ago)
Author:
merck
Message:
MMerck: Added code to calculate correlation factor.
MMerck: Added code to reverse the axis.
Location:
trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/linearregression.cpp

    r3401 r4489  
    1818#include "linearregression.h"
    1919#include <math.h>
     20#include <qstring.h>
    2021
    2122LinearRegression::LinearRegression()
     
    3334        m_dSXX = 0.0;
    3435        m_dSY  = 0.0;
     36        m_dSYY = 0.0;
    3537        m_dSXY = 0.0;
    3638        m_iNum = 0;
     39        m_zReversed = false;
    3740}
    3841
     
    4548void LinearRegression::addPoint( double p_dX, double p_dY )
    4649{
     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 );
    4756        m_dSX += p_dX;
    4857        m_dSXX += ( p_dX * p_dX );
    4958        m_dSY += p_dY;
     59        m_dSYY += ( p_dY * p_dY );
    5060        m_dSXY += ( p_dX * p_dY );
    5161        m_iNum++;
     62        qDebug( "Fit has Axis: %f   Slope: %f   with %d points", getAxis(), getSlope(), m_iNum );
    5263}
    5364
    54 double LinearRegression::getAxis()
     65double LinearRegression::getAxis( )
    5566{
    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        }
    5874        else
    5975                return 0.0;
     
    6379{
    6480        double dSlope;
    65         if( m_iNum > 0 )
     81        if( m_iNum > 1 )
    6682        {
    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;
    6990        }
    7091        else
     
    7293        return dSlope;
    7394}
     95
     96double 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  
    3535        double getAxis();
    3636        double getSlope();
     37        double getR();
     38        const bool getReversed () const { return m_zReversed; }
     39        void setReversed ( bool p_zReversed ) { m_zReversed = p_zReversed; }
    3740
    3841private:
     
    4144        double m_dSXY;                          // Sum over all X * Y
    4245        double m_dSXX;                          // Sum over all X^2
     46        double m_dSYY;                          // Sum over all Y^2
    4347        int m_iNum;
     48  bool  m_zReversed;
    4449};
    4550
Note: See TracChangeset for help on using the changeset viewer.