a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
CorrelatedGaussianObservables Class Reference

A class for correlated Gaussian observables. More...

#include <CorrelatedGaussianObservables.h>

Detailed Description

A class for correlated Gaussian observables.

Author
HEPfit Collaboration

This class builds the correlated Gaussian observables that are specified in the SomeModel.conf file or specified by the user.

Definition at line 32 of file CorrelatedGaussianObservables.h.

Public Member Functions

void AddObs (Observable &Obs_i)
 A method to add observables to the list of correlated Gaussian observables. More...
 
void ComputeCov (gslpp::matrix< double > Corr)
 Computes the covariance matrix for the correlated Gaussian observables set. More...
 
virtual double computeWeight ()
 A method to compute the weight associated with the observable. More...
 
 CorrelatedGaussianObservables ()
 The default Constructor. More...
 
 CorrelatedGaussianObservables (const CorrelatedGaussianObservables &orig)
 The copy constructor. More...
 
 CorrelatedGaussianObservables (std::string name_i)
 Constructor. More...
 
gslpp::matrix< double > getCov () const
 A get method to access the covariance matrix of the correlated Gaussian observables. More...
 
std::string getName () const
 A get method to access the name of the correlated Gaussian observables set. More...
 
std::vector< ObservablegetObs () const
 A get method to access the vector of observables that are defined in one correlated Gaussian observables set. More...
 
Observable getObs (int i) const
 A get method to access an element of the vector of observables that are defined in one correlated Gaussian observables set. More...
 
bool isEOF ()
 A method to check if the end of file has been reached. More...
 
bool isPrediction ()
 A method to check if the Correlated Observables are set for prediction. More...
 
int ParseCGO (boost::ptr_vector< Observable > &Observables, std::ifstream &ifile, boost::tokenizer< boost::char_separator< char > >::iterator &beg, std::string &infilename, ThObsFactory &myObsFactory, StandardModel *myModel, int lineNo, int rank)
 The parser for CorrelatedGaussianObservables. More...
 
void setCovarianceFromConfig (bool setInvCov)
 A method to specify whether the inverse covariance is being set from the config file. More...
 
void setIsPrediction (bool IsPrediction_i)
 A method to set a set of CGO to be predicted. More...
 
void setName (std::string name_i)
 A method to set a set of CGO to be predicted. More...
 
virtual ~CorrelatedGaussianObservables ()
 The default destructor. More...
 

Private Attributes

bool covarianceFromConfig
 
std::string filepath
 The path to the config file being parsed. More...
 
gslpp::matrix< double > * InvCov
 The inverse covariance matrix. More...
 
bool IsEOF
 A boolean which is true if the end of file is reached. More...
 
bool IsPrediction
 Flag to define a set of Correlated Observables to be predicted. More...
 
std::string name
 The name of the correlated Gaussian Observables set. More...
 
std::vector< ObservableObs
 A vector of observables whose correlation will be calculated. More...
 

Constructor & Destructor Documentation

◆ CorrelatedGaussianObservables() [1/3]

CorrelatedGaussianObservables::CorrelatedGaussianObservables ( std::string  name_i)

Constructor.

Parameters
[in]name_ia given name for the set of correlated Gaussian observables

Definition at line 13 of file CorrelatedGaussianObservables.cpp.

14 {
15  name = name_i;
16  IsPrediction = false;
17  IsEOF = false;
18  covarianceFromConfig = false;
19  InvCov = NULL;
20 }

◆ CorrelatedGaussianObservables() [2/3]

CorrelatedGaussianObservables::CorrelatedGaussianObservables ( )

The default Constructor.

Definition at line 22 of file CorrelatedGaussianObservables.cpp.

23 {
24  name = "";
25  IsPrediction = false;
26  IsEOF = false;
27  covarianceFromConfig = false;
28  InvCov = NULL;
29 }

◆ CorrelatedGaussianObservables() [3/3]

CorrelatedGaussianObservables::CorrelatedGaussianObservables ( const CorrelatedGaussianObservables orig)

The copy constructor.

Definition at line 31 of file CorrelatedGaussianObservables.cpp.

