CMS 3D CMS Logo

AutocorrelationAnalyzer Class Reference

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. More...

#include <CommonTools/Statistics/interface/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_
HepSymMatrix theCorrelations
HepSymMatrix theCovariances
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]

Definition at line 5 of file AutocorrelationAnalyzer.cc.

00006 : theSize(size),
00007   theNTotal(0),
00008   theMeans(size, 0),
00009   theCovariances(theSize, 0),
00010   theCorrelations(theSize, 0),
00011   calculated_(false)
00012 {
00013 }


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.

00027   {
00028     for (int ii = 0; ii < theSize; ii++) {
00029       theMeans[ii] += t[ii];
00030       for (int ij = ii; ij < theSize; ij++) {
00031         theCovariances[ii][ij] += t[ii] * t[ij];
00032       }
00033     }
00034     ++theNTotal;
00035   }

void AutocorrelationAnalyzer::calculate (  )  [private]

Definition at line 41 of file AutocorrelationAnalyzer.cc.

References calculated_, k, kk, funct::sqrt(), theCorrelations, theCovariances, theMeans, theNTotal, and theSize.

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

00042 {
00043   for(int k = 0; k < theSize; ++k)
00044   {
00045     theMeans[k] /= theNTotal;
00046     for (int kk = k; kk < theSize; kk++) 
00047     {
00048       theCovariances[k][kk] /= theNTotal;
00049     }
00050   }
00051 
00052   for (int k = 0; k < theSize; k++) 
00053   {
00054     for (int kk = k; kk < theSize; kk++)
00055     {
00056       theCorrelations[k][kk] = theCovariances[k][kk]
00057         / sqrt (theCovariances[k][k]*theCovariances[kk][kk]);
00058     }
00059   }
00060 
00061   calculated_ = true;
00062 }

double AutocorrelationAnalyzer::correlation ( int  i,
int  j 
)

Definition at line 32 of file AutocorrelationAnalyzer.cc.

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

00033 {
00034   if(!calculated_) calculate();
00035   assert(i<=theSize && j<=theSize);
00036   return theCorrelations(i-1,j-1);
00037 }

double AutocorrelationAnalyzer::covariance ( int  i,
int  j 
)

Definition at line 24 of file AutocorrelationAnalyzer.cc.

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

00025 {
00026   if(!calculated_) calculate();
00027   assert(i<=theSize && j<=theSize);
00028   return theCovariances(i-1,j-1);
00029 }

double AutocorrelationAnalyzer::mean ( int  i  ) 

indexing starts from 0

Definition at line 16 of file AutocorrelationAnalyzer.cc.

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

00017 {
00018   if(!calculated_) calculate();
00019   assert(i < theSize);
00020   return theMeans[i];
00021 }


Friends And Related Function Documentation

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

Definition at line 65 of file AutocorrelationAnalyzer.cc.

00066 {
00067   aa.calculate();
00068   os << "Means: " << std::endl << aa.theMeans << std::endl;
00069   os << "Covariances: " << std::endl << aa.theCovariances << std::endl;
00070   os << "Correlations: " << std::endl << aa.theCorrelations << std::endl;
00071   return os;
00072 }


Member Data Documentation

bool AutocorrelationAnalyzer::calculated_ [private]

Definition at line 47 of file AutocorrelationAnalyzer.h.

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

HepSymMatrix AutocorrelationAnalyzer::theCorrelations [private]

Definition at line 46 of file AutocorrelationAnalyzer.h.

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

HepSymMatrix AutocorrelationAnalyzer::theCovariances [private]

Definition at line 45 of file AutocorrelationAnalyzer.h.

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

HepVector AutocorrelationAnalyzer::theMeans [private]

Definition at line 44 of file AutocorrelationAnalyzer.h.

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

int AutocorrelationAnalyzer::theNTotal [private]

Definition at line 43 of file AutocorrelationAnalyzer.h.

Referenced by analyze(), and calculate().

int AutocorrelationAnalyzer::theSize [private]

Definition at line 42 of file AutocorrelationAnalyzer.h.

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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:14:50 2009 for CMSSW by  doxygen 1.5.4