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

A class for correlated Gaussian parameters. More...

#include <CorrelatedGaussianParameters.h>

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 23 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 ()
 The default Constructor. More...
 
 CorrelatedGaussianParameters (const CorrelatedGaussianParameters &orig)
 The copy constructor. More...
 
 CorrelatedGaussianParameters (std::string name_i)
 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() [1/3]

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  IsEOF = false;
23 }

◆ CorrelatedGaussianParameters() [2/3]

CorrelatedGaussianParameters::CorrelatedGaussianParameters ( )

The default Constructor.

Definition at line 25 of file CorrelatedGaussianParameters.cpp.

26 {
27  Cov = NULL;
28  v = NULL;
29  e = NULL;
30  IsEOF = false;
31 }

◆ CorrelatedGaussianParameters() [3/3]

CorrelatedGaussianParameters::CorrelatedGaussianParameters ( const CorrelatedGaussianParameters orig)

The copy constructor.

Definition at line 33 of file CorrelatedGaussianParameters.cpp.

34 {
35  Pars = orig.Pars;
36  name = orig.name;
37  Cov = new gslpp::matrix<double>(*orig.Cov);
38  v = new gslpp::matrix<double>(*orig.v);
39  e = new gslpp::vector<double>(*orig.e);
40  DiagPars = orig.DiagPars;
41  IsEOF = orig.IsEOF;
42 }

◆ ~CorrelatedGaussianParameters()

CorrelatedGaussianParameters::~CorrelatedGaussianParameters ( )
virtual

The default destructor.

Definition at line 44 of file CorrelatedGaussianParameters.cpp.

45 {
46  //Cov = new gslpp::matrix<double>(10, 10, 0.); /** Put in to prevent seg fault during error handling in InputParser **/
47  if(Cov != NULL)
48  delete(Cov);
49  if(v != NULL)
50  delete(v);
51  if(e != NULL)
52  delete(e);
53 }

Member Function Documentation

◆ AddPar()

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 55 of file CorrelatedGaussianParameters.cpp.

56 {
57  Pars.push_back(Par_i);
58 }

◆ DiagonalizePars()

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 60 of file CorrelatedGaussianParameters.cpp.

61 {
62  unsigned int size = Pars.size();
63  if (Corr.size_i() != size || Corr.size_j() != size)
64  throw std::runtime_error("The size of the correlated parameters in " + name + " does not match the size of the correlation matrix!");
65  Cov = new gslpp::matrix<double>(size, size, 0.);
66  for (unsigned int i = 0; i < size; i++)
67  for (unsigned int j = 0; j < size; j++)
68  (*Cov)(i, j) = Pars.at(i).geterrg() * Corr(i, j) * Pars.at(j).geterrg();
69 
70  *Cov = Cov->inverse();
71 
72  gslpp::matrix<gslpp::complex>vv(size, size, 0.);
74 
75  Cov->eigensystem(vv, ee);
76 
77  v = new gslpp::matrix<double>(size, size, 0.);
78  e = new gslpp::vector<double>(size, 0.);
79  *v = vv.real();
80  *e = ee.real();
81 
82  gslpp::vector<double> ave_in(size, 0.);
83 
84  int ind = 0;
85  for(std::vector<ModelParameter>::iterator it = Pars.begin(); it != Pars.end(); it++)
86  {
87  ave_in(ind) = it->getave();
88  ind++;
89  }
90 
91  gslpp::vector<double> ave = v->transpose() * ave_in;
92 
93  for (unsigned int i = 0; i < size; i++)
94  {
95  std::stringstream ss;
96  ss << (i+1);
97  std::string namei = name + ss.str();
98  ModelParameter current(namei,ave(i),1./sqrt((*e)(i)),0.);
99  current.setCgp_name(name);
100  DiagPars.push_back(current);
101  }
102 }

◆ getCov()

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

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

Definition at line 91 of file CorrelatedGaussianParameters.h.

92  {
93  return *Cov;
94  }

◆ getDiagPars()

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 100 of file CorrelatedGaussianParameters.h.

101  {
102  return DiagPars;
103  }

◆ getName()

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 83 of file CorrelatedGaussianParameters.h.

84  {
85  return name;
86  }

◆ getOrigParsValue()

std::vector< double > CorrelatedGaussianParameters::getOrigParsValue ( const std::vector< double > &  DiagPars_i) const

Definition at line 104 of file CorrelatedGaussianParameters.cpp.

105 {
106  if (DiagPars_i.size() != DiagPars.size()) {
107  std::stringstream out;
108  out << DiagPars_i.size();
109  throw std::runtime_error("CorrelatedGaussianParameters::getOrigParsValue(DiagPars_i): DiagPars_i.size() = " + out.str() + " does not match the size of DiagPars");
110  }
111  gslpp::vector<double> pars_in(DiagPars_i.size(), 0.);
112 
113  int ind = 0;
114  for (std::vector<double>::const_iterator it = DiagPars_i.begin(); it != DiagPars_i.end(); it++) {
115  pars_in(ind) = *it;
116  ind++;
117  }
118 
119  gslpp::vector<double> val = (*v) * pars_in;
120 
121  std::vector<double> res;
122 
123  for (unsigned int i = 0; i < DiagPars_i.size(); i++) {
124  res.push_back(val(i));
125  }
126  return (res);
127 }

◆ getPar()

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 74 of file CorrelatedGaussianParameters.h.

75  {
76  return (Pars.at(i));
77  }

◆ getPars()

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 64 of file CorrelatedGaussianParameters.h.

65  {
66  return Pars;
67  }

◆ isEOF()

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 129 of file CorrelatedGaussianParameters.h.

130  {
131  return IsEOF;
132  }

◆ ParseCGP()

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 129 of file CorrelatedGaussianParameters.cpp.

135 {
136  name = *beg;
137  ++beg;
138  int size = atoi((*beg).c_str());
139  int nlines = 0;
140  std::vector<bool> lines;
141  std::string line;
142  boost::char_separator<char>sep(" \t");
143  for (int i = 0; i < size; i++) {
144  IsEOF = getline(ifile, line).eof();
145  if (line.empty() || line.at(0) == '#') {
146  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);
147  else sleep(2);
148  }
149  lineNo++;
150  boost::tokenizer<boost::char_separator<char> > tok(line, sep);
151  beg = tok.begin();
152  std::string type = *beg;
153  ++beg;
154  if (type.compare("ModelParameter") != 0){
155  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");
156  else sleep(2);
157  }
158  ModelParameter tmpMP;
159  beg = tmpMP.ParseModelParameter(beg);
160  lines.push_back(!tmpMP.IsFixed());
161  if (beg != tok.end())
162  if (rank == 0) std::cout << "WARNING: unread information in parameter " << tmpMP.getname() << std::endl;
163  if (!tmpMP.IsFixed()) {
164  tmpMP.setCgp_name(name);
165  AddPar(tmpMP);
166  nlines++;
167  } else {
168  ModPars.push_back(tmpMP);
169  }
170  }
171  if (nlines > 1) {
173  int ni = 0;
174  for (int i = 0; i < size; i++) {
175  IsEOF = getline(ifile, line).eof();
176  if (line.empty() || line.at(0) == '#') {
177  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);
178  else sleep(2);
179  }
180  lineNo++;
181  if (lines.at(i)) {
182  boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
183  beg = mytok.begin();
184  int nj = 0;
185  for (int j = 0; j < size; j++) {
186  if ((*beg).compare(0, 1, "0") == 0
187  || (*beg).compare(0, 1, "1") == 0
188  || (*beg).compare(0, 1, "-") == 0) {
189  if (std::distance(mytok.begin(), mytok.end()) < size) {
190  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");
191  else sleep(2);
192  }
193  if (lines.at(j)) {
194  myCorr(ni, nj) = atof((*beg).c_str());
195  nj++;
196  }
197  beg++;
198  } else {
199  if (rank == 0) std::cout << "ERROR: invalid correlation matrix for "
200  << name << ". Check element (" << ni + 1 << "," << nj + 1 << ") in line number " + boost::lexical_cast<std::string>(lineNo) << std::endl;
201  exit(EXIT_FAILURE);
202  }
203  }
204  ni++;
205  }
206  }
207  DiagonalizePars(myCorr);
208  ModPars.insert(ModPars.end(), getDiagPars().begin(), getDiagPars().end());
209 
210  } else {
211  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;
212  if (getPars().size() == 1) ModPars.push_back(ModelParameter(getPar(0)));
213  for (int i = 0; i < size; i++) {
214  IsEOF = getline(ifile, line).eof();
215  lineNo++;
216  }
217  }
218  return lineNo;
219 }

Member Data Documentation

◆ Cov

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

The covariance matrix.

Definition at line 136 of file CorrelatedGaussianParameters.h.

◆ DiagPars

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

The eigenvector of the covariance matrix.

Definition at line 140 of file CorrelatedGaussianParameters.h.

◆ e

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

The diagonalized parameters.

Definition at line 139 of file CorrelatedGaussianParameters.h.

◆ IsEOF

bool CorrelatedGaussianParameters::IsEOF
private

Definition at line 141 of file CorrelatedGaussianParameters.h.

◆ name

std::string CorrelatedGaussianParameters::name
private

The name of the correlated Gaussian Parameters set.

Definition at line 137 of file CorrelatedGaussianParameters.h.

◆ Pars

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

A vector of parameters whose correlation will be calculated.

Definition at line 135 of file CorrelatedGaussianParameters.h.

◆ v

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

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

Definition at line 138 of file CorrelatedGaussianParameters.h.


The documentation for this class was generated from the following files:
gslpp::matrix< double >
A class for constructing and defining operations on real matrices.
Definition: gslpp_matrix_double.h:48
CorrelatedGaussianParameters::getPars
const std::vector< ModelParameter > & getPars() const
A get method to access the vector of parameters that are defined in one correlated Gaussian parameter...
Definition: CorrelatedGaussianParameters.h:64
gslpp::matrix< double >::size_j
size_t size_j() const
Definition: gslpp_matrix_double.cpp:137
gslpp::matrix< double >::transpose
matrix< double > transpose() const
Definition: gslpp_matrix_double.cpp:166
gslpp::matrix< gslpp::complex >
ModelParameter::ParseModelParameter
boost::tokenizer< boost::char_separator< char > >::iterator & ParseModelParameter(boost::tokenizer< boost::char_separator< char > >::iterator &beg)
Parser for model parameters.
Definition: ModelParameter.cpp:39
CorrelatedGaussianParameters::e
gslpp::vector< double > * e
The diagonalized parameters.
Definition: CorrelatedGaussianParameters.h:139
CorrelatedGaussianParameters::v
gslpp::matrix< double > * v
The rotation matrix form the diagonalized parameters to the original parameters.
Definition: CorrelatedGaussianParameters.h:138
ModelParameter::IsFixed
bool IsFixed() const
A method to check if the parameter is fixed.
Definition: ModelParameter.h:123
CorrelatedGaussianParameters::DiagonalizePars
void DiagonalizePars(gslpp::matrix< double > Corr)
Diagonalizes the correlated Gaussian parameters set.
Definition: CorrelatedGaussianParameters.cpp:60
CorrelatedGaussianParameters::DiagPars
std::vector< ModelParameter > DiagPars
The eigenvector of the covariance matrix.
Definition: CorrelatedGaussianParameters.h:140
ModelParameter::getname
std::string getname() const
A get method to get the name of each parameter.
Definition: ModelParameter.h:69
gslpp::matrix< double >::inverse
matrix< double > inverse()
Definition: gslpp_matrix_double.cpp:178
CorrelatedGaussianParameters::AddPar
void AddPar(ModelParameter &Par_i)
A method to add parameters to the list of correlated Gaussian parameters.
Definition: CorrelatedGaussianParameters.cpp:55
gslpp::sqrt
complex sqrt(const complex &z)
Definition: gslpp_complex.cpp:385
ModelParameter
A class for model parameters.
Definition: ModelParameter.h:28
gslpp::matrix< double >::size_i
size_t size_i() const
Definition: gslpp_matrix_double.cpp:132
CorrelatedGaussianParameters::Pars
std::vector< ModelParameter > Pars
A vector of parameters whose correlation will be calculated.
Definition: CorrelatedGaussianParameters.h:135
gslpp::vector< double >
A class for constructing and defining operations on real vectors.
Definition: gslpp_vector_double.h:33
ModelParameter::setCgp_name
void setCgp_name(std::string cgp_name)
A set method to set the name of the set of correlated parameter.
Definition: ModelParameter.h:140
CorrelatedGaussianParameters::name
std::string name
The name of the correlated Gaussian Parameters set.
Definition: CorrelatedGaussianParameters.h:137
CorrelatedGaussianParameters::Cov
gslpp::matrix< double > * Cov
The covariance matrix.
Definition: CorrelatedGaussianParameters.h:136
gslpp::matrix< double >::eigensystem
void eigensystem(matrix< complex > &U, vector< complex > &S)
Definition: gslpp_matrix_double.cpp:280
gslpp::vector< gslpp::complex >
CorrelatedGaussianParameters::getDiagPars
const std::vector< ModelParameter > & getDiagPars() const
A get method to access the diagonalized parameters.
Definition: CorrelatedGaussianParameters.h:100
CorrelatedGaussianParameters::getPar
ModelParameter getPar(int i) const
A get method to access an element of the vector of parameters that are defined in one correlated Gaus...
Definition: CorrelatedGaussianParameters.h:74
CorrelatedGaussianParameters::IsEOF
bool IsEOF
Definition: CorrelatedGaussianParameters.h:141