13#include <boost/lexical_cast.hpp>
33 v =
new gslpp::matrix<double>(*orig.
v);
34 e =
new gslpp::vector<double>(*orig.
e);
48 Pars.push_back(Par_i);
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();
65 TMatrixDSymEigen SE(
Cov);
67 TMatrixD vv(SE.GetEigenVectors());
68 TVectorD ee(SE.GetEigenValues());
69 unsigned int EVbad = 0;
71 v =
new gslpp::matrix<double>(size, size, 0.);
72 e =
new gslpp::vector<double>(size, 0.);
74 for (
unsigned int i = 0; i < size; i++) {
76 for (
unsigned int j = 0; j < size; j++) {
77 (*v)(i, j) = vv(i, j);
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;
92 gslpp::vector<double> ave_in(size, 0.);
95 for (std::vector<ModelParameter>::iterator it =
Pars.begin(); it !=
Pars.end(); it++) {
96 ave_in(ind) = it->getave();
100 gslpp::vector<double> ave =
v->transpose() * ave_in;
102 for (
unsigned int i = 0; i < size; i++) {
103 std::stringstream ss;
105 std::string namei =
name + ss.str();
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");
120 gslpp::vector<double> pars_in(DiagPars_i.size(), 0.);
123 for (std::vector<double>::const_iterator it = DiagPars_i.begin(); it != DiagPars_i.end(); it++) {
128 gslpp::vector<double> val = (*v) * pars_in;
130 std::vector<double> res;
132 for (
unsigned int i = 0; i < DiagPars_i.size(); i++) {
133 res.push_back(val(i));
139 std::string& filename,
140 std::ifstream& ifile,
141 boost::tokenizer<boost::char_separator<char> >::iterator & beg,
146 int size = atoi((*beg).c_str());
148 std::vector<bool> lines;
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);
158 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
160 std::string type = *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");
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;
176 ModPars.push_back(tmpMP);
180 TMatrixD myCorr(nlines, nlines);
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);
190 boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
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");
202 myCorr(ni, nj) = atof((*beg).c_str());
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;
215 if (!myCorr.IsSymmetric()) {
216 if (rank == 0) std::cout <<
"ERROR: invalid correlation matrix for "
217 <<
name <<
". Correlation matrix is not symmetric." << std::endl;
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);
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;
233 for (
int i = 0; i < size; i++) {
234 IsEOF = getline(ifile, line).eof();
A class for model parameters.
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.