20#include "../../kernel.hpp"
22#include "../interval.hpp"
30 std::vector<double>
vx;
31 std::vector<double>
vy;
33 std::vector<std::vector<double> >
vz;
34 std::vector<std::vector<double> >
vz_w;
68static void createTeXExport(
Fitcontroller& _fControl,
const std::string& sTeXExportFile,
const std::string& sCmd,
mu::varmap_type& paramsMap,
FittingData& fitData,
const std::vector<double>& vInitialVals,
size_t nSize,
const std::string& sFitAnalysis,
const std::string& sFuncDisplay,
const std::string& sFittedFunction,
double dChisq);
78 vector<double> vInitialVals;
79 vector<double> vInterVal;
84 string sFitLog =
"<savepath>/numerefit.log";
87 bool bMaskDialog =
false;
88 bool bTeXExport =
false;
89 string sTeXExportFile =
"<savepath>/fit.tex";
90 string sDimsForFitLog;
91 string sFunctionDefString =
"";
92 string sFuncDisplay =
"";
138 if (varMap.find(
"x") != varMap.end())
141 if (varMap.find(
"y") != varMap.end())
144 if (varMap.find(
"z") != varMap.end())
157 if (varMap.find(fitData.
sChiMap_Vars[0]) == varMap.end())
160 if (varMap.find(fitData.
sChiMap_Vars[1]) == varMap.end())
173 for (
auto pItem = paramsMap.begin(); pItem != paramsMap.end(); ++pItem)
175 if (pItem->first ==
"x" || pItem->first ==
"y" || pItem->first ==
"z")
178 if (varMap.find(pItem->first) == varMap.end())
194 if (!paramsMap.size())
208 if (paramsMap.size() > fitData.
vy.size())
211 if (paramsMap.size() > fitData.
vx.size())
215 && (paramsMap.size() > fitData.
vz.size() || paramsMap.size() > fitData.
vz[0].size()))
226 for (
auto iter = paramsMap.begin(); iter != paramsMap.end(); ++iter)
228 vInitialVals.push_back((*(iter->second)).real());
235 return calculateChiMap(sFunctionDefString, sFuncDisplay, _idx, varMap, paramsMap, fitData, vInitialVals);
243 sFunctionDefString =
applyFitAlgorithm(_fControl, fitData, paramsMap, sFuncDisplay, sCmd);
258 size_t nSize = ((fitData.
vz.size()) ? (fitData.
vz.size() * fitData.
vz[0].size()) : fitData.
vx.size());
267 oFitLog.open(sFitLog.c_str(), ios_base::ate | ios_base::app);
279 oFitLog << std::setw(156) << std::setfill(
'=') <<
'=' << endl;
281 oFitLog << std::setw(156) << std::setfill(
'=') <<
'=' << endl;
284 oFitLog <<
getFitOptionsTable(_fControl, fitData, sFuncDisplay, sFittedFunction, sDimsForFitLog, dChisq, paramsMap, nSize,
true) << endl;
286 string sPMSign =
" ";
287 sPMSign[0] = (char)177;
291 oFitLog <<
_lang.
get(
"PARSERFUNCS_FIT_LOG_TABLEHEAD1") << endl;
293 oFitLog <<
_lang.
get(
"PARSERFUNCS_FIT_LOG_TABLEHEAD2") << endl;
296 oFitLog << std::setw(156) << std::setfill(
'-') <<
'-' << endl;
297 oFitLog <<
getParameterTable(fitData, paramsMap, vInitialVals, 160, sPMSign,
true);
298 oFitLog << std::setw(156) << std::setfill(
'-') <<
'-' << endl;
344 if (paramsMap.size() > 1 && paramsMap.size() != nSize)
347 oFitLog <<
_lang.
get(
"PARSERFUNCS_FIT_CORRELMAT_HEAD") <<
":" << endl;
364 string sFitAnalysis =
getFitAnalysis(_fControl, fitData, dChisq / (
double)(nSize - paramsMap.size()), dAverageErrorPercentage, nSize != paramsMap.size());
367 oFitLog <<
_lang.
get(
"PARSERFUNCS_FIT_ANALYSIS") <<
":" << endl;
368 oFitLog << sFitAnalysis << endl;
382 createTeXExport(_fControl, sTeXExportFile, sCmd, paramsMap, fitData, vInitialVals, nSize, sFitAnalysis, sFuncDisplay, sFittedFunction, dChisq);
386 bool bDefinitionSuccess =
false;
388 if (!_functions.
isDefined(sFunctionDefString))
389 bDefinitionSuccess = _functions.
defineFunc(sFunctionDefString);
391 bDefinitionSuccess = _functions.
defineFunc(sFunctionDefString,
true);
395 if (bDefinitionSuccess)
413 vector<double> vInterVal;
414 static const string sBADFUNCTIONS =
"ascii(),char(),findfile(),findparam(),gauss(),getopt(),is_string(),rand(),replace(),replaceall(),split(),strfnd(),string_cast(),strrfnd(),strlen(),time(),to_char(),to_cmd(),to_string(),to_value()";
455 sTeXExportFile = _data.
ValidFileName(sTeXExportFile,
".tex");
457 if (sTeXExportFile.substr(sTeXExportFile.rfind(
'.')) !=
".tex")
458 sTeXExportFile.replace(sTeXExportFile.rfind(
'.'), string::npos,
".tex");
462 for (
unsigned int i = 0; i < sCmd.length(); i++)
479 for (
size_t i = 0; i < vInterVal.size(); i += 2)
481 fitData.
ivl[i / 2].reset(vInterVal[i], vInterVal[i+1]);
487 for (
unsigned int i = 0; i < fitData.
sFitFunction.length(); i++)
494 fitData.
sFitFunction.replace(i, string::npos, sCmd.substr(sCmd.find(
'-')));
599 sCmd = sCmd.substr(0,
findParameter(sCmd,
"params",
'=') - 1);
603 if (fitData.
sParams.find(
'[') != string::npos)
606 if (fitData.
sParams.find(
']') != string::npos)
623 if (fitData.
sParams.back() ==
'-')
662 while (sBADFUNCTIONS.find(
',', nPos) != string::npos)
664 if (fitData.
sFitFunction.find(sBADFUNCTIONS.substr(nPos, sBADFUNCTIONS.find(
',', nPos) - nPos - 1)) != string::npos)
669 nPos = sBADFUNCTIONS.find(
',', nPos) + 1;
671 if (nPos >= sBADFUNCTIONS.length())
695 if (paramsMap.find(
"x") != paramsMap.end())
696 paramsMap.erase(paramsMap.find(
"x"));
698 if (paramsMap.find(
"y") != paramsMap.end())
699 paramsMap.erase(paramsMap.find(
"y"));
701 if (!paramsMap.size())
714 if (fitData.
sParams.find(
'=') != string::npos)
716 for (
size_t i = 0; i < fitData.
sParams.length(); i++)
720 for (
size_t j = i; j < fitData.
sParams.length(); j++)
727 fitData.
sParams.erase(i, j - i);
731 if (j == fitData.
sParams.length() - 1)
754 vector<double> vTempZ;
755 string sDataTable =
"";
758 bool openEnd =
false;
759 bool isCluster =
false;
803 else if (nColumns == 2)
851 if (
isnan(fitData.
ivl[1].front()) && !isCluster)
865 if (nDim == 2 || isCluster)
867 for (
size_t i = 0; i < _idx.
row.
size(); i++)
874 fitData.
vx.push_back(_idx.
row[i] + 1);
902 else if (nColumns == 4)
905 for (
size_t i = 0; i < _idx.
row.
size(); i++)
924 fitData.
vy_w.push_back(0.0);
938 fitData.
vy_w.push_back(0.0);
963 fitData.
vy_w.push_back(0.0);
968 else if (!isCluster && (fitData.
nFitVars & 2))
970 for (
size_t i = 0; i < _idx.
row.
size(); i++)
984 for (
size_t k = 2; k < _idx.
col.
size(); k++)
986 if (nColumns > 3 && k == _idx.
row.
size() + 2)
994 vTempZ.push_back(NAN);
997 fitData.
vy_w.push_back(0.0);
1001 vTempZ.push_back(_data.
getElement(_idx.
row[i], _idx.
col[k], sDataTable).real());
1008 fitData.
vy_w.push_back(0.0);
1013 fitData.
vz.push_back(vTempZ);
1018 fitData.
vz_w.push_back(fitData.
vy_w);
1019 fitData.
vy_w.clear();
1025 for (
unsigned int i = 0; i < _idx.
row.
size(); i++)
1040 fitData.
vy_w.push_back(0.0);
1045 sDimsForFitLog.clear();
1065 else if (nColumns == 4)
1072 if (nErrorCols == 2)
1073 sDimsForFitLog +=
", " +
toString(_idx.
col[3] + 1);
1104 for (
int k = 0; k < (int)nDim; k++)
1108 if (k + 1 < (
int)nDim)
1109 sDimsForFitLog +=
", ";
1128 while (sFunction.front() ==
'(')
1132 sFunction.erase(0, 1);
1133 sFunction.pop_back();
1153 for (
size_t i = 0; i < _idx.
row.
size(); i++)
1157 auto iter = paramsMap.begin();
1159 for (
unsigned int n = 0; n < vInitialVals.size(); n++)
1161 *(iter->second) = vInitialVals[n];
1190 sFunctionDefString =
"Fit(x) := " + sFuncDisplay +
" " +
_lang.
get(
"PARSERFUNCS_FIT_DEFINECOMMENT");
1202 sFunctionDefString =
"Fitw(x) := " + sFuncDisplay +
" " +
_lang.
get(
"PARSERFUNCS_FIT_DEFINECOMMENT");
1205 else if (fitData.
nDim == 3)
1215 sFunctionDefString =
"Fit(x,y) := " + sFuncDisplay +
" " +
_lang.
get(
"PARSERFUNCS_FIT_DEFINECOMMENT");
1217 else if (fitData.
nDim == 5)
1227 sFunctionDefString =
"Fitw(x,y) := " + sFuncDisplay +
" " +
_lang.
get(
"PARSERFUNCS_FIT_DEFINECOMMENT");
1240 auto iter = paramsMap.begin();
1242 for (
unsigned int n = 0; n < vInitialVals.size(); n++)
1244 *(iter->second) = vInitialVals[n];
1254 bool bDefinitionSuccess =
false;
1256 if (!_functions.
isDefined(sFunctionDefString))
1257 bDefinitionSuccess = _functions.
defineFunc(sFunctionDefString);
1259 bDefinitionSuccess = _functions.
defineFunc(sFunctionDefString,
true);
1263 if (bDefinitionSuccess)
1279 string sFunctionDefString;
1294 sFunctionDefString =
"Fit(x) := " + sFuncDisplay +
" " +
_lang.
get(
"PARSERFUNCS_FIT_DEFINECOMMENT");
1306 sFunctionDefString =
"Fitw(x) := " + sFuncDisplay +
" " +
_lang.
get(
"PARSERFUNCS_FIT_DEFINECOMMENT");
1309 else if (fitData.
nDim == 3)
1319 sFunctionDefString =
"Fit(x,y) := " + sFuncDisplay +
" " +
_lang.
get(
"PARSERFUNCS_FIT_DEFINECOMMENT");
1321 else if (fitData.
nDim == 5)
1331 sFunctionDefString =
"Fitw(x,y) := " + sFuncDisplay +
" " +
_lang.
get(
"PARSERFUNCS_FIT_DEFINECOMMENT");
1334 return sFunctionDefString;
1347 double dSize = (fitData.
vz.size()) ? (fitData.
vz.size() * fitData.
vz[0].size()) : fitData.
vx.size();
1348 double dFactor = dChisq;
1352 dFactor /= dSize - paramsMapSize;
1354 dFactor /= dSize*dSize - paramsMapSize;
1358 for (
unsigned int i = 0; i < fitData.
vz_w.size(); i++)
1360 for (
unsigned int j = 0; j < fitData.
vz_w[0].size(); j++)
1362 fitData.
vz_w[i][j] *= dFactor;
1373 string sFitParameterTable;
1378 sFitParameterTable +=
_lang.
get(
"PARSERFUNCS_FIT_FUNCTION", sFuncDisplay) +
"\n";
1379 sFitParameterTable +=
_lang.
get(
"PARSERFUNCS_FIT_FITTED_FUNC", sFittedFunction) +
"\n";
1380 sFitParameterTable +=
_lang.
get(
"PARSERFUNCS_FIT_DATASET") +
" " + sDimsForFitLog +
"\n";
1384 sFitParameterTable +=
_lang.
get(
"PARSERFUNCS_FIT_FUNCTION", sFittedFunction) +
"\n";
1389 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_POINTS_W_ERR",
toString((
int)nSize)) +
"\n";
1391 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_POINTS_WO_ERR",
toString((
int)nSize)) +
"\n";
1394 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_COORD_RESTRICTS",
"x",
toString(fitData.
ivl[0].min(), 5),
toString(fitData.
ivl[0].max(), 5)) +
"\n";
1397 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_COORD_RESTRICTS",
"y",
toString(fitData.
ivl[1].min(), 5),
toString(fitData.
ivl[1].max(), 5)) +
"\n";
1400 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_COORD_RESTRICTS",
"z",
toString(fitData.
ivl[2].min(), 5),
toString(fitData.
ivl[2].max(), 5)) +
"\n";
1404 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_PARAM_RESTRICTS", fitData.
sRestrictions) +
"\n";
1406 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_FREEDOMS",
toString((
int)nSize - paramsMap.size())) +
"\n";
1410 if (nSize != paramsMap.size() && !(fitData.
nFitVars & 2))
1412 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_CHI2",
toString(dChisq, 7)) +
"\n";
1413 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_RED_CHI2",
toString(dChisq / (
double) (nSize - paramsMap.size()), 7)) +
"\n";
1414 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_STD_DEV",
toString(sqrt(_fControl.
getFitChi() / (
double)(nSize - paramsMap.size())), 7)) +
"\n";
1416 else if (fitData.
nFitVars & 2 && nSize != paramsMap.size() )
1418 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_CHI2",
toString(dChisq, 7)) +
"\n";
1419 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_RED_CHI2",
toString(dChisq / (
double) (nSize - paramsMap.size()), 7)) +
"\n";
1420 sFitParameterTable += sPrefix +
_lang.
get(
"PARSERFUNCS_FIT_STD_DEV",
toString(sqrt(_fControl.
getFitChi() / (
double)(nSize - paramsMap.size())), 7)) +
"\n";
1423 return sFitParameterTable;
1434 for (
unsigned int n = 0; n < paramsMapSize; n++)
1443 else if (n + 1 == paramsMapSize)
1449 for (
unsigned int k = 0; k < paramsMapSize; k++)
1456 sCovMatrix +=
" \\\n";
1457 else if (n + 1 == paramsMapSize)
1458 sCovMatrix +=
" /\n";
1460 sCovMatrix +=
" |\n";
1472 auto pItem = paramsMap.begin();
1473 string sParameterTable;
1476 for (
size_t n = 0; n < paramsMap.size(); n++)
1478 if (pItem == paramsMap.end())
1483 sParameterTable +=
"| ";
1487 sParameterTable += pItem->first +
" "
1488 +
strfill(
toString(vInitialVals[n], _option), (pItem->first.length() > (windowSize - 32) / 2 + windowSize % 2 ? 0u : (windowSize - 32) / 2 + windowSize % 2 - pItem->first.length()))
1494 if (fitData.
vz_w[n][n])
1496 sParameterTable +=
" " +
strfill(
"(" +
toString(
abs(sqrt(
abs(fitData.
vz_w[n][n])) / (*(pItem->second)) * 100.0), 4) +
"%)", 16) +
"\n";
1498 sParameterTable +=
"\n";
1503 return sParameterTable;
1513 string sErrors =
"";
1514 auto pItem = paramsMap.begin();
1515 double dAverageErrorPercentage = 0.0;
1520 for (
unsigned int n = 0; n < paramsMap.size(); n++)
1522 if (pItem == paramsMap.end())
1526 if (fitData.
vz_w[n][n])
1528 dAverageErrorPercentage +=
abs(sqrt(
abs(fitData.
vz_w[n][n] / (*(pItem->second)))) * 100.0);
1534 sErrors += pItem->first +
"_error = " +
toCmdString(sqrt(
abs(fitData.
vz_w[n][n]))) +
",";
1541 dAverageErrorPercentage /= (double)paramsMap.size();
1554 return dAverageErrorPercentage;
1563 dNormChisq = sqrt(dNormChisq);
1567 return _lang.
get(
"PARSERFUNCS_FIT_MAXITER_REACHED");
1575 if (log10(dNormChisq) > -1.0 && log10(dNormChisq) < 0.5 && dAverageErrorPercentage < 50.0)
1576 return _lang.
get(
"PARSERFUNCS_FIT_GOOD_W_ERROR");
1577 else if (log10(dNormChisq) <= -1.0 && dAverageErrorPercentage < 20.0)
1578 return _lang.
get(
"PARSERFUNCS_FIT_BETTER_W_ERROR");
1579 else if (log10(dNormChisq) >= 0.5 && log10(dNormChisq) < 1.5 && dAverageErrorPercentage < 100.0)
1580 return _lang.
get(
"PARSERFUNCS_FIT_NOT_GOOD_W_ERROR");
1582 return _lang.
get(
"PARSERFUNCS_FIT_BAD_W_ERROR");
1586 if (log10(dNormChisq) < -3.0 && dAverageErrorPercentage < 20.0)
1587 return _lang.
get(
"PARSERFUNCS_FIT_GOOD_WO_ERROR");
1588 else if (log10(dNormChisq) < 0.0 && dAverageErrorPercentage < 50.0)
1589 return _lang.
get(
"PARSERFUNCS_FIT_IMPROVABLE_WO_ERROR");
1590 else if (log10(dNormChisq) >= 0.0 && log10(dNormChisq) < 0.5 && dAverageErrorPercentage < 100.0)
1591 return _lang.
get(
"PARSERFUNCS_FIT_NOT_GOOD_WO_ERROR");
1593 return _lang.
get(
"PARSERFUNCS_FIT_BAD_WO_ERROR");
1598 return _lang.
get(
"PARSERFUNCS_FIT_OVERFITTING");
1608static void createTeXExport(
Fitcontroller& _fControl,
const string& sTeXExportFile,
const string& sCmd,
mu::varmap_type& paramsMap,
FittingData& fitData,
const vector<double>& vInitialVals,
size_t nSize,
const string& sFitAnalysis,
const string& sFuncDisplay,
const string& sFittedFunction,
double dChisq)
1610 ofstream oTeXExport;
1615 if (oTeXExport.fail())
1623 oTeXExport <<
"%\n% " <<
_lang.
get(
"OUTPUT_PRINTLEGAL_TEX") <<
"\n%" << endl;
1624 oTeXExport <<
"\\section{" <<
_lang.
get(
"PARSERFUNCS_FIT_HEADLINE") <<
": " <<
getTimeStamp(
false) <<
"}" << endl;
1625 oTeXExport <<
"\\begin{itemize}" << endl;
1626 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_FUNCTION",
"$" +
replaceToTeX(sFuncDisplay,
true) +
"$") << endl;
1627 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_FITTED_FUNC",
"$" +
replaceToTeX(sFittedFunction,
true) +
"$") << endl;
1630 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_POINTS_W_ERR",
toString((
int)nSize)) << endl;
1632 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_POINTS_WO_ERR",
toString((
int)nSize)) << endl;
1635 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_COORD_RESTRICTS",
"x",
toString(fitData.
ivl[0].min(), 5),
toString(fitData.
ivl[0].max(), 5)) << endl;
1638 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_COORD_RESTRICTS",
"y",
toString(fitData.
ivl[1].min(), 5),
toString(fitData.
ivl[1].max(), 5)) << endl;
1641 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_COORD_RESTRICTS",
"z",
toString(fitData.
ivl[2].min(), 5),
toString(fitData.
ivl[2].max(), 5)) << endl;
1646 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_FREEDOMS",
toString((
int)nSize - paramsMap.size())) << endl;
1651 if (nSize != paramsMap.size() && !(fitData.
nFitVars & 2))
1653 string sChiReplace =
_lang.
get(
"PARSERFUNCS_FIT_CHI2",
toString(dChisq, 7));
1654 sChiReplace.replace(sChiReplace.find(
"chi^2"), 5,
"$\\chi^2$");
1655 oTeXExport <<
"\t\\item " << sChiReplace << endl;
1656 sChiReplace =
_lang.
get(
"PARSERFUNCS_FIT_RED_CHI2",
toString(dChisq / (
double) (nSize - paramsMap.size()), 7));
1657 sChiReplace.replace(sChiReplace.find(
"chi^2"), 5,
"$\\chi^2$");
1658 oTeXExport <<
"\t\\item " << sChiReplace << endl;
1659 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_STD_DEV",
toString(sqrt(_fControl.
getFitChi() / (
double)(nSize - paramsMap.size())), 7)) << endl;
1661 else if (fitData.
nFitVars & 2 && nSize != paramsMap.size())
1663 string sChiReplace =
_lang.
get(
"PARSERFUNCS_FIT_CHI2",
toString(dChisq, 7));
1664 sChiReplace.replace(sChiReplace.find(
"chi^2"), 5,
"$\\chi^2$");
1665 oTeXExport <<
"\t\\item " << sChiReplace << endl;
1666 sChiReplace =
_lang.
get(
"PARSERFUNCS_FIT_RED_CHI2",
toString(dChisq / (
double) (nSize - paramsMap.size()), 7));
1667 sChiReplace.replace(sChiReplace.find(
"chi^2"), 5,
"$\\chi^2$");
1668 oTeXExport <<
"\t\\item " << sChiReplace << endl;
1669 oTeXExport <<
"\t\\item " <<
_lang.
get(
"PARSERFUNCS_FIT_STD_DEV",
toString(sqrt(_fControl.
getFitChi() / (
double)(nSize - paramsMap.size())), 7)) << endl;
1673 oTeXExport <<
"\\end{itemize}" << endl <<
"\\begin{table}[htb]" << endl <<
"\t\\centering\n\t\\begin{tabular}{cccc}" << endl <<
"\t\t\\toprule" << endl;
1677 oTeXExport <<
"\t\t" <<
_lang.
get(
"PARSERFUNCS_FIT_PARAM") <<
" & "
1678 <<
_lang.
get(
"PARSERFUNCS_FIT_INITIAL") <<
" & "
1679 <<
_lang.
get(
"PARSERFUNCS_FIT_FITTED") <<
" & "
1680 <<
_lang.
get(
"PARSERFUNCS_FIT_PARAM_DEV") <<
"\\\\" << endl;
1682 oTeXExport <<
"\t\t" <<
_lang.
get(
"PARSERFUNCS_FIT_PARAM") <<
" & "
1683 <<
_lang.
get(
"PARSERFUNCS_FIT_INITIAL") <<
" & "
1684 <<
_lang.
get(
"PARSERFUNCS_FIT_FITTED") <<
" & "
1685 <<
_lang.
get(
"PARSERFUNCS_FIT_ASYMPTOTIC_ERROR") <<
"\\\\" << endl;
1687 oTeXExport <<
"\t\t\\midrule" << endl;
1689 auto pItem = paramsMap.begin();
1690 string sErrors =
"";
1691 string sPMSign =
" ";
1694 for (
unsigned int n = 0; n < paramsMap.size(); n++)
1696 if (pItem == paramsMap.end())
1699 oTeXExport <<
"\t\t$" <<
replaceToTeX(pItem->first,
true) <<
"$ & $"
1700 << vInitialVals[n] <<
"$ & $"
1701 << *(pItem->second) <<
"$ & $\\pm"
1702 << sqrt(
abs(fitData.
vz_w[n][n]));
1706 if (fitData.
vz_w[n][n])
1708 oTeXExport <<
" \\quad (" +
toString(
abs(sqrt(
abs(fitData.
vz_w[n][n] / (*(pItem->second)))) * 100.0), 4) +
"\\%)$\\\\" << endl;
1711 oTeXExport <<
"$\\\\" << endl;
1717 oTeXExport <<
"\t\t\\bottomrule" << endl <<
"\t\\end{tabular}" << endl <<
"\\end{table}" << endl;
1720 if (paramsMap.size() > 1 && paramsMap.size() != nSize)
1722 oTeXExport << endl <<
"\\subsection{" <<
_lang.
get(
"PARSERFUNCS_FIT_CORRELMAT_HEAD") <<
"}" << endl;
1723 oTeXExport <<
"\\[" << endl <<
"\t\\begin{pmatrix}" << endl;
1725 for (
unsigned int n = 0; n < paramsMap.size(); n++)
1727 oTeXExport <<
"\t\t";
1729 for (
unsigned int k = 0; k < paramsMap.size(); k++)
1731 oTeXExport << fitData.
vz_w[n][k] / sqrt(fabs(fitData.
vz_w[n][n]*fitData.
vz_w[k][k]));
1733 if (k + 1 < paramsMap.size())
1734 oTeXExport <<
" & ";
1737 oTeXExport <<
"\\\\" << endl;
1740 oTeXExport <<
"\t\\end{pmatrix}" << endl <<
"\\]" << endl;
1745 oTeXExport <<
"\\subsection{" <<
_lang.
get(
"PARSERFUNCS_FIT_ANALYSIS") <<
"}" << endl;
1746 oTeXExport << sFitAnalysis << endl;
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
This class contains the internal fit logic and the interface to the GSL fitting module.
bool fit(FitVector &vx, FitVector &vy, const std::string &__sExpr, const std::string &__sRestrictions, mu::varmap_type &mParamsMap, double __dPrecision=1e-4, int nMaxIterations=500)
Calculate an unweighted 1D-fit.
int getIterations() const
Return the number of needed iterations.
FitMatrix getCovarianceMatrix() const
Returns the covariance matrix of the performed fit.
double getFitChi() const
Return the weighted sum of the residuals.
std::string getFitFunction()
Returns the fit function, where each parameter is replaced with its value converted to a string.
This class implements the function definition managing instance.
std::string getDefinitionString(size_t _i) const
Returns the definition string of the ith defined custom function.
bool defineFunc(const std::string &sExpr, bool bRedefine=false, bool bFallback=false)
This function defines a custom function, by passing it to a new FunctionDefinition class instance.
bool call(std::string &sExpr, int nRecursion=0)
This function searches for known custom definitions in the passed expression and replaces them with t...
bool isDefined(const std::string &sFunc)
This method checks, whether the passed function is already defined.
size_t getFunctionIndex(const std::string &sFuncName)
Returns the numerical index of the selected custom defined functions.
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
This class represents the central memory managing instance. It will handle all tables and clusters,...
mu::value_type getElement(int _nLine, int _nCol, const std::string &_sTable) const
bool isValidElement(long long int _nLine, long long int _nCol, const std::string &_sTable) const
std::vector< mu::value_type > min(const std::string &sTable, std::string sDir) const
int getLines(StringView sTable, bool _bFull=false) const
std::vector< mu::value_type > num(const std::string &sTable, std::string sDir) const
std::string getHeadLineElement(int _i, const std::string &_sTable) const
std::vector< mu::value_type > max(const std::string &sTable, std::string sDir) const
bool containsTablesOrClusters(const std::string &sCmdLine)
This member function evaluates, whether the passed command line contains tables or clusters.
void writeToTable(int _nLine, int _nCol, const std::string &_sCache, const mu::value_type &_dData)
bool setHeadLineElement(int _i, const std::string &_sTable, std::string _sHead)
int getCols(StringView sTable, bool _bFull=false) const
size_t size() const
This member function returns the size of the internal memory buffer as items.
Cluster & getCluster(StringView sCluster)
This member function returns a reference to the cluster indicated by the passed cluster identifier.
std::string getDataFileName(const std::string &sTable) const
This member function will return the file name of the selected table. Will default to the table name.
virtual bool isStringExpression(const std::string &sExpression) override
Returns true, if the passed expression is an expression containing strings, string variables or strin...
static NumeReKernel * getInstance()
This static member function returns a a pointer to the singleton instance of the kernel.
NumeRe::StringParser & getStringParser()
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
MemoryManager & getMemoryManager()
static void print(const std::string &__sLine, bool printingEnabled=true)
This member function appends the passed string as a new output line to the buffer and informs the ter...
FunctionDefinitionManager & getDefinitions()
static void issueWarning(std::string sWarningMessage)
This static function may be used to issue a warning to the user. The warning will be printed by the t...
static void toggleTableStatus()
Toggles the table writing status, which will reduce the number or events send to the terminal.
This class manages the setting values of the internal (kernel) settings of this application.
bool systemPrints() const
Returns, whether system messages shall be printed to the terminal.
size_t getPrecision() const
Returns the precision for displaying floating numbers in the terminal. This value determines the numb...
size_t getWindow(int nWindow=0) const
Returns the current window size of the terminal.
Common exception class for all exceptions thrown in NumeRe.
@ CANNOT_BE_A_FITTING_PARAM
INSERT HERE.
@ FUNCTION_CANNOT_BE_FITTED
static size_t invalid_position
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
VectorIndex subidx(size_t pos, size_t nLen=std::string::npos) const
This member function returns a subset of the internal stored index just like the std::string::substr(...
int last() const
This member function returns the last index value, which can be reached by the values stored internal...
size_t size() const
This member function returns the size of the indices stored in this class.
bool isOpenEnd() const
This member function determines, whether the internal index set has an open end.
void setRange(int nMin, int nMax)
This member function can be used to force the indices stored internally to be in a defined interval....
std::string to_string() const
This member function converts the vector indexes contents into a human-readable string representation...
int & back()
This member function returns a reference to the final index value stored internally.
bool isExpanded() const
This member function determines, whether the indices are calculated or actual vectorial indices.
int & front()
This member function returns a reference to the first index value stored internally.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
const varmap_type & GetUsedVar()
Return a map containing the used variables only.
Mathematical expressions parser.
mu::value_type getDataFromObject(const std::string &sObject, long long int i, long long int j, bool isCluster)
This function returns the data from the selected object and switches automatically between tables and...
string getDataElements(string &sLine, Parser &_parser, MemoryManager &_data, const Settings &_option, int options)
Searches the passed string for calls to any table or cluster and replaces them with internal vectors ...
Indices getIndicesForPlotAndFit(const string &sExpression, string &sDataTable, int &nColumns, bool &openEnd, bool &isCluster)
This function will calculate the indices from the passed data expression and return them optimized fo...
Indices getIndices(StringView sCmd, mu::Parser &_parser, MemoryManager &_data, const Settings &_option)
Wrapper for the new getIndices function interface.
bool isValidIndexSet(const Indices &_idx)
std::string toSystemCodePage(std::string)
Converts an internal to an external string. Does nothing currently.
static void createTeXExport(Fitcontroller &_fControl, const std::string &sTeXExportFile, const std::string &sCmd, mu::varmap_type ¶msMap, FittingData &fitData, const std::vector< double > &vInitialVals, size_t nSize, const std::string &sFitAnalysis, const std::string &sFuncDisplay, const std::string &sFittedFunction, double dChisq)
static std::vector< double > evaluateFittingParams(FittingData &fitData, std::string &sCmd, Indices &_idx, std::string &sTeXExportFile, bool &bTeXExport, bool &bMaskDialog)
bool fitDataSet(string &sCmd, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option)
static int getDataForFit(const std::string &sCmd, std::string &sDimsForFitLog, FittingData &fitData)
static mu::varmap_type getFittingParameters(FittingData &fitData, const mu::varmap_type &varMap, const std::string &sCmd)
static std::string applyFitAlgorithm(Fitcontroller &_fControl, FittingData &fitData, mu::varmap_type ¶msMap, const std::string &sFuncDisplay, const std::string &sCmd)
static double calculatePercentageAvgAndCreateParserVariables(FittingData &fitData, mu::varmap_type ¶msMap, double dChisq)
static std::string getFitAnalysis(Fitcontroller &_fControl, FittingData &fitData, double dNormChisq, double dAverageErrorPercentage, bool noOverfitting)
static bool calculateChiMap(std::string sFunctionDefString, const std::string &sFuncDisplay, Indices &_idx, mu::varmap_type &varMap, mu::varmap_type ¶msMap, FittingData &fitData, std::vector< double > vInitialVals)
static std::string getFitOptionsTable(Fitcontroller &_fControl, FittingData &fitData, const std::string &sFuncDisplay, const std::string &sFittedFunction, const std::string &sDimsForFitLog, double dChisq, const mu::varmap_type ¶msMap, size_t nSize, bool forFitLog)
static void removeObsoleteParentheses(std::string &sFunction)
static std::string constructCovarianceMatrix(FittingData &fitData, size_t paramsMapSize, bool forFitLog)
static void calculateCovarianceData(FittingData &fitData, double dChisq, size_t paramsMapSize)
static std::string getParameterTable(FittingData &fitData, mu::varmap_type ¶msMap, const std::vector< double > &vInitialVals, size_t windowSize, const std::string &sPMSign, bool forFitLog)
std::string strfill(const std::string &sString, unsigned int nWidth, char cFill=' ', bool limit=false)
This function fills the passed string up to the width nWidth with the characters cFill....
unsigned int getMatchingParenthesis(const StringView &)
Returns the position of the closing parenthesis.
CONSTCD11 std::enable_if<!std::chrono::treat_as_floating_point< T >::value, T >::type trunc(T t) NOEXCEPT
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
MUP_BASETYPE value_type
The numeric datatype used by the parser.
bool isnan(const value_type &v)
bool isinf(const value_type &v)
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
value_type rint(value_type v)
bool evaluateIndices(const string &sCache, Indices &_idx, MemoryManager &_data)
This function will evaluate the passed indices, so that they match the dimensions of the passed cache...
void convertVectorToExpression(string &sLine, const Settings &_option)
This function replaces vector expressions with their corresponding multi- expression equation.
vector< double > readAndParseIntervals(string &sExpr, Parser &_parser, MemoryManager &_data, FunctionDefinitionManager &_functions, const Settings &_option, bool bEraseInterval)
This function will read the interval syntax in commands and return their values in a single vector.
void StripSpaces(std::string &)
Removes leading and trailing white spaces and tabulator characters.
int findParameter(const std::string &sCmd, const std::string &sParam, const char cFollowing)
This function searches the passed parameter in the passed command string. If something is found,...
std::string sRestrictions
std::vector< std::vector< double > > vz_w
std::vector< double > vy_w
std::vector< std::vector< double > > vz
std::string sChiMap_Vars[2]
This structure is central for managing the indices of a table or cluster read or write data access....
This class represents a set of intervals used together for calculations and simulations.
std::vector< Interval > intervals
std::string toString(int)
Converts an integer to a string without the Settings bloat.