CMS 3D CMS Logo

RandomMultiGauss Class Reference

Vector of random numbers according to covariance matrix. More...

#include <CommonTools/Statistics/interface/RandomMultiGauss.h>

List of all members.

Public Member Functions

AlgebraicVector fire ()
 Generation of a vector of random numbers.
 RandomMultiGauss (const AlgebraicSymMatrix &aMatrix)
 constructor with covariance matrix only (all means = 0)
 RandomMultiGauss (const AlgebraicVector &aVector, const AlgebraicSymMatrix &aMatrix)
 constructor with explicit vector of mean values
 ~RandomMultiGauss ()

Private Member Functions

void initialise (const AlgebraicSymMatrix &)
 generation of the cholesky decomposition

Private Attributes

AlgebraicVector theMeans
int theSize
AlgebraicMatrix theTriangle


Detailed Description

Vector of random numbers according to covariance matrix.

Generates vectors of random numbers given a vector of mean values (optional) and a covariance matrix. Will accept empty rows/columns in the input matrix. Uses RandGauss with default engine for generation.

Definition at line 14 of file RandomMultiGauss.h.


Constructor & Destructor Documentation

RandomMultiGauss::RandomMultiGauss ( const AlgebraicVector aVector,
const AlgebraicSymMatrix aMatrix 
)

constructor with explicit vector of mean values

Definition at line 9 of file RandomMultiGauss.cc.

References initialise(), theMeans, and theSize.

00009                                                                                                      :
00010   theSize(aMatrix.num_row()),
00011   theMeans(aVector),
00012   theTriangle(theSize,theSize,0) {
00013   //
00014   // Check consistency
00015   //
00016   if ( theMeans.num_row() == theSize ) {
00017     initialise(aMatrix);
00018   }
00019   else {
00020 //    throw DetLogicError("RandomMultiGauss: size of vector and matrix do not match");
00021     theMeans = AlgebraicVector(theSize,0);
00022   }
00023 }
//

RandomMultiGauss::RandomMultiGauss ( const AlgebraicSymMatrix aMatrix  ) 

constructor with covariance matrix only (all means = 0)

Definition at line 27 of file RandomMultiGauss.cc.

References initialise().

00027                                                                      :
00028   theSize(aMatrix.num_row()),
00029   theMeans(theSize,0),
00030   theTriangle(theSize,theSize,0) {
00031   //
00032   initialise(aMatrix);
00033 }
//

RandomMultiGauss::~RandomMultiGauss (  )  [inline]

Definition at line 23 of file RandomMultiGauss.h.

00023 {}


Member Function Documentation

AlgebraicVector RandomMultiGauss::fire (  ) 

Generation of a vector of random numbers.

Definition at line 74 of file RandomMultiGauss.cc.

References i, theMeans, theSize, and theTriangle.

00074                                        {
00075   AlgebraicVector vRandom(theSize,0);
00076   for ( int i=0; i<theSize; i++ ) {
00077     if ( theTriangle[i][i]!=0 ) 
00078       vRandom[i] = RandGauss::shoot();
00079   }
00080   return theTriangle*vRandom+theMeans;
00081 }

void RandomMultiGauss::initialise ( const AlgebraicSymMatrix aMatrix  )  [private]

generation of the cholesky decomposition

Definition at line 37 of file RandomMultiGauss.cc.

References i1, i2, i3, funct::sqrt(), sum(), theSize, and theTriangle.

Referenced by RandomMultiGauss().

00037                                                                     {
00038   //
00039   // Cholesky decomposition with protection against empty rows/columns
00040   //
00041   for ( int i1=0; i1<theSize; i1++ ) {
00042     if ( fabs(aMatrix[i1][i1])<FLT_MIN )  continue;
00043 
00044     for ( int i2=i1; i2<theSize; i2++ ) {
00045       if ( fabs(aMatrix[i2][i2])<FLT_MIN )  continue;
00046 
00047       double sum = aMatrix[i2][i1];
00048       for ( int i3=i1-1; i3>=0; i3-- ) {
00049         if ( fabs(aMatrix[i3][i3])<FLT_MIN )  continue;
00050         sum -= theTriangle[i1][i3]*theTriangle[i2][i3];
00051       }
00052       
00053       if ( i1==i2 ) {
00054         //
00055         // check for positive definite input matrix, but allow for effects
00056         // due to finite precision
00057         //
00058         if ( sum<=0 ) {
00059 //        if ( sum<-FLT_MIN )  throw DetLogicError("RandomMultiGauss: input matrix is not positive definite");
00060           sum = FLT_MIN;
00061         }
00062         theTriangle[i1][i1] = sqrt(sum);
00063       }
00064       else {
00065         theTriangle[i1][i2] = 0.;
00066         theTriangle[i2][i1] = sum / theTriangle[i1][i1];
00067       }
00068     }
00069   }
00070 }


Member Data Documentation

AlgebraicVector RandomMultiGauss::theMeans [private]

Definition at line 35 of file RandomMultiGauss.h.

Referenced by fire(), and RandomMultiGauss().

int RandomMultiGauss::theSize [private]

Definition at line 34 of file RandomMultiGauss.h.

Referenced by fire(), initialise(), and RandomMultiGauss().

AlgebraicMatrix RandomMultiGauss::theTriangle [private]

Definition at line 36 of file RandomMultiGauss.h.

Referenced by fire(), and initialise().


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