32 {
33  Obs = orig.Obs;
34  name = orig.name;
35  if (orig.InvCov) InvCov = new gslpp::matrix<double>(*orig.InvCov);
36  else InvCov = NULL;
38  IsEOF = orig.IsEOF;
39  covarianceFromConfig = false;
40 }

◆ ~CorrelatedGaussianObservables()

CorrelatedGaussianObservables::~CorrelatedGaussianObservables ( )
virtual

The default destructor.

Definition at line 42 of file CorrelatedGaussianObservables.cpp.

43 {
44 // Cov = new gslpp::matrix<double>(100, 100, 0.); /** Put in to prevent seg fault during error handling in InputParser **/
45  if (InvCov) delete(InvCov);
46 }

Member Function Documentation

◆ AddObs()

void CorrelatedGaussianObservables::AddObs ( Observable Obs_i)

A method to add observables to the list of correlated Gaussian observables.

Parameters
Obs_ireference to an object of type Observable

Definition at line 48 of file CorrelatedGaussianObservables.cpp.

49 {
50  Obs.push_back(Obs_i);
51 }

◆ ComputeCov()

void CorrelatedGaussianObservables::ComputeCov ( gslpp::matrix< double >  Corr)

Computes the covariance matrix for the correlated Gaussian observables set.

Parameters
Corrthe correlation matrix for the correlated Gassian observables set

Definition at line 53 of file CorrelatedGaussianObservables.cpp.

54 {
55  unsigned int size = Obs.size();
56  if (Corr.size_i() != size || Corr.size_j() != size)
57  throw std::runtime_error("The size of the correlated observables in " + name + " does not match the size of the correlation matrix!");
58  InvCov = new gslpp::matrix<double>(size, size, 0.);
60  for (unsigned int i = 0; i < size; i++)
61  for (unsigned int j = 0; j < size; j++)
62  (*InvCov)(i, j) = Corr(i, j);
63  } else {
64  for (unsigned int i = 0; i < size; i++) {
65  for (unsigned int j = 0; j < size; j++) {
66  if (Corr(i, j) != Corr(j, i)) throw std::runtime_error("Invalid correlation matrix for " + name + ". The matrix is not symmetric: for elements [" + boost::lexical_cast<std::string>(i) + ", " + boost::lexical_cast<std::string>(j) + "]");
67  (*InvCov)(i, j) = Obs.at(i).getErrg() * Corr(i, j) * Obs.at(j).getErrg();
68  }
69  }
70  *InvCov = InvCov->inverse();
71  }
72 }

◆ computeWeight()

double CorrelatedGaussianObservables::computeWeight ( )
virtual

A method to compute the weight associated with the observable.

Definition at line 74 of file CorrelatedGaussianObservables.cpp.

75 {
76  gslpp::vector<double> x(Obs.size());
77 
78  for (unsigned int i = 0; i < Obs.size(); i++)
79  x(i) = Obs.at(i).computeTheoryValue() - Obs.at(i).getAve();
80 
81  return (-0.5 * x * ((*InvCov) * x));
82 }

◆ getCov()

gslpp::matrix<double> CorrelatedGaussianObservables::getCov ( ) const
inline

A get method to access the covariance matrix of the correlated Gaussian observables.

Definition at line 105 of file CorrelatedGaussianObservables.h.

106  {
107  return *InvCov;
108  }

◆ getName()

std::string CorrelatedGaussianObservables::getName ( ) const
inline

A get method to access the name of the correlated Gaussian observables set.

Returns
the name

Definition at line 97 of file CorrelatedGaussianObservables.h.

98  {
99  return name;
100  }

◆ getObs() [1/2]

std::vector<Observable> CorrelatedGaussianObservables::getObs ( ) const
inline

A get method to access the vector of observables that are defined in one correlated Gaussian observables set.

Returns
a vector of type Observable()

Definition at line 78 of file CorrelatedGaussianObservables.h.

79  {
80  return Obs;
81  }

◆ getObs() [2/2]

Observable CorrelatedGaussianObservables::getObs ( int  i) const
inline

A get method to access an element of the vector of observables that are defined in one correlated Gaussian observables set.

Returns
an element of the vector of type Observable()

Definition at line 88 of file CorrelatedGaussianObservables.h.

89  {
90  return (Obs.at(i));
91  }

