18#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
19#include "TLinearFitter.h"
25#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
29 LOGP(info, fmt::runtime(getFormula().c_str()));
35 std::string formula = getFormula();
36 formula.replace(formula.find(
"p"), formula.find(
"]") + 1,
"1");
37 size_t pos = std::string::npos;
38 while ((
pos = formula.find(
"* p")) != std::string::npos) {
39 size_t end_pos = formula.find(
"]",
pos) + 2;
40 formula.erase(
pos, end_pos -
pos);
43 while ((
pos = formula.find(
" + ")) != std::string::npos) {
44 formula.replace(
pos + 1, 1,
"++");
51 std::string formula =
"";
53 const auto terms = getTerms();
54 for (int32_t
i = 0;
i < (int32_t)terms.size() - 1; ++
i) {
55 formula += fmt::format(
"{} + ", terms[
i]);
57 formula += terms.back();
64 std::vector<std::string> terms{
"par[0]"};
66 for (uint32_t deg = 1; deg <= mDegree; ++deg) {
67 const auto strTmp = combination_with_repetiton<std::vector<std::string>>(deg, mDim,
nullptr, indexPar,
nullptr, mInteractionOnly);
68 terms.insert(terms.end(), strTmp.begin(), strTmp.end());
75 const std::string formula = getTLinearFitterFormula();
76 TLinearFitter fitter(int32_t(mDim), formula.data(),
"");
85 const int32_t nDim =
static_cast<int32_t
>(
x.size() /
y.size());
86 fitter.AssignData(
static_cast<int32_t
>(
y.size()), nDim,
x.data(),
y.data(), error.empty() ? nullptr : error.data());
88 const int32_t status = fitter.Eval();
91 LOGP(info,
"Fitting failed with status: {}", status);
93 return std::vector<float>();
97 fitter.GetParameters(
params);
98 std::vector<float> paramsFloat;
99 paramsFloat.reserve(
static_cast<uint32_t
>(
params.GetNrows()));
100 std::copy(
params.GetMatrixArray(),
params.GetMatrixArray() +
params.GetNrows(), std::back_inserter(paramsFloat));
106 TLinearFitter fitter = getTLinearFitter();
107 return fit(fitter,
x,
y, error, clearPoints);
115 uint32_t
pos[FMaxdegree + 1]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
121 for (uint32_t
i = degree;
i > 0; --
i) {
127 for (uint32_t
j =
i;
j <= degree; ++
j) {
138 if (interactionOnly) {
139 bool checkInteraction =
false;
140 for (
size_t i = 1;
i < degree; ++
i) {
141 checkInteraction =
pos[
i] ==
pos[
i + 1];
142 if (checkInteraction) {
146 if (checkInteraction) {
152 if constexpr (std::is_same_v<Type, float>) {
153 float term = par[indexPar++];
154 for (
size_t i = 1;
i <= degree; ++
i) {
160 for (
size_t i = 1;
i <= degree; ++
i) {
161 term += fmt::format(
"x[{}] * ",
pos[
i]);
163 term += fmt::format(
"par[{}]", indexPar++);
164 val.emplace_back(term);
178 int32_t indexPar = 1;
179 for (uint32_t deg = 1; deg <= degree; ++deg) {
180 val += combination_with_repetiton<float>(deg, dim, par, indexPar,
x, interactionOnly);
GLenum const GLfloat * params
TFitResultPtr fit(const size_t nBins, const T *arr, const T xMin, const T xMax, TF1 &func, std::string_view option="")