CorrelatedGaussianParameters Class Reference

A class for correlated Gaussian parameters. More...

#include <CorrelatedGaussianParameters.h>

Collaboration diagram for CorrelatedGaussianParameters:
[legend]

Detailed Description

A class for correlated Gaussian parameters.

Author
HEPfit Collaboration

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

Definition at line 29 of file CorrelatedGaussianParameters.h.

Public Member Functions

void AddPar (ModelParameter &Par_i)
 A method to add parameters to the list of correlated Gaussian parameters. More...
 
 CorrelatedGaussianParameters (std::string name_i)
 Constructor. More...
 
 CorrelatedGaussianParameters ()
 The default Constructor. More...
 
 CorrelatedGaussianParameters (const CorrelatedGaussianParameters &orig)
 The copy constructor. More...
 
void DiagonalizePars (gslpp::matrix< double > Corr)
 Diagonalizes the correlated Gaussian parameters set. More...
 
gslpp::matrix< double > getCov () const
 A get method to access the covariance matrix of the correlated Gaussian parameters. More...
 
const std::vector< ModelParameter > & getDiagPars () const
 A get method to access the diagonalized parameters. More...
 
std::string getName () const
 A get method to access the name of the correlated Gaussian parameters set. More...
 
std::vector< double > getOrigParsValue (const std::vector< double > &DiagPars_i) const
 
ModelParameter getPar (int i) const
 A get method to access an element of the vector of parameters that are defined in one correlated Gaussian parameters set. More...
 
const std::vector< ModelParameter > & getPars () const
 A get method to access the vector of parameters that are defined in one correlated Gaussian parameters set. More...
 
bool isEOF ()
 A method to check if the end of file has been reached. More...
 
int ParseCGP (std::vector< ModelParameter > &ModPars, std::string &filename, std::ifstream &ifile, boost::tokenizer< boost::char_separator< char > >::iterator &beg, int lineNo, int rank)
 The parser for CorrelatedGaussianParameters. More...
 
virtual ~CorrelatedGaussianParameters ()
 The default destructor. More...
 

Private Attributes

gslpp::matrix< double > * Cov
 The covariance matrix. More...
 
std::vector< ModelParameterDiagPars
 The eigenvector of the covariance matrix. More...
 
gslpp::vector< double > * e
 The diagonalized parameters. More...
 
bool IsEOF
 
std::string name
 The name of the correlated Gaussian Parameters set. More...
 
std::vector< ModelParameterPars
 A vector of parameters whose correlation will be calculated. More...
 
gslpp::matrix< double > * v
 The rotation matrix form the diagonalized parameters to the original parameters. More...
 

Constructor & Destructor Documentation

CorrelatedGaussianParameters::CorrelatedGaussianParameters ( std::string  name_i)

Constructor.

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

Definition at line 16 of file CorrelatedGaussianParameters.cpp.

17 {
18  name = name_i;
19  Cov = NULL;
20  v = NULL;
21  e = NULL;
22 }
gslpp::vector< double > * e
The diagonalized parameters.
gslpp::matrix< double > * Cov
The covariance matrix.
gslpp::matrix< double > * v
The rotation matrix form the diagonalized parameters to the original parameters.
std::string name
The name of the correlated Gaussian Parameters set.
CorrelatedGaussianParameters::CorrelatedGaussianParameters ( )

The default Constructor.

Definition at line 24 of file CorrelatedGaussianParameters.cpp.

25 {
26  Cov = NULL;
27  v = NULL;
28  e = NULL;
29 }
gslpp::vector< double > * e
The diagonalized parameters.
gslpp::matrix< double > * Cov
The covariance matrix.
gslpp::matrix< double > * v
The rotation matrix form the diagonalized parameters to the original parameters.
CorrelatedGaussianParameters::CorrelatedGaussianParameters ( const CorrelatedGaussianParameters orig)

The copy constructor.

Definition at line 31 of file CorrelatedGaussianParameters.cpp.

32 {
33  Pars = orig.Pars;
34  name = orig.name;
35  Cov = new gslpp::matrix<double>(*orig.Cov);
36  v = new gslpp::matrix<double>(*orig.v);
37  e = new gslpp::vector<double>(*orig.e);
38  DiagPars = orig.DiagPars;
39 }
gslpp::vector< double > * e
The diagonalized parameters.
A class for constructing and defining operations on real matrices.
std::vector< ModelParameter > DiagPars
The eigenvector of the covariance matrix.
gslpp::matrix< double > * Cov
The covariance matrix.
std::vector< ModelParameter > Pars
A vector of parameters whose correlation will be calculated.
gslpp::matrix< double > * v
The rotation matrix form the diagonalized parameters to the original parameters.
A class for constructing and defining operations on real vectors.
std::string name
The name of the correlated Gaussian Parameters set.
CorrelatedGaussianParameters::~CorrelatedGaussianParameters ( )
virtual

The default destructor.

Definition at line 41 of file CorrelatedGaussianParameters.cpp.

42 {
43  //Cov = new gslpp::matrix<double>(10, 10, 0.); /** Put in to prevent seg fault during error handling in InputParser **/
44  if(Cov != NULL)
45  delete(Cov);
46  if(v != NULL)
47  delete(v);
48  if(e != NULL)
49  delete(e);
50 }
gslpp::vector< double > * e
The diagonalized parameters.
gslpp::matrix< double > * Cov
The covariance matrix.
gslpp::matrix< double > * v
The rotation matrix form the diagonalized parameters to the original parameters.

Member Function Documentation

void CorrelatedGaussianParameters::AddPar ( ModelParameter Par_i)

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

Parameters
Par_ireference to an object of type ModelParameter

Definition at line 52 of file CorrelatedGaussianParameters.cpp.

53 {
54  Pars.push_back(Par_i);
55 }
std::vector< ModelParameter > Pars
A vector of parameters whose correlation will be calculated.
void CorrelatedGaussianParameters::DiagonalizePars ( gslpp::matrix< double >  Corr)

Diagonalizes the correlated Gaussian parameters set.

Parameters
Corrthe correlation matrix for the correlated Gaussian parameters set

Definition at line 57 of file CorrelatedGaussianParameters.cpp.

58 {
59  unsigned int size = Pars.size();
60  if (Corr.size_i() != size || Corr.size_j() != size)
61  throw std::runtime_error("The size of the correlated parameters in " + name + " does not match the size of the correlation matrix!");
62  Cov = new gslpp::matrix<double>(size, size, 0.);
63  for (unsigned int i = 0; i < size; i++)
64  for (unsigned int j = 0; j < size; j++)
65  (*Cov)(i, j) = Pars.at(i).geterrg() * Corr(i, j) * Pars.at(j).geterrg();
66 
67  *Cov = Cov->inverse();
68 
69  gslpp::matrix<gslpp::complex>vv(size, size, 0.);
71 
72  Cov->eigensystem(vv, ee);
73 
74  v = new gslpp::matrix<double>(size, size, 0.);
75  e = new gslpp::vector<double>(size, 0.);
76  *v = vv.real();
77  *e = ee.real();
78 
79  gslpp::vector<double> ave_in(size, 0.);
80 
81  int ind = 0;
82  for(std::vector<ModelParameter>::iterator it = Pars.begin(); it != Pars.end(); it++)
83  {
84  ave_in(ind) = it->getave();
85  ind++;
86  }
87 
88  gslpp::vector<double> ave = v->transpose() * ave_in;
89 
90  for (unsigned int i = 0; i < size; i++)
91  {
92  std::stringstream ss;
93  ss << (i+1);
94  std::string namei = name + ss.str();
95  ModelParameter current(namei,ave(i),1./sqrt((*e)(i)),0.);
96  current.setCgp_name(name);
97  DiagPars.push_back(current);
98  }
99 }
gslpp::vector< double > * e
The diagonalized parameters.
A class for constructing and defining operations on real matrices.
std::vector< ModelParameter > DiagPars
The eigenvector of the covariance matrix.
gslpp::matrix< double > * Cov
The covariance matrix.
A class for model parameters.
std::vector< ModelParameter > Pars
A vector of parameters whose correlation will be calculated.
void eigensystem(matrix< complex > &U, vector< complex > &S)
gslpp::matrix< double > * v
The rotation matrix form the diagonalized parameters to the original parameters.
A class for constructing and defining operations on real vectors.
std::string name
The name of the correlated Gaussian Parameters set.
complex sqrt(const complex &z)
gslpp::matrix<double> CorrelatedGaussianParameters::getCov ( ) const
inline

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

Definition at line 97 of file CorrelatedGaussianParameters.h.

98  {
99  return *Cov;
100  }
gslpp::matrix< double > * Cov
The covariance matrix.
const std::vector<ModelParameter>& CorrelatedGaussianParameters::getDiagPars ( ) const
inline

A get method to access the diagonalized parameters.

Returns
a vector of type ModelParameters

Definition at line 106 of file CorrelatedGaussianParameters.h.

107  {
108  return DiagPars;
109  }
std::vector< ModelParameter > DiagPars
The eigenvector of the covariance matrix.
std::string CorrelatedGaussianParameters::getName ( ) const
inline

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

Returns
the name

Definition at line 89 of file CorrelatedGaussianParameters.h.

90  {
91  return name;
92  }
std::string name
The name of the correlated Gaussian Parameters set.
std::vector< double > CorrelatedGaussianParameters::getOrigParsValue ( const std::vector< double > &  DiagPars_i) const

Definition at line 101 of file CorrelatedGaussianParameters.cpp.

102 {
103  if (DiagPars_i.size() != DiagPars.size()) {
104  std::stringstream out;
105  out << DiagPars_i.size();
106  throw std::runtime_error("CorrelatedGaussianParameters::getOrigParsValue(DiagPars_i): DiagPars_i.size() = " + out.str() + " does not match the size of DiagPars");
107  }
108  gslpp::vector<double> pars_in(DiagPars_i.size(), 0.);
109 
110  int ind = 0;
111  for (std::vector<double>::const_iterator it = DiagPars_i.begin(); it != DiagPars_i.end(); it++) {
112  pars_in(ind) = *it;
113  ind++;
114  }
115 
116  gslpp::vector<double> val = (*v) * pars_in;
117 
118  std::vector<double> res;
119 
120  for (unsigned int i = 0; i < DiagPars_i.size(); i++) {
121  res.push_back(val(i));
122  }
123  return (res);
124 }
std::vector< ModelParameter > DiagPars
The eigenvector of the covariance matrix.
A class for constructing and defining operations on real vectors.
ModelParameter CorrelatedGaussianParameters::getPar ( int  i) const
inline

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

Returns
an element of the vector of type ModelParameter()

Definition at line 80 of file CorrelatedGaussianParameters.h.

81  {
82  return (Pars.at(i));
83  }
std::vector< ModelParameter > Pars
A vector of parameters whose correlation will be calculated.
const std::vector<ModelParameter>& CorrelatedGaussianParameters::getPars ( ) const
inline

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

Returns
a vector of type ModelParameter()

Definition at line 70 of file CorrelatedGaussianParameters.h.

71  {
72  return Pars;
73  }
std::vector< ModelParameter > Pars
A vector of parameters whose correlation will be calculated.
bool CorrelatedGaussianParameters::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 135 of file CorrelatedGaussianParameters.h.

136  {
137  return IsEOF;
138  }
int CorrelatedGaussianParameters::ParseCGP ( std::vector< ModelParameter > &  ModPars,
std::string &  filename,
std::ifstream &  ifile,
boost::tokenizer< boost::char_separator< char > >::iterator &  beg,
int  lineNo,
int  rank 
)

The parser for CorrelatedGaussianParameters.

Parameters
[in]ModParsthe vector containing the model parameters
[in]filenamethe name of the config file being parsed
[in]ifilethe stream containing the config file to be parsed
[in]begthe iterator that parses a line in the config file
[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 126 of file CorrelatedGaussianParameters.cpp.

132 {
133  name = *beg;
134  ++beg;
135  int size = atoi((*beg).c_str());
136  int nlines = 0;
137  std::string line;
138  boost::char_separator<char>sep(" \t");
139  for (int i = 0; i < size; i++) {
140  IsEOF = getline(ifile, line).eof();
141  if (line.empty() || line.at(0) == '#') {
142  if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedGaussianParameters please! In line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + filename);
143  else sleep(2);
144  }
145  lineNo++;
146  boost::tokenizer<boost::char_separator<char> > tok(line, sep);
147  beg = tok.begin();
148  std::string type = *beg;
149  ++beg;
150  if (type.compare("ModelParameter") != 0){
151  if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + filename + ", expecting a ModelParameter type here...\n");
152  else sleep(2);
153  }
154  ModelParameter tmpMP;
155  beg = tmpMP.ParseModelParameter(beg);
156  if (beg != tok.end())
157  if (rank == 0) std::cout << "WARNING: unread information in parameter " << tmpMP.getname() << std::endl;
158  tmpMP.setCgp_name(name);
159  AddPar(tmpMP);
160  nlines++;
161  }
162  if (nlines > 1) {
164  int ni = 0;
165  for (int i = 0; i < size; i++) {
166  IsEOF = getline(ifile, line).eof();
167  if (line.empty() || line.at(0) == '#') {
168  if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedGaussianParameters please! In line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + filename);
169  else sleep(2);
170  }
171  lineNo++;
172  boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
173  beg = mytok.begin();
174  int nj = 0;
175  for (int j = 0; j < size; j++) {
176  if ((*beg).compare(0, 1, "0") == 0
177  || (*beg).compare(0, 1, "1") == 0
178  || (*beg).compare(0, 1, "-") == 0) {
179  if (std::distance(mytok.begin(), mytok.end()) < size) {
180  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 " + filename + ".\n");
181  else sleep(2);
182  }
183  myCorr(ni, nj) = atof((*beg).c_str());
184  nj++;
185  beg++;
186  } else {
187  if (rank == 0) std::cout << "ERROR: invalid correlation matrix for "
188  << name << ". Check element (" << ni + 1 << "," << nj + 1 << ") in line number " + boost::lexical_cast<std::string>(lineNo) << std::endl;
189  exit(EXIT_FAILURE);
190  }
191  }
192  ni++;
193  }
194  DiagonalizePars(myCorr);
195  ModPars.insert(ModPars.end(), getDiagPars().begin(), getDiagPars().end());
196 
197  } else {
198  if (rank == 0) std::cout << "\nWARNING: Correlated Gaussian Parameters " << name.c_str() << " defined with less than two correlated parameters. The set is being marked as normal Parameters." << std::endl;
199  if (getPars().size() == 1) ModPars.push_back(ModelParameter(getPar(0)));
200  for (int i = 0; i < size; i++) {
201  IsEOF = getline(ifile, line).eof();
202  lineNo++;
203  }
204  }
205  return lineNo;
206 }
void setCgp_name(std::string cgp_name)
A set method to set the name of the set of correlated parameter.
A class for constructing and defining operations on real matrices.
A base class for defining operations on matrices, both real and complex.
const std::vector< ModelParameter > & getDiagPars() const
A get method to access the diagonalized parameters.
const std::vector< ModelParameter > & getPars() const
A get method to access the vector of parameters that are defined in one correlated Gaussian parameter...
A class for model parameters.
void DiagonalizePars(gslpp::matrix< double > Corr)
Diagonalizes the correlated Gaussian parameters set.
std::string getname() const
A get method to get the name of each parameter.
std::string name
The name of the correlated Gaussian Parameters set.
boost::tokenizer< boost::char_separator< char > >::iterator & ParseModelParameter(boost::tokenizer< boost::char_separator< char > >::iterator &beg)
Parser for model parameters.
void AddPar(ModelParameter &Par_i)
A method to add parameters to the list of correlated Gaussian parameters.
ModelParameter getPar(int i) const
A get method to access an element of the vector of parameters that are defined in one correlated Gaus...

Member Data Documentation

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

The covariance matrix.

Definition at line 142 of file CorrelatedGaussianParameters.h.

std::vector<ModelParameter> CorrelatedGaussianParameters::DiagPars
private

The eigenvector of the covariance matrix.

Definition at line 146 of file CorrelatedGaussianParameters.h.

gslpp::vector<double>* CorrelatedGaussianParameters::e
private

The diagonalized parameters.

Definition at line 145 of file CorrelatedGaussianParameters.h.

bool CorrelatedGaussianParameters::IsEOF
private

Definition at line 147 of file CorrelatedGaussianParameters.h.

std::string CorrelatedGaussianParameters::name
private

The name of the correlated Gaussian Parameters set.

Definition at line 143 of file CorrelatedGaussianParameters.h.

std::vector<ModelParameter> CorrelatedGaussianParameters::Pars
private

A vector of parameters whose correlation will be calculated.

Definition at line 141 of file CorrelatedGaussianParameters.h.

gslpp::matrix<double>* CorrelatedGaussianParameters::v
private

The rotation matrix form the diagonalized parameters to the original parameters.

Definition at line 144 of file CorrelatedGaussianParameters.h.


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