◆ isEOF()

bool CorrelatedGaussianObservables::isEOF ( )
inline

A method to check if the end of file has been reached.

Returns
a boolean which is true if the end of file has been reached

Definition at line 133 of file CorrelatedGaussianObservables.h.

134  {
135  return IsEOF;
136  }

◆ isPrediction()

bool CorrelatedGaussianObservables::isPrediction ( )
inline

A method to check if the Correlated Observables are set for prediction.

Returns
a boolean which is true if the set of CGO are to be predicted

Definition at line 151 of file CorrelatedGaussianObservables.h.

152  {
153  return IsPrediction;
154  }

◆ ParseCGO()

int CorrelatedGaussianObservables::ParseCGO ( boost::ptr_vector< Observable > &  Observables,
std::ifstream &  ifile,
boost::tokenizer< boost::char_separator< char > >::iterator &  beg,
std::string &  infilename,
ThObsFactory myObsFactory,
StandardModel myModel,
int  lineNo,
int  rank 
)

The parser for CorrelatedGaussianObservables.

Parameters
[in]Observablesthe pointer vector containing the Observables
[in]ifilethe stream containing the config file to be parsed
[in]begthe iterator that parses a line in the config file
[in]infilenamethe name of the config file being parsed
[in]myModela pointer to the model
[in]lineNothe current line number at which the file is being parsed
[in]rankthe rank of the process that is using the parser
Returns
the line number (integer) after the parsing is done

Definition at line 84 of file CorrelatedGaussianObservables.cpp.

91  {
92  if (infilename.find("\\/") == std::string::npos) filepath = infilename.substr(0, infilename.find_last_of("\\/") + 1);
93  boost::char_separator<char> sep(" \t");
94  name = *beg;
95  ++beg;
96  int size = atoi((*beg).c_str());
97 
98  int nlines = 0;
99  std::vector<bool> lines;
100  std::string line;
101  for (int i = 0; i < size; i++) {
102  IsEOF = getline(ifile, line).eof();
103  if (line.empty() || line.at(0) == '#') {
104  if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedGaussianObservables please! In file " + infilename + " at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n");
105  else sleep(2);
106  }
107  lineNo++;
108  boost::tokenizer<boost::char_separator<char> > tok(line, sep);
109  beg = tok.begin();
110  std::string type = *beg;
111  ++beg;
112  if (type.compare("Observable") != 0 && type.compare("BinnedObservable") != 0 && type.compare("FunctionObservable") != 0) {
113  if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + infilename + ", expecting an Observable or BinnedObservable or FunctionObservable type here...\n");
114  else sleep(2);
115  }
116  Observable * tmpObs = new Observable();
118  beg = tmpObs->ParseObservable(type, &tok, beg, filepath, infilename, rank);
119  tmpObs->setTho(myObsFactory.CreateThMethod(tmpObs->getThname(), *myModel));
120  if (!IsPrediction) {
121  if (tmpObs->isTMCMC()) {
122  AddObs(*tmpObs);
123  lines.push_back(true);
124  nlines++;
125  } else {
126  Observables.push_back(tmpObs);
127  lines.push_back(false);
128  }
129  } else {
130  if (tmpObs->isTMCMC()) {
131  if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + infilename + ", Observable/BinnedObservable cannot be set to MCMC in CorrelatedObservable. Use CorrelatedGaussianObservable instead.\n");
132  else sleep(2);
133  } else {
134  AddObs(*tmpObs);
135  nlines++;
136  }
137  if (tmpObs->getDistr().compare("weight") == 0 || tmpObs->getDistr().compare("file") == 0) {
138  if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + infilename + ", Observable/BinnedObservable cannot be set to weight or file in CorrelatedObservable. Use CorrelatedGaussianObservable instead.\n");
139  else sleep(2);
140  }
141  }
142  }
143 
144  if (nlines > 1) {
145  if (!IsPrediction) {
147  int ni = 0;
148  for (int i = 0; i < size; i++) {
149  IsEOF = getline(ifile, line).eof();
150  if (line.empty() || line.at(0) == '#') {
151  if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedGaussianObservables please! In file " + infilename + " at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n");
152  else sleep(2);
153  }
154  lineNo++;
155  if (lines.at(i)) {
156  boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
157  beg = mytok.begin();
158  int nj = 0;
159  for (int j = 0; j < size; j++) {
160  if ((*beg).compare(0, 1, "0") == 0
161  || (*beg).compare(0, 1, "1") == 0
162  || (*beg).compare(0, 1, "-") == 0 || (covarianceFromConfig == true)) {
163  if (std::distance(mytok.begin(), mytok.end()) < size) {
164  if (rank == 0) throw std::runtime_error(("ERROR: Correlation matrix is of wrong size in Correlated Gaussian Observables: " + name + +" at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n").c_str());
165  else sleep(2);
166  }
167  if (lines.at(j)) {
168  myCorr(ni, nj) = atof((*beg).c_str());
169  nj++;
170  }
171  beg++;
172  } else {
173  if (rank == 0) throw std::runtime_error("ERROR: invalid correlation matrix for " + name + ". Check element (" + boost::lexical_cast<std::string>(ni + 1) + "," + boost::lexical_cast<std::string>(nj + 1) + ") in line number " + boost::lexical_cast<std::string>(lineNo) + " in file " + infilename + ".\n");
174  else sleep(2);
175  }
176  }
177  ni++;
178  }
179  }
180  ComputeCov(myCorr);
181  } else {
182  InvCov = new gslpp::matrix<double>(size, size, 0.);
183  }
184  } else {
185  if (rank == 0) std::cout << "\nWARNING: Correlated (Gaussian) Observable " << name.c_str() << " defined with less than two observables" << " in file " << infilename << ". The set is being marked as normal Observables." << std::endl;
186  if (getObs().size() == 1) Observables.push_back(new Observable(getObs(0)));
187  for (int i = 0; i < size; i++) {
188  IsEOF = getline(ifile, line).eof();
189  lineNo++;
190  }
191  }
192  return lineNo;
193 }

◆ setCovarianceFromConfig()

void CorrelatedGaussianObservables::setCovarianceFromConfig ( bool  setInvCov)
inline

A method to specify whether the inverse covariance is being set from the config file.

Parameters
[in]setInvCova boolean which is true if the inverse covariance matrix is set from file

Definition at line 169 of file CorrelatedGaussianObservables.h.

170  {
171  covarianceFromConfig = setInvCov;
172  }

◆ setIsPrediction()

void CorrelatedGaussianObservables::setIsPrediction ( bool  IsPrediction_i)
inline

A method to set a set of CGO to be predicted.

Parameters
[in]IsPrediction_ia boolean which is true if the set of CGO is set for prediction

Definition at line 142 of file CorrelatedGaussianObservables.h.

143  {
144  IsPrediction = IsPrediction_i;
145  }

◆ setName()

void CorrelatedGaussianObservables::setName ( std::string  name_i)
inline

A method to set a set of CGO to be predicted.

Parameters
[in]IsPrediction_ia boolean which is true if the set of CGO is set for prediction

Definition at line 160 of file CorrelatedGaussianObservables.h.

161  {
162  name = name_i;
163  }

Member Data Documentation

◆ covarianceFromConfig

bool CorrelatedGaussianObservables::covarianceFromConfig
private

Definition at line 181 of file CorrelatedGaussianObservables.h.

◆ filepath

std::string CorrelatedGaussianObservables::filepath
private

The path to the config file being parsed.

Definition at line 178 of file CorrelatedGaussianObservables.h.

◆ InvCov

gslpp::matrix<double>* CorrelatedGaussianObservables::InvCov
private

The inverse covariance matrix.

Definition at line 176 of file CorrelatedGaussianObservables.h.

◆ IsEOF

bool CorrelatedGaussianObservables::IsEOF
private

A boolean which is true if the end of file is reached.

Definition at line 179 of file CorrelatedGaussianObservables.h.

◆ IsPrediction

bool CorrelatedGaussianObservables::IsPrediction
private

Flag to define a set of Correlated Observables to be predicted.

Definition at line 180 of file CorrelatedGaussianObservables.h.

◆ name

std::string CorrelatedGaussianObservables::name
private

The name of the correlated Gaussian Observables set.

Definition at line 177 of file CorrelatedGaussianObservables.h.

◆ Obs

