CorrelatedGaussianObservables Class Reference

A class for correlated Gaussian observables. More...

#include <CorrelatedGaussianObservables.h>

Collaboration diagram for CorrelatedGaussianObservables:
[legend]

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 31 of file Observables/src/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 (std::string name_i)
 Constructor. More...
 
 CorrelatedGaussianObservables ()
 The default Constructor. More...
 
 CorrelatedGaussianObservables (const CorrelatedGaussianObservables &orig)
 The copy 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 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

gslpp::matrix< double > * Cov
 The covariance matrix. More...
 
std::string filepath
 The path to the config file being parsed. 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::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 Observables/src/CorrelatedGaussianObservables.cpp.

14 {
15  name = name_i;
16  IsPrediction = false;
17 }
bool IsPrediction
Flag to define a set of Correlated Observables to be predicted.
std::string name
The name of the correlated Gaussian Observables set.
CorrelatedGaussianObservables::CorrelatedGaussianObservables ( )

The default Constructor.

Definition at line 19 of file Observables/src/CorrelatedGaussianObservables.cpp.

20 {
21  name = "";
22  IsPrediction = false;
23 }
bool IsPrediction
Flag to define a set of Correlated Observables to be predicted.
std::string name
The name of the correlated Gaussian Observables set.
CorrelatedGaussianObservables::CorrelatedGaussianObservables ( const CorrelatedGaussianObservables orig)

The copy constructor.

Definition at line 25 of file Observables/src/CorrelatedGaussianObservables.cpp.

26 {
27  Obs = orig.Obs;
28  name = orig.name;
29  Cov = new gslpp::matrix<double>(*orig.Cov);
31 }
A class for constructing and defining operations on real matrices.
gslpp::matrix< double > * Cov
The covariance matrix.
bool IsPrediction
Flag to define a set of Correlated Observables to be predicted.
std::vector< Observable > Obs
A vector of observables whose correlation will be calculated.
std::string name
The name of the correlated Gaussian Observables set.
CorrelatedGaussianObservables::~CorrelatedGaussianObservables ( )
virtual

The default destructor.

Put in to prevent seg fault during error handling in InputParser

Definition at line 33 of file Observables/src/CorrelatedGaussianObservables.cpp.

34 {
35  Cov = new gslpp::matrix<double>(10, 10, 0.);
36  delete(Cov);
37 }
A class for constructing and defining operations on real matrices.
gslpp::matrix< double > * Cov
The covariance matrix.

Member Function Documentation

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 39 of file Observables/src/CorrelatedGaussianObservables.cpp.

40 {
41  Obs.push_back(Obs_i);
42 }
std::vector< Observable > Obs
A vector of observables whose correlation will be calculated.
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 44 of file Observables/src/CorrelatedGaussianObservables.cpp.

45 {
46  unsigned int size = Obs.size();
47  if (Corr.size_i() != size || Corr.size_j() != size)
48  throw std::runtime_error("The size of the correlated observables in " + name + " does not match the size of the correlation matrix!");
49  Cov = new gslpp::matrix<double>(size, size, 0.);
50  for (unsigned int i = 0; i < size; i++)
51  for (unsigned int j = 0; j < size; j++)
52  (*Cov)(i, j) = Obs.at(i).getErrg() * Corr(i, j) * Obs.at(j).getErrg();
53  *Cov = Cov->inverse();
54 }
A class for constructing and defining operations on real matrices.
gslpp::matrix< double > * Cov
The covariance matrix.
std::vector< Observable > Obs
A vector of observables whose correlation will be calculated.
std::string name
The name of the correlated Gaussian Observables set.
double CorrelatedGaussianObservables::computeWeight ( )
virtual

A method to compute the weight associated with the observable.

Definition at line 56 of file Observables/src/CorrelatedGaussianObservables.cpp.

