Anp::DataCorr Class Reference

#include <DataCorr.h>

List of all members.

Public Member Functions

 DataCorr ()
 ~DataCorr ()
unsigned int Fill (DataIter ibeg, DataIter iend)
unsigned int Size () const
const Corr::CorrMap GetCorrCoef () const
void Reset ()

Private Attributes

unsigned int fSampleSize
Corr::DataMap fData

Detailed Description

Definition at line 35 of file DataCorr.h.


Constructor & Destructor Documentation

Anp::DataCorr::DataCorr (  ) 

Definition at line 10 of file DataCorr.cxx.

00011    :fSampleSize(0),
00012     fData()
00013 {
00014 }

Anp::DataCorr::~DataCorr (  ) 

Definition at line 17 of file DataCorr.cxx.

00018 {
00019 }


Member Function Documentation

unsigned int Anp::DataCorr::Fill ( DataIter  ibeg,
DataIter  iend 
)

Definition at line 22 of file DataCorr.cxx.

References fData, fSampleSize, Anp::Corr::Data::sum_x, Anp::Corr::Data::sum_xx, Anp::Corr::Data::sum_xy, Anp::Corr::Data::sum_y, and Anp::Corr::Data::sum_yy.

Referenced by Anp::Plot::Data::Fill().

00023 {
00024    for(DataIter xit = ibeg; xit != iend; ++xit)
00025    {
00026       const short key_x  = xit -> Key();
00027       const float data_x = xit -> Data();
00028                   
00029       for(DataIter yit = xit + 1; yit != iend; ++yit)
00030       {
00031          if(xit == yit)
00032          {
00033             continue;
00034          }
00035 
00036          const short key_y  = yit -> Key();
00037          const float data_y = yit -> Data();
00038          
00039          const Corr::Key key(key_x, key_y);
00040          
00041          Corr::Data &data = fData[key];
00042 
00043          data.sum_x  += data_x;
00044          data.sum_y  += data_y;
00045          data.sum_xx += data_x * data_x;
00046          data.sum_xy += data_x * data_y;
00047          data.sum_yy += data_y * data_y;
00048       }
00049    }
00050 
00051    return ++fSampleSize;
00052 }

const Anp::Corr::CorrMap Anp::DataCorr::GetCorrCoef (  )  const

Definition at line 55 of file DataCorr.cxx.

References fData, fSampleSize, Munits::second, Anp::Corr::Data::sum_x, Anp::Corr::Data::sum_xx, Anp::Corr::Data::sum_xy, Anp::Corr::Data::sum_y, and Anp::Corr::Data::sum_yy.

Referenced by Anp::Plot::Data::Fill().

00056 {
00057    Corr::CorrMap cmap;
00058 
00059    if(fSampleSize < 2)
00060    {
00061       std::cerr << "DataCorr::GetCorrCoef() - sample size is too small" << std::endl;
00062       return cmap;
00063    }
00064    
00065    const double inv_size = 1.0/double(fSampleSize);
00066    
00067    for(Corr::DataMap::const_iterator dit = fData.begin(); dit != fData.end(); ++dit)
00068    {
00069       const Corr::Key &key = dit -> first;
00070       const Corr::Data &data = dit -> second;      
00071 
00072       const double nom  = data.sum_xy - data.sum_x*data.sum_y * inv_size;
00073       const double den1 = data.sum_xx - data.sum_x*data.sum_x * inv_size;
00074       const double den2 = data.sum_yy - data.sum_y*data.sum_y * inv_size;
00075 
00076       if(!(den1 > 0.0) || !(den2 > 0.0))
00077       {
00078          continue;       
00079       }
00080 
00081       const double corr = nom/std::sqrt(den1 * den2);
00082 
00083       if(!cmap.insert(Corr::CorrMap::value_type(key, corr)).second)
00084       {
00085          std::cerr << "DataCorr::GetCorrCoef() - found a duplicate key" << std::endl;
00086       }      
00087    }
00088 
00089    return cmap;
00090 }

void Anp::DataCorr::Reset (  ) 

Definition at line 93 of file DataCorr.cxx.

References fData, and fSampleSize.

Referenced by Anp::Plot::Data::Fill().

00094 {
00095    fSampleSize = 0;
00096    fData.clear();
00097 }

unsigned int Anp::DataCorr::Size ( void   )  const [inline]

Definition at line 61 of file DataCorr.h.

References fSampleSize.

00061 { return fSampleSize; }


Member Data Documentation

Definition at line 54 of file DataCorr.h.

Referenced by Fill(), GetCorrCoef(), and Reset().

unsigned int Anp::DataCorr::fSampleSize [private]

Definition at line 52 of file DataCorr.h.

Referenced by Fill(), GetCorrCoef(), Reset(), and Size().


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

Generated on 3 Dec 2018 for loon by  doxygen 1.6.1