Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NTuplePearsonFCN.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015 
00016 #include "NTuplePearsonFCN.h"
00017 
00018 #include "functions/FunctionBase.h"
00019 
00020 #include "datasrcs/DataPointTuple.h"
00021 #include "datasrcs/DataSource.h"
00022 
00023 using std::vector;
00024 
00025 NTuplePearsonFCN::
00026 NTuplePearsonFCN ( )
00027 {
00028 }
00029 
00030 NTuplePearsonFCN::
00031 NTuplePearsonFCN ( const NTuplePearsonFCN & fcn )
00032   : NTupleFCN ( fcn )
00033 {
00034 }
00035 
00036 StatedFCN * 
00037 NTuplePearsonFCN::
00038 clone () const
00039 {
00040   return new NTuplePearsonFCN ( *this );
00041 }
00042 
00043 double
00044 NTuplePearsonFCN::
00045 up () const
00046 {
00047   return 1.0;
00048 }
00049 
00050 namespace dp = hippodraw::DataPoint2DTuple;
00051 
00052 double
00053 NTuplePearsonFCN::
00054 objectiveValue () const
00055 {
00056   double result = 0.0;
00057 
00058   unsigned int size = m_indices.size ();
00059 
00060   if ( size == dp::SIZE ) {
00061     int ix = m_indices [ dp::X ];
00062     int iy = m_indices [ dp::Y ];
00063 
00064     unsigned int rows = m_ntuple -> rows ();
00065 
00066     for ( unsigned int i = 0; i < rows; i++ ) {
00067       if ( acceptRow ( i ) ) {
00068         const vector < double > & row = m_ntuple -> getRow ( i );
00069         double function_value = m_function -> operator () ( row [ ix ] );
00070         double diff = function_value -  row [ iy ];
00071         result += diff * diff / (function_value + 10e-6);
00072       }
00073     }
00074   }
00075   else { 
00076     unsigned int dimen = size - 2;
00077     vector < double > coord ( dimen );
00078 
00079     int iy = m_indices [ size / 2 - 1 ];
00080     int ie = m_indices [ size - 1 ];
00081 
00082     unsigned int rows = m_ntuple -> rows ();
00083 
00084     for ( unsigned int i = 0; i < rows; i++ ) {
00085       if ( acceptRow ( i ) ) {
00086         const vector < double > & row = m_ntuple -> getRow ( i );
00087 
00088         double err = ie < 0 ? 0. : row [ ie ];
00089         if ( err == 0.0 && m_has_errors ) continue;
00090         if ( m_has_errors == false ) err = 1.0;
00091 
00092         for ( unsigned int j = 0; j < dimen; j++ ) {
00093           coord [ j ] = row [ m_indices [ j ] ];
00094         }
00095         double value = m_function -> operator () ( coord );
00096         double diff = value - row [ iy ];
00097         result += diff * diff / ( value * 10e-6 );
00098       }
00099     }
00100   }
00101 
00102   return result;
00103 }
00104 
00105 bool
00106 NTuplePearsonFCN::
00107 needsIntegrated () const
00108 {
00109   return false;
00110 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3