57 {
58  gslpp::vector<double> x(Obs.size());
59 
60  for (unsigned int i = 0; i < Obs.size(); i++)
61  x(i) = Obs.at(i).computeTheoryValue() - Obs.at(i).getAve();
62 
63  return (-0.5 * x * ((*Cov) * x));
64 }
gslpp::matrix< double > * Cov
The covariance matrix.
std::vector< Observable > Obs
A vector of observables whose correlation will be calculated.
A class for constructing and defining operations on real vectors.
gslpp::matrix<double> CorrelatedGaussianObservables::getCov ( ) const
inline

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

Definition at line 104 of file Observables/src/CorrelatedGaussianObservables.h.

105  {
106  return *Cov;
107  }
gslpp::matrix< double > * Cov
The covariance matrix.
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 96 of file Observables/src/CorrelatedGaussianObservables.h.

97  {
98  return name;
99  }
std::string name
The name of the correlated Gaussian Observables set.
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 77 of file Observables/src/CorrelatedGaussianObservables.h.

78  {
79  return Obs;
80  }
std::vector< Observable > Obs
A vector of observables whose correlation will be calculated.
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 87 of file Observables/src/CorrelatedGaussianObservables.h.

88  {
89  return (Obs.at(i));
90  }
std::vector< Observable > Obs
A vector of observables whose correlation will be calculated.
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 132 of file Observables/src/CorrelatedGaussianObservables.h.

133  {
134  return IsEOF;
135  }
bool IsEOF
A boolean which is true if the end of file is reached.
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 150 of file Observables/src/CorrelatedGaussianObservables.h.

151  {
152  return IsPrediction;
153  }
bool IsPrediction
Flag to define a set of Correlated Observables to be predicted.
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 66 of file Observables/src/CorrelatedGaussianObservables.cpp.