std::vector<Observable> CorrelatedGaussianObservables::Obs
private

A vector of observables whose correlation will be calculated.

Definition at line 175 of file CorrelatedGaussianObservables.h.


The documentation for this class was generated from the following files:
CorrelatedGaussianObservables::IsPrediction
bool IsPrediction
Flag to define a set of Correlated Observables to be predicted.
Definition: CorrelatedGaussianObservables.h:180
Observable::getDistr
std::string getDistr() const
A get method to access the name of the distribution of the observable.
Definition: Observable.h:140
gslpp::matrix< double >
A class for constructing and defining operations on real matrices.
Definition: gslpp_matrix_double.h:48
Observable::setTho
void setTho(ThObservable *tho_i)
A set method to fix the pointer to object of type ThObservable.
Definition: Observable.h:413
CorrelatedGaussianObservables::name
std::string name
The name of the correlated Gaussian Observables set.
Definition: CorrelatedGaussianObservables.h:177
Observable::ParseObservable
boost::tokenizer< boost::char_separator< char > >::iterator & ParseObservable(std::string &type, boost::tokenizer< boost::char_separator< char > > *tok, boost::tokenizer< boost::char_separator< char > >::iterator &beg, std::string &filepath, std::string &infilename, int rank)
The parser for Observables.
Definition: Observable.cpp:202
gslpp::matrix< double >::size_j
size_t size_j() const
Definition: gslpp_matrix_double.cpp:137
CorrelatedGaussianObservables::filepath
std::string filepath
The path to the config file being parsed.
Definition: CorrelatedGaussianObservables.h:178
gslpp::matrix
A base class for defining operations on matrices, both real and complex.
Definition: gslpp_matrix_base.h:21
CorrelatedGaussianObservables::getObs
std::vector< Observable > getObs() const
A get method to access the vector of observables that are defined in one correlated Gaussian observab...
Definition: CorrelatedGaussianObservables.h:78
Observable::getThname
std::string getThname() const
A get method to access the thname of the observable as defined in ThFactory class.
Definition: Observable.h:368
CorrelatedGaussianObservables::AddObs
void AddObs(Observable &Obs_i)
A method to add observables to the list of correlated Gaussian observables.
Definition: CorrelatedGaussianObservables.cpp:48
myModel
My own Model.
Definition: myModel.h:17
Observable::isTMCMC
bool isTMCMC() const
A method to check if the observable is listed for MCMC.
Definition: Observable.h:341
gslpp::matrix< double >::inverse
matrix< double > inverse()
Definition: gslpp_matrix_double.cpp:178
CorrelatedGaussianObservables::covarianceFromConfig
bool covarianceFromConfig
Definition: CorrelatedGaussianObservables.h:181
CorrelatedGaussianObservables::IsEOF
bool IsEOF
A boolean which is true if the end of file is reached.
Definition: CorrelatedGaussianObservables.h:179
Observable
A class for observables.
Definition: Observable.h:28
CorrelatedGaussianObservables::InvCov
gslpp::matrix< double > * InvCov
The inverse covariance matrix.
Definition: CorrelatedGaussianObservables.h:176
gslpp::matrix< double >::size_i
size_t size_i() const
Definition: gslpp_matrix_double.cpp:132
gslpp::vector< double >
A class for constructing and defining operations on real vectors.
Definition: gslpp_vector_double.h:33
CorrelatedGaussianObservables::ComputeCov
void ComputeCov(gslpp::matrix< double > Corr)
Computes the covariance matrix for the correlated Gaussian observables set.
Definition: CorrelatedGaussianObservables.cpp:53
Observable::setHasInverseCovariance
void setHasInverseCovariance(bool hasInverseCovariance)
A set method to state that the Observable is a part of ObservablesWithInverseCovariance.
Definition: Observable.h:464
ThObsFactory::CreateThMethod
ThObservable * CreateThMethod(const std::string &name, StandardModel &model) const
This method checks for the existence of an observable of a specific name in the map thobs and returns...
Definition: ThObsFactory.cpp:4623
CorrelatedGaussianObservables::Obs
std::vector< Observable > Obs
A vector of observables whose correlation will be calculated.
Definition: CorrelatedGaussianObservables.h:175