CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

AutocorrelationAnalyzer Class Reference

#include <AutocorrelationAnalyzer.h>

List of all members.

Public Member Functions

template<class T >
void analyze (const T &t)
 AutocorrelationAnalyzer (int size)
double correlation (int i, int j)
double covariance (int i, int j)
double mean (int i)
 indexing starts from 0

Private Member Functions

void calculate ()

Private Attributes

bool calculated_
CLHEP::HepSymMatrix theCorrelations
CLHEP::HepSymMatrix theCovariances
CLHEP::HepVector theMeans
int theNTotal
int theSize

Friends

std::ostream & operator<< (std::ostream &os, AutocorrelationAnalyzer &aa)

Detailed Description

This class accepts objects which support the [] operator, such as a digi or a vector, and calculates the correlation matrix between the components Rick Wilkinson, Fedor Ratnikov

Definition at line 15 of file AutocorrelationAnalyzer.h.


Constructor & Destructor Documentation

AutocorrelationAnalyzer::AutocorrelationAnalyzer ( int  size) [explicit]

Member Function Documentation

template<class T >
void AutocorrelationAnalyzer::analyze ( const T t) [inline]

Definition at line 26 of file AutocorrelationAnalyzer.h.

References theCovariances, theMeans, theNTotal, and theSize.

  {
    for (int ii = 0; ii < theSize; ii++) {
      theMeans[ii] += t[ii];
      for (int ij = ii; ij < theSize; ij++) {
        theCovariances[ii][ij] += t[ii] * t[ij];
      }
    }
    ++theNTotal;
  }
void AutocorrelationAnalyzer::calculate ( ) [private]

Definition at line 41 of file AutocorrelationAnalyzer.cc.

References calculated_, gen::k, mathSSE::sqrt(), theCorrelations, theCovariances, theMeans, theNTotal, and theSize.

Referenced by correlation(), covariance(), mean(), and operator<<().

{
  for(int k = 0; k < theSize; ++k)
  {
    theMeans[k] /= theNTotal;
    for (int kk = k; kk < theSize; kk++) 
    {
      theCovariances[k][kk] /= theNTotal;
    }
  }

  for (int k = 0; k < theSize; k++) 
  {
    for (int kk = k; kk < theSize; kk++)
    {
      theCorrelations[k][kk] = theCovariances[k][kk]
        / sqrt (theCovariances[k][k]*theCovariances[kk][kk]);
    }
  }

  calculated_ = true;
}
double AutocorrelationAnalyzer::correlation ( int  i,
int  j 
)

Definition at line 32 of file AutocorrelationAnalyzer.cc.

References calculate(), calculated_, theCorrelations, and theSize.

{
  if(!calculated_) calculate();
  assert(i<=theSize && j<=theSize);
  return theCorrelations(i+1,j+1);
}
double AutocorrelationAnalyzer::covariance ( int  i,
int  j 
)

Definition at line 24 of file AutocorrelationAnalyzer.cc.

References calculate(), calculated_, theCovariances, and theSize.

{
  if(!calculated_) calculate();
  assert(i<=theSize && j<=theSize);
  return theCovariances(i+1,j+1);
}
double AutocorrelationAnalyzer::mean ( int  i)

indexing starts from 0

Definition at line 16 of file AutocorrelationAnalyzer.cc.

References calculate(), calculated_, i, theMeans, and theSize.

{
  if(!calculated_) calculate();
  assert(i < theSize);
  return theMeans[i];
}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
AutocorrelationAnalyzer aa 
) [friend]

Definition at line 65 of file AutocorrelationAnalyzer.cc.

{
  aa.calculate();
  os << "Means: " << std::endl << aa.theMeans << std::endl;
  os << "Covariances: " << std::endl << aa.theCovariances << std::endl;
  os << "Correlations: " << std::endl << aa.theCorrelations << std::endl;
  return os;
}

Member Data Documentation

Definition at line 47 of file AutocorrelationAnalyzer.h.

Referenced by calculate(), correlation(), covariance(), and mean().

CLHEP::HepSymMatrix AutocorrelationAnalyzer::theCorrelations [private]

Definition at line 46 of file AutocorrelationAnalyzer.h.

Referenced by calculate(), correlation(), and operator<<().

CLHEP::HepSymMatrix AutocorrelationAnalyzer::theCovariances [private]

Definition at line 45 of file AutocorrelationAnalyzer.h.

Referenced by analyze(), calculate(), covariance(), and operator<<().

CLHEP::HepVector AutocorrelationAnalyzer::theMeans [private]

Definition at line 44 of file AutocorrelationAnalyzer.h.

Referenced by analyze(), calculate(), mean(), and operator<<().

Definition at line 43 of file AutocorrelationAnalyzer.h.

Referenced by analyze(), and calculate().

Definition at line 42 of file AutocorrelationAnalyzer.h.

Referenced by analyze(), calculate(), correlation(), covariance(), and mean().