CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
RandomMultiGauss Class Reference

#include <RandomMultiGauss.h>

Public Member Functions

AlgebraicVector fire ()
 
 RandomMultiGauss (const AlgebraicVector &aVector, const AlgebraicSymMatrix &aMatrix)
 
 RandomMultiGauss (const AlgebraicSymMatrix &aMatrix)
 
 ~RandomMultiGauss ()
 

Private Member Functions

void initialise (const AlgebraicSymMatrix &)
 

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 CLHEP::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.

9  :
10  theSize(aMatrix.num_row()),
11  theMeans(aVector),
13  //
14  // Check consistency
15  //
16  if ( theMeans.num_row() == theSize ) {
17  initialise(aMatrix);
18  }
19  else {
20 // throw DetLogicError("RandomMultiGauss: size of vector and matrix do not match");
22  }
23 }
AlgebraicMatrix theTriangle
void initialise(const AlgebraicSymMatrix &)
AlgebraicVector theMeans
CLHEP::HepVector AlgebraicVector
RandomMultiGauss::RandomMultiGauss ( const AlgebraicSymMatrix aMatrix)

constructor with covariance matrix only (all means = 0)

Definition at line 27 of file RandomMultiGauss.cc.

References initialise().

27  :
28  theSize(aMatrix.num_row()),
29  theMeans(theSize,0),
31  //
32  initialise(aMatrix);
33 }
AlgebraicMatrix theTriangle
void initialise(const AlgebraicSymMatrix &)
AlgebraicVector theMeans
RandomMultiGauss::~RandomMultiGauss ( )
inline

Definition at line 23 of file RandomMultiGauss.h.

References fire(), and initialise().

23 {}

Member Function Documentation

AlgebraicVector RandomMultiGauss::fire ( )

Generation of a vector of random numbers.

Definition at line 74 of file RandomMultiGauss.cc.

References mps_fire::i, theMeans, theSize, and theTriangle.

Referenced by ~RandomMultiGauss().

74  {
75  AlgebraicVector vRandom(theSize,0);
76  for ( int i=0; i<theSize; i++ ) {
77  if ( theTriangle[i][i]!=0 )
78  vRandom[i] = CLHEP::RandGauss::shoot();
79  }
80  return theTriangle*vRandom+theMeans;
81 }
AlgebraicMatrix theTriangle
AlgebraicVector theMeans
CLHEP::HepVector AlgebraicVector
void RandomMultiGauss::initialise ( const AlgebraicSymMatrix aMatrix)
private

generation of the cholesky decomposition

Definition at line 37 of file RandomMultiGauss.cc.

References mathSSE::sqrt(), theSize, and theTriangle.

Referenced by RandomMultiGauss(), and ~RandomMultiGauss().

37  {
38  //
39  // Cholesky decomposition with protection against empty rows/columns
40  //
41  for ( int i1=0; i1<theSize; i1++ ) {
42  if ( fabs(aMatrix[i1][i1])<FLT_MIN ) continue;
43 
44  for ( int i2=i1; i2<theSize; i2++ ) {
45  if ( fabs(aMatrix[i2][i2])<FLT_MIN ) continue;
46 
47  double sum = aMatrix[i2][i1];
48  for ( int i3=i1-1; i3>=0; i3-- ) {
49  if ( fabs(aMatrix[i3][i3])<FLT_MIN ) continue;
50  sum -= theTriangle[i1][i3]*theTriangle[i2][i3];
51  }
52 
53  if ( i1==i2 ) {
54  //
55  // check for positive definite input matrix, but allow for effects
56  // due to finite precision
57  //
58  if ( sum<=0 ) {
59 // if ( sum<-FLT_MIN ) throw DetLogicError("RandomMultiGauss: input matrix is not positive definite");
60  sum = FLT_MIN;
61  }
62  theTriangle[i1][i1] = sqrt(sum);
63  }
64  else {
65  theTriangle[i1][i2] = 0.;
66  theTriangle[i2][i1] = sum / theTriangle[i1][i1];
67  }
68  }
69  }
70 }
AlgebraicMatrix theTriangle
T sqrt(T t)
Definition: SSEVec.h:18

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().