73  {
74  if (infilename.find("\\/") == std::string::npos) filepath = infilename.substr(0, infilename.find_last_of("\\/") + 1);
75  boost::char_separator<char> sep(" \t");
76  name = *beg;
77  ++beg;
78  int size = atoi((*beg).c_str());
79 
80  int nlines = 0;
81  std::vector<bool> lines;
82  std::string line;
83  for (int i = 0; i < size; i++) {
84  IsEOF = getline(ifile, line).eof();
85  if (line.empty() || line.at(0) == '#') {
86  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");
87  else sleep(2);
88  }
89  lineNo++;
90  boost::tokenizer<boost::char_separator<char> > tok(line, sep);
91  beg = tok.begin();
92  std::string type = *beg;
93  ++beg;
94  if (type.compare("Observable") != 0 && type.compare("BinnedObservable") != 0 && type.compare("FunctionObservable") != 0) {
95  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");
96  else sleep(2);
97  }
98  Observable * tmpObs = new Observable();
99  beg = tmpObs->ParseObservable(type, &tok, beg, filepath, infilename, rank);
100  tmpObs->setTho(myObsFactory.CreateThMethod(tmpObs->getThname(), *myModel));
101  if (!IsPrediction) {
102  if (tmpObs->isTMCMC()) {
103  AddObs(*tmpObs);
104  lines.push_back(true);
105  nlines++;
106  } else {
107  Observables.push_back(tmpObs);
108  lines.push_back(false);
109  }
110  } else {
111  if (tmpObs->isTMCMC()) {
112  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");
113  else sleep(2);
114  } else {
115  AddObs(*tmpObs);
116  nlines++;
117  }
118  if (tmpObs->getDistr().compare("weight") == 0 || tmpObs->getDistr().compare("file") == 0) {
119  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");
120  else sleep(2);
121  }
122  }
123  }
124 
125  if (nlines > 1) {
126  if (!IsPrediction) {
128  int ni = 0;
129  for (int i = 0; i < size; i++) {
130  IsEOF = getline(ifile, line).eof();
131  if (line.empty() || line.at(0) == '#') {
132  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");
133  else sleep(2);
134  }
135  lineNo++;
136  if (lines.at(i)) {
137  boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
138  beg = mytok.begin();
139  int nj = 0;
140  for (int j = 0; j < size; j++) {
141  if ((*beg).compare(0, 1, "0") == 0
142  || (*beg).compare(0, 1, "1") == 0
143  || (*beg).compare(0, 1, "-") == 0) {
144  if (std::distance(mytok.begin(), mytok.end()) < size) {
145  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());
146  else sleep(2);
147  }
148  if (lines.at(j)) {
149  myCorr(ni, nj) = atof((*beg).c_str());
150  nj++;
151  }
152  beg++;
153  } else {
154  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");
155  else sleep(2);
156  }
157  }
158  ni++;
159  }
160  }
161  ComputeCov(myCorr);
162  } else {
163  Cov = new gslpp::matrix<double>(size, size, 0.);
164  }
165  } else {
166  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;
167  if (getObs().size() == 1) Observables.push_back(new Observable(getObs(0)));
168  for (int i = 0; i < size; i++) {
169  IsEOF = getline(ifile, line).eof();
170  lineNo++;
171  }
172  }
173  return lineNo;
174 }
std::vector< Observable > getObs() const
A get method to access the vector of observables that are defined in one correlated Gaussian observab...
std::string filepath
The path to the config file being parsed.
bool IsEOF
A boolean which is true if the end of file is reached.
A class for constructing and defining operations on real matrices.
A base class for defining operations on matrices, both real and complex.
void setTho(ThObservable *tho_i)
A set method to fix the pointer to object of type ThObservable.
Definition: Observable.h:385
std::string getDistr() const
A get method to access the name of the distribution of the observable.
Definition: Observable.h:139
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:184
gslpp::matrix< double > * Cov
The covariance matrix.
bool isTMCMC() const
A method to check if the observable is listed for MCMC.
Definition: Observable.h:322
std::string getThname() const
A get method to access the thname of the observable as defined in ThFactory class.
Definition: Observable.h:340
ThObservable * CreateThMethod(const std::string &name, const StandardModel &model) const
This method checks for the existence of an observable of a specific name in the map thobs and returns...
bool IsPrediction
Flag to define a set of Correlated Observables to be predicted.
A class for observables.
Definition: Observable.h:28
std::string name
The name of the correlated Gaussian Observables set.
void AddObs(Observable &Obs_i)
A method to add observables to the list of correlated Gaussian observables.
void ComputeCov(gslpp::matrix< double > Corr)
Computes the covariance matrix for the correlated Gaussian observables set.
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 141 of file Observables/src/CorrelatedGaussianObservables.h.

142  {
143  IsPrediction = IsPrediction_i;
144  }
bool IsPrediction
Flag to define a set of Correlated Observables to be predicted.
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 159 of file Observables/src/CorrelatedGaussianObservables.h.

160  {
161  name = name_i;
162  }
std::string name
The name of the correlated Gaussian Observables set.

Member Data Documentation

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

The covariance matrix.

Definition at line 166 of file Observables/src/CorrelatedGaussianObservables.h.

std::string CorrelatedGaussianObservables::filepath
private

The path to the config file being parsed.

Definition at line 168 of file Observables/src/CorrelatedGaussianObservables.h.

bool CorrelatedGaussianObservables::IsEOF
private

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

Definition at line 169 of file Observables/src/CorrelatedGaussianObservables.h.

bool CorrelatedGaussianObservables::IsPrediction
private

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

Definition at line 170 of file Observables/src/CorrelatedGaussianObservables.h.

std::string CorrelatedGaussianObservables::name
private

The name of the correlated Gaussian Observables set.

Definition at line 167 of file Observables/src/CorrelatedGaussianObservables.h.

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

A vector of observables whose correlation will be calculated.

Definition at line 165 of file Observables/src/CorrelatedGaussianObservables.h.


The documentation for this class was generated from the following files: