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 24 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 (TMatrixDSym Corr)
 Diagonalizes the correlated Gaussian parameters set. More...
 
const TMatrixDSym & 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

TMatrixDSym 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.

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

◆ CorrelatedGaussianParameters() [2/3]

CorrelatedGaussianParameters::CorrelatedGaussianParameters ( )

The default Constructor.

Definition at line 23 of file CorrelatedGaussianParameters.cpp.

23 {
24 v = NULL;
25 e = NULL;
26 IsEOF = false;
27}

◆ CorrelatedGaussianParameters() [3/3]

CorrelatedGaussianParameters::CorrelatedGaussianParameters ( const CorrelatedGaussianParameters orig)

The copy constructor.

Definition at line 29 of file CorrelatedGaussianParameters.cpp.

29 : Cov(orig.Cov)
30 {
31 Pars = orig.Pars;
32 name = orig.name;
33 v = new gslpp::matrix<double>(*orig.v);
34 e = new gslpp::vector<double>(*orig.e);
35 DiagPars = orig.DiagPars;
36 IsEOF = orig.IsEOF;
37}
std::vector< ModelParameter > DiagPars
The eigenvector of the covariance matrix.
TMatrixDSym Cov
The covariance matrix.
std::vector< ModelParameter > Pars
A vector of parameters whose correlation will be calculated.

◆ ~CorrelatedGaussianParameters()

CorrelatedGaussianParameters::~CorrelatedGaussianParameters ( )
virtual

The default destructor.

Definition at line 39 of file CorrelatedGaussianParameters.cpp.

39 {
40 //Cov = new gslpp::matrix<double>(10, 10, 0.); /** Put in to prevent seg fault during error handling in InputParser **/
41 if (v != NULL)
42 delete(v);
43 if (e != NULL)
44 delete(e);
45}

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

47 {
48 Pars.push_back(Par_i);
49}

◆ DiagonalizePars()

void CorrelatedGaussianParameters::DiagonalizePars ( TMatrixDSym  Corr)

Diagonalizes the correlated Gaussian parameters set.

Parameters
Corrthe correlation matrix for the correlated Gaussian parameters set

Definition at line 51 of file CorrelatedGaussianParameters.cpp.

51 {
52 unsigned int size = Pars.size();
53 if (Corr.GetNrows() != size || Corr.GetNcols() != size)
54 throw std::runtime_error("The size of the correlated parameters in " + name + " does not match the size of the correlation matrix!");
55 Cov.ResizeTo(size,size);
56 for (unsigned int i = 0; i < size; i++) {
57 for (unsigned int j = i; j < size; j++) {
58 Cov(i, j) = Pars.at(i).geterrg() * Corr(i, j) * Pars.at(j).geterrg();
59 Cov(j, i) = Cov(i, j); // Make sure TMatrixDsym element (j,i) is stored symmetrically
60 }
61 }
62
63 // *Cov = Cov->inverse();
64
65 TMatrixDSymEigen SE(Cov);
66
67 TMatrixD vv(SE.GetEigenVectors());
68 TVectorD ee(SE.GetEigenValues());
69 unsigned int EVbad = 0;
70
71 v = new gslpp::matrix<double>(size, size, 0.);
72 e = new gslpp::vector<double>(size, 0.);
73
74 for (unsigned int i = 0; i < size; i++) {
75 (*e)(i) = ee(i);
76 for (unsigned int j = 0; j < size; j++) {
77 (*v)(i, j) = vv(i, j);
78 }
79
80 if (ee(i) <= 0.) {
81 EVbad++;
82 }
83
84 }
85
86 if (EVbad > 0) {
87 std::cout << "WARNING: Covariance matrix of the correlated parameters in "<< name <<" is not a positive definite matrix!" << std::endl;
88 std::cout << "("<< EVbad <<" non positive eigenvalue(s).)" << std::endl;
89 sleep(2);
90 }
91
92 gslpp::vector<double> ave_in(size, 0.);
93
94 int ind = 0;
95 for (std::vector<ModelParameter>::iterator it = Pars.begin(); it != Pars.end(); it++) {
96 ave_in(ind) = it->getave();
97 ind++;
98 }
99
100 gslpp::vector<double> ave = v->transpose() * ave_in;
101
102 for (unsigned int i = 0; i < size; i++) {
103 std::stringstream ss;
104 ss << (i + 1);
105 std::string namei = name + ss.str();
106 // ModelParameter current(namei,ave(i),1./sqrt((*e)(i)),0.);
107 ModelParameter current(namei, ave(i), sqrt((*e)(i)), 0.);
108 current.setCgp_name(name);
109 DiagPars.push_back(current);
110 //std::cout << current << std::endl;
111 }
112}
A class for model parameters.

◆ getCov()

const TMatrixDSym & CorrelatedGaussianParameters::getCov ( ) const
inline

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

Definition at line 92 of file CorrelatedGaussianParameters.h.

93 {
94 return Cov;
95 }

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

102 {
103 return DiagPars;
104 }

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

85 {
86 return name;
87 }

◆ getOrigParsValue()

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

Definition at line 114 of file CorrelatedGaussianParameters.cpp.

114 {
115 if (DiagPars_i.size() != DiagPars.size()) {
116 std::stringstream out;
117 out << DiagPars_i.size();
118 throw std::runtime_error("CorrelatedGaussianParameters::getOrigParsValue(DiagPars_i): DiagPars_i.size() = " + out.str() + " does not match the size of DiagPars");
119 }
120 gslpp::vector<double> pars_in(DiagPars_i.size(), 0.);
121
122 int ind = 0;
123 for (std::vector<double>::const_iterator it = DiagPars_i.begin(); it != DiagPars_i.end(); it++) {
124 pars_in(ind) = *it;
125 ind++;
126 }
127
128 gslpp::vector<double> val = (*v) * pars_in;
129
130 std::vector<double> res;
131
132 for (unsigned int i = 0; i < DiagPars_i.size(); i++) {
133 res.push_back(val(i));
134 }
135 return (res);
136}

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

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

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

66 {
67 return Pars;
68 }

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

131 {
132 return IsEOF;
133 }

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

143 {
144 name = *beg;
145 ++beg;
146 int size = atoi((*beg).c_str());
147 int nlines = 0;
148 std::vector<bool> lines;
149 std::string line;
150 boost::char_separator<char>sep(" \t");
151 for (int i = 0; i < size; i++) {
152 IsEOF = getline(ifile, line).eof();
153 if (line.empty() || line.at(0) == '#') {
154 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);
155 else sleep(2);
156 }
157 lineNo++;
158 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
159 beg = tok.begin();
160 std::string type = *beg;
161 ++beg;
162 if (type.compare("ModelParameter") != 0) {
163 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");
164 else sleep(2);
165 }
166 ModelParameter tmpMP;
167 beg = tmpMP.ParseModelParameter(beg);
168 lines.push_back(!tmpMP.IsFixed());
169 if (beg != tok.end())
170 if (rank == 0) std::cout << "WARNING: unread information in parameter " << tmpMP.getname() << std::endl;
171 if (!tmpMP.IsFixed()) {
172 tmpMP.setCgp_name(name);
173 AddPar(tmpMP);
174 nlines++;
175 } else {
176 ModPars.push_back(tmpMP);
177 }
178 }
179 if (nlines > 1) {
180 TMatrixD myCorr(nlines, nlines);
181 int ni = 0;
182 for (int i = 0; i < size; i++) {
183 IsEOF = getline(ifile, line).eof();
184 if (line.empty() || line.at(0) == '#') {
185 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);
186 else sleep(2);
187 }
188 lineNo++;
189 if (lines.at(i)) {
190 boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
191 beg = mytok.begin();
192 int nj = 0;
193 for (int j = 0; j < size; j++) {
194 if ((*beg).compare(0, 1, "0") == 0
195 || (*beg).compare(0, 1, "1") == 0
196 || (*beg).compare(0, 1, "-") == 0) {
197 if (std::distance(mytok.begin(), mytok.end()) < size) {
198 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");
199 else sleep(2);
200 }
201 if (lines.at(j)) {
202 myCorr(ni, nj) = atof((*beg).c_str());
203 nj++;
204 }
205 beg++;
206 } else {
207 if (rank == 0) std::cout << "ERROR: invalid correlation matrix for "
208 << name << ". Check element (" << ni + 1 << "," << nj + 1 << ") in line number " + boost::lexical_cast<std::string>(lineNo) << std::endl;
209 exit(EXIT_FAILURE);
210 }
211 }
212 ni++;
213 }
214 }
215 if (!myCorr.IsSymmetric()) {
216 if (rank == 0) std::cout << "ERROR: invalid correlation matrix for "
217 << name << ". Correlation matrix is not symmetric." << std::endl;
218 exit(EXIT_FAILURE);
219 } else {
220 TMatrixDSym mySCorr(nlines);
221 for (int i = 0; i < nlines; i++) {
222 for (int j = 0; j <= i; j++) {
223 mySCorr(i, j) = myCorr(i, j);
224 mySCorr(j, i) = mySCorr(i, j); // Make sure TMatrixDsym element (j,i) is stored symmetrically
225 }
226 }
227 DiagonalizePars(mySCorr);
228 ModPars.insert(ModPars.end(), getDiagPars().begin(), getDiagPars().end());
229 }
230 } else {
231 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;
232 if (getPars().size() == 1) ModPars.push_back(ModelParameter(getPar(0)));
233 for (int i = 0; i < size; i++) {
234 IsEOF = getline(ifile, line).eof();
235 lineNo++;
236 }
237 }
238 return lineNo;
239}
const std::vector< ModelParameter > & getPars() const
A get method to access the vector of parameters that are defined in one correlated Gaussian parameter...
void AddPar(ModelParameter &Par_i)
A method to add parameters to the list of correlated Gaussian parameters.
const std::vector< ModelParameter > & getDiagPars() const
A get method to access the diagonalized parameters.
void DiagonalizePars(TMatrixDSym Corr)
Diagonalizes the correlated Gaussian parameters set.
ModelParameter getPar(int i) const
A get method to access an element of the vector of parameters that are defined in one correlated Gaus...
boost::tokenizer< boost::char_separator< char > >::iterator & ParseModelParameter(boost::tokenizer< boost::char_separator< char > >::iterator &beg)
Parser for model parameters.
void setCgp_name(std::string cgp_name)
A set method to set the name of the set of correlated parameter.
std::string getname() const
A get method to get the name of each parameter.
bool IsFixed() const
A method to check if the parameter is fixed.

Member Data Documentation

◆ Cov

TMatrixDSym CorrelatedGaussianParameters::Cov
private

The covariance matrix.

Definition at line 137 of file CorrelatedGaussianParameters.h.

◆ DiagPars

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

The eigenvector of the covariance matrix.

Definition at line 141 of file CorrelatedGaussianParameters.h.

◆ e

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

The diagonalized parameters.

Definition at line 140 of file CorrelatedGaussianParameters.h.

◆ IsEOF

bool CorrelatedGaussianParameters::IsEOF
private

Definition at line 142 of file CorrelatedGaussianParameters.h.

◆ name

std::string CorrelatedGaussianParameters::name
private

The name of the correlated Gaussian Parameters set.

Definition at line 138 of file CorrelatedGaussianParameters.h.

◆ Pars

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

A vector of parameters whose correlation will be calculated.

Definition at line 136 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 139 of file CorrelatedGaussianParameters.h.


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