13 #ifndef ROOT_Fit_FitUtil 14 #define ROOT_Fit_FitUtil 35 #define USE_PARAMCACHE 42 vecCore::Mask<T> Int2Mask(
unsigned i)
45 for (
unsigned j = 0; j < vecCore::VectorSize<T>(); j++)
46 vecCore::Set<T>(x, j, j);
47 return vecCore::Mask<T>(x <
T(i));
77 LikelihoodAux(
T logv = {},
T w = {},
T w2 = {}) : logvalue(logv), weight(w), weight2(w2) {}
100 LikelihoodAux(
double logv = 0.0,
double w = 0.0,
double w2 = 0.0) : logvalue(logv), weight(w), weight2(w2){};
127 template <
class ParamFunc = ROOT::Math::IParamMultiFunctionTempl<
double>>
132 : fDim(0), fParams(0), fFunc(0), fIg1Dim(0), fIgNDim(0), fFunc1Dim(0), fFuncNDim(0)
135 SetFunction(func, p);
157 fIg1Dim->SetFunction(static_cast<const ROOT::Math::IGenFunction &>(*fFunc1Dim));
158 }
else if (fDim > 1) {
161 const>(*
this, &IntegralEvaluator::FN, fDim);
163 fIgNDim->SetFunction(*fFuncNDim);
191 return ExecFunc(fFunc, &xx, fParams);
194 double FN(
const double *
x)
const {
return ExecFunc(fFunc, x, fParams); }
199 return (fIg1Dim) ? fIg1Dim->Integral(*x1, *x2) : fIgNDim->Integral(x1, x2);
206 double dV = *x2 - *
x1;
207 return fIg1Dim->Integral(*x1, *x2) / dV;
208 }
else if (fIgNDim) {
210 for (
unsigned int i = 0; i < fDim; ++i)
211 dV *= (x2[i] - x1[i]);
212 return fIgNDim->Integral(x1, x2) / dV;
222 inline double ExecFunc(
T *
f,
const double *
x,
const double *p)
const 227 #ifdef R__HAS_VECCORE 232 vecCore::Load<ROOT::Double_v>(xx,
x);
233 const double *p0 = p;
234 auto res = (*f)(&xx, (
const double *)p0);
235 return vecCore::Get<ROOT::Double_v>(res, 0);
237 std::vector<ROOT::Double_v> xx(fDim);
238 for (
unsigned int i = 0; i < fDim; ++i) {
239 vecCore::Load<ROOT::Double_v>(xx[i], x + i);
241 auto res = (*f)(xx.data(), p);
242 return vecCore::Get<ROOT::Double_v>(res, 0);
249 IntegralEvaluator &
operator=(
const IntegralEvaluator &rhs);
283 unsigned int &nPoints,
285 unsigned nChunks = 0);
299 unsigned int &nPoints,
301 unsigned nChunks = 0);
316 unsigned nChunks = 0);
323 unsigned int &nPoints,
325 unsigned nChunks = 0);
347 #ifdef R__HAS_VECCORE 348 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
354 auto fval = func(&
x, p);
356 return vecCore::Get<ROOT::Double_v>(logPdf, 0);
372 #ifdef R__HAS_VECCORE 383 unsigned int n = data.
Size();
387 #ifdef USE_PARAMCACHE 397 Error(
"FitUtil::EvaluateChi2",
"The vectorized implementation doesn't support Integrals, BinVolume or ExpErrors\n. Aborting operation.");
401 double maxResValue = std::numeric_limits<double>::max() /
n;
402 std::vector<double> ones{1, 1, 1, 1};
403 auto vecSize = vecCore::VectorSize<T>();
405 auto mapFunction = [&](
unsigned int i) {
407 T x1,
y, invErrorVec;
409 vecCore::Load<T>(
y, data.
ValuePtr(i * vecSize));
410 const auto invError = data.
ErrorPtr(i * vecSize);
411 auto invErrorptr = (invError !=
nullptr) ? invError : &ones.front();
412 vecCore::Load<T>(invErrorVec, invErrorptr);
416 if(data.
NDim() > 1) {
417 xc.resize(data.
NDim());
419 for (
unsigned int j = 1; j < data.
NDim(); ++j)
428 #ifdef USE_PARAMCACHE 435 T tmp = (y - fval) * invErrorVec;
440 auto m = vecCore::Mask_v<T>(chi2 > maxResValue);
442 vecCore::MaskedAssign<T>(chi2,
m, maxResValue);
447 auto redFunction = [](
const std::vector<T> &objs) {
448 return std::accumulate(objs.begin(), objs.end(),
T{});
456 Warning(
"FitUtil::EvaluateChi2",
"Multithread execution policy requires IMT, which is disabled. Changing " 457 "to ROOT::Fit::ExecutionPolicy::kSerial.");
473 Error(
"FitUtil::EvaluateChi2",
"Execution policy unknown. Avalaible choices:\n ROOT::Fit::ExecutionPolicy::kSerial (default)\n ROOT::Fit::ExecutionPolicy::kMultithread (requires IMT)\n");
478 if (data.
Size() % vecSize != 0)
479 vecCore::MaskedAssign(res, vecCore::Int2Mask<T>(data.
Size() % vecSize),
480 res + mapFunction(data.
Size() / vecSize));
482 return vecCore::ReduceAdd(res);
486 int iWeight,
bool extended,
unsigned int &nPoints,
490 unsigned int n = data.
Size();
493 bool normalizeFunc =
false;
496 #ifdef USE_PARAMCACHE 503 if (!normalizeFunc) {
504 if (data.
NDim() == 1) {
510 std::vector<T>
x(data.
NDim());
511 for (
unsigned int j = 0; j < data.
NDim(); ++j)
522 std::vector<double>
xmin(data.
NDim());
523 std::vector<double>
xmax(data.
NDim());
528 for (
unsigned int ir = 0; ir < data.
Range().
Size(); ++ir) {
530 norm += igEval.Integral(
xmin.data(),
xmax.data());
537 vecCore::Load<T>(xmin_v,
xmin.data());
538 vecCore::Load<T>(xmax_v,
xmax.data());
539 if (vecCore::ReduceAdd(func(&xmin_v, p)) != 0 || vecCore::ReduceAdd(func(&xmax_v, p)) != 0) {
540 MATH_ERROR_MSG(
"FitUtil::EvaluateLogLikelihood",
"A range has not been set and the function is not zero at +/- inf");
543 norm = igEval.Integral(&
xmin[0], &
xmax[0]);
549 auto vecSize = vecCore::VectorSize<T>();
550 unsigned int numVectors = n / vecSize;
552 auto mapFunction = [ &, p](
const unsigned i) {
561 const T *
x =
nullptr;
562 unsigned int ndim = data.
NDim();
567 for (
unsigned int j = 1; j < ndim; ++j)
574 #ifdef USE_PARAMCACHE 581 if (i < 5 || (i > numVectors-5) ) {
582 if (ndim == 1) std::cout << i <<
" x " << x[0] <<
" fval = " << fval;
583 else std::cout << i <<
" x " << x[0] <<
" y " << x[1] <<
" fval = " << fval;
587 if (normalizeFunc) fval = fval * (1 / norm);
596 vecCore::Load<T>(weight, data.
WeightsPtr(i*vecSize));
603 W2 = weight * weight;
608 if (i < 5 || (i > numVectors-5) ) {
609 std::cout <<
" " << fval <<
" logfval " << logval << std::endl;
617 auto redFunction = [](
const std::vector<LikelihoodAux<T>> &objs) {
629 Warning(
"FitUtil::EvaluateLogL",
"Multithread execution policy requires IMT, which is disabled. Changing " 630 "to ROOT::Fit::ExecutionPolicy::kSerial.");
649 Error(
"FitUtil::EvaluateLogL",
"Execution policy unknown. Avalaible choices:\n ROOT::Fit::ExecutionPolicy::kSerial (default)\n ROOT::Fit::ExecutionPolicy::kMultithread (requires IMT)\n");
657 unsigned int remainingPoints = n % vecSize;
658 if (remainingPoints > 0) {
659 auto remainingPointsContribution = mapFunction(numVectors);
661 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
662 vecCore::MaskedAssign(logl_v, remainingMask, logl_v + remainingPointsContribution.logvalue);
663 vecCore::MaskedAssign(sumW_v, remainingMask, sumW_v + remainingPointsContribution.weight);
664 vecCore::MaskedAssign(sumW2_v, remainingMask, sumW2_v + remainingPointsContribution.weight2);
673 for (
unsigned vIt = 0; vIt < vecSize; vIt++) {
676 sumW2 += sumW2_v[vIt];
681 double extendedTerm = 0;
685 if (!normalizeFunc) {
687 std::vector<double>
xmin(data.
NDim());
688 std::vector<double>
xmax(data.
NDim());
693 for (
unsigned int ir = 0; ir < data.
Range().
Size(); ++ir) {
702 vecCore::Load<T>(xmin_v,
xmin.data());
703 vecCore::Load<T>(xmax_v,
xmax.data());
704 if (vecCore::ReduceAdd(func(&xmin_v, p)) != 0 || vecCore::ReduceAdd(func(&xmax_v, p)) != 0) {
705 MATH_ERROR_MSG(
"FitUtil::EvaluateLogLikelihood",
"A range has not been set and the function is not zero at +/- inf");
714 extendedTerm = - nuTot;
718 extendedTerm = - (sumW2 / sumW) * nuTot;
727 logl += extendedTerm;
731 std::cout <<
"Evaluated log L for parameters (";
732 for (
unsigned int ip = 0; ip < func.
NPar(); ++ip)
733 std::cout <<
" " << p[ip];
734 std::cout <<
") nll = " << -logl << std::endl;
746 int iWeight,
bool extended,
unsigned int,
764 #ifdef USE_PARAMCACHE 767 auto vecSize = vecCore::VectorSize<T>();
770 if (fitOpt.fExpErrors || fitOpt.fIntegral)
771 Error(
"FitUtil::EvaluateChi2",
772 "The vectorized implementation doesn't support Integrals or BinVolume\n. Aborting operation.");
773 bool useW2 = (iWeight == 2);
775 auto mapFunction = [&](
unsigned int i) {
777 vecCore::Load<T>(
y, data.
ValuePtr(i * vecSize));
780 if (data.
NDim() > 1) {
781 std::vector<T>
x(data.
NDim());
782 for (
unsigned int j = 0; j < data.
NDim(); ++j)
784 #ifdef USE_PARAMCACHE 785 fval = func(
x.data());
787 fval = func(
x.data(), p);
793 #ifdef USE_PARAMCACHE 802 vecCore::MaskedAssign<T>(fval, fval < 0.0, 0.0);
812 assert (data.
GetErrorType() != ROOT::Fit::BinData::ErrorType::kNoError);
814 vecCore::Load<T>(error, data.
ErrorPtr(i * vecSize));
816 auto m = vecCore::Mask_v<T>(y != 0.0);
819 nloglike = weight * ( fval -
y);
828 if (extended) nloglike = fval -
y;
830 vecCore::MaskedAssign<T>(
838 auto redFunction = [](
const std::vector<T> &objs) {
return std::accumulate(objs.begin(), objs.end(),
T{}); };
844 Warning(
"FitUtil::Evaluate<T>::EvalPoissonLogL",
845 "Multithread execution policy requires IMT, which is disabled. Changing " 846 "to ROOT::Fit::ExecutionPolicy::kSerial.");
853 for (
unsigned int i = 0; i < (data.
Size() / vecSize); i++) {
854 res += mapFunction(i);
864 "FitUtil::Evaluate<T>::EvalPoissonLogL",
865 "Execution policy unknown. Avalaible choices:\n ROOT::Fit::ExecutionPolicy::kSerial (default)\n ROOT::Fit::ExecutionPolicy::kMultithread (requires IMT)\n");
869 if (data.
Size() % vecSize != 0)
870 vecCore::MaskedAssign(res, vecCore::Int2Mask<T>(data.
Size() % vecSize),
871 res + mapFunction(data.
Size() / vecSize));
873 return vecCore::ReduceAdd(res);
878 Error(
"FitUtil::Evaluate<T>::EvalChi2Effective",
"The vectorized evaluation of the Chi2 with coordinate errors is still not supported");
885 static vecCore::Mask<T> CheckInfNaNValues(
T &rval)
899 unsigned int &nPoints,
901 unsigned nChunks = 0)
911 "Error on the coordinates are not used in calculating Chi2 gradient");
916 assert(fg !=
nullptr);
922 Error(
"FitUtil::EvaluateChi2Gradient",
"The vectorized implementation doesn't support Integrals," 923 "BinVolume or ExpErrors\n. Aborting operation.");
925 unsigned int npar = func.
NPar();
926 auto vecSize = vecCore::VectorSize<T>();
927 unsigned initialNPoints = data.
Size();
928 unsigned numVectors = initialNPoints / vecSize;
931 std::vector<vecCore::Mask<T>> validPointsMasks(numVectors + 1);
933 auto mapFunction = [&](
const unsigned int i) {
935 std::vector<T> gradFunc(npar);
936 std::vector<T> pointContributionVec(npar);
941 vecCore::Load<T>(
y, data.
ValuePtr(i * vecSize));
942 const auto invErrorPtr = data.
ErrorPtr(i * vecSize);
944 if (invErrorPtr ==
nullptr)
947 vecCore::Load<T>(invError, invErrorPtr);
953 const T *
x =
nullptr;
955 unsigned int ndim = data.
NDim();
962 for (
unsigned int j = 1; j < ndim; ++j)
972 validPointsMasks[i] = CheckInfNaNValues(fval);
973 if (vecCore::MaskEmpty(validPointsMasks[i])) {
975 return pointContributionVec;
979 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
982 validPointsMasks[i] = CheckInfNaNValues(gradFunc[ipar]);
984 if (vecCore::MaskEmpty(validPointsMasks[i])) {
989 vecCore::MaskedAssign(pointContributionVec[ipar], validPointsMasks[i],
990 -2.0 * (y - fval) * invError * invError * gradFunc[ipar]);
993 return pointContributionVec;
997 auto redFunction = [&](
const std::vector<std::vector<T>> &partialResults) {
998 std::vector<T> result(npar);
1000 for (
auto const &pointContributionVec : partialResults) {
1001 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
1002 result[parameterIndex] += pointContributionVec[parameterIndex];
1008 std::vector<T> gVec(npar);
1009 std::vector<double>
g(npar);
1017 Warning(
"FitUtil::EvaluateChi2Gradient",
1018 "Multithread execution policy requires IMT, which is disabled. Changing " 1019 "to ROOT::Fit::ExecutionPolicy::kSerial.");
1037 "FitUtil::EvaluateChi2Gradient",
1038 "Execution policy unknown. Avalaible choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
1042 unsigned int remainingPoints = initialNPoints % vecSize;
1043 if (remainingPoints > 0) {
1044 auto remainingPointsContribution = mapFunction(numVectors);
1046 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
1047 for (
unsigned int param = 0; param < npar; param++) {
1048 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1052 for (
unsigned int param = 0; param < npar; param++) {
1053 grad[param] = vecCore::ReduceAdd(gVec[param]);
1057 nPoints = initialNPoints;
1059 if (std::any_of(validPointsMasks.begin(), validPointsMasks.end(),
1060 [](vecCore::Mask<T> validPoints) {
return !vecCore::MaskFull(validPoints); })) {
1061 unsigned nRejected = 0;
1063 for (
const auto &mask : validPointsMasks) {
1064 for (
unsigned int i = 0; i < vecSize; i++) {
1065 nRejected += !vecCore::Get(mask, i);
1069 assert(nRejected <= initialNPoints);
1070 nPoints = initialNPoints - nRejected;
1072 if (nPoints < npar) {
1074 "Too many points rejected for overflow in gradient calculation");
1081 Error(
"FitUtil::Evaluate<T>::EvalChi2Residual",
"The vectorized evaluation of the Chi2 with the ith residual is still not supported");
1088 Error(
"FitUtil::Evaluate<T>::EvaluatePoissonBinPdf",
"The vectorized evaluation of the BinnedLikelihood fit evaluated point by point is still not supported");
1096 unsigned nChunks = 0)
1101 assert(fg !=
nullptr);
1110 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"The vectorized implementation doesn't support Integrals," 1111 "BinVolume or ExpErrors\n. Aborting operation.");
1113 unsigned int npar = func.
NPar();
1114 auto vecSize = vecCore::VectorSize<T>();
1115 unsigned initialNPoints = data.
Size();
1116 unsigned numVectors = initialNPoints / vecSize;
1118 auto mapFunction = [&](
const unsigned int i) {
1120 std::vector<T> gradFunc(npar);
1121 std::vector<T> pointContributionVec(npar);
1126 vecCore::Load<T>(
y, data.
ValuePtr(i * vecSize));
1130 const T *
x =
nullptr;
1132 unsigned ndim = data.
NDim();
1137 for (
unsigned int j = 1; j < ndim; ++j)
1148 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
1149 vecCore::Mask<T> positiveValuesMask = fval > 0;
1152 vecCore::MaskedAssign(pointContributionVec[ipar], positiveValuesMask, gradFunc[ipar] * (1. - y / fval));
1154 vecCore::Mask<T> validNegativeValuesMask = !positiveValuesMask && gradFunc[ipar] != 0;
1156 if (!vecCore::MaskEmpty(validNegativeValuesMask)) {
1159 T gg = kdmax1 * gradFunc[ipar];
1164 #ifdef DEBUG_FITUTIL 1167 if (i < 5 || (i > data.
Size()-5) ) {
1168 if (data.
NDim() > 1) std::cout << i <<
" x " << x[0] <<
" y " << x[1];
1169 else std::cout << i <<
" x " << x[0];
1170 std::cout <<
" func " << fval <<
" gradient ";
1171 for (
unsigned int ii = 0; ii < npar; ++ii) std::cout <<
" " << pointContributionVec[ii];
1177 return pointContributionVec;
1181 auto redFunction = [&](
const std::vector<std::vector<T>> &partialResults) {
1182 std::vector<T> result(npar);
1184 for (
auto const &pointContributionVec : partialResults) {
1185 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
1186 result[parameterIndex] += pointContributionVec[parameterIndex];
1192 std::vector<T> gVec(npar);
1200 Warning(
"FitUtil::EvaluatePoissonLogLGradient",
1201 "Multithread execution policy requires IMT, which is disabled. Changing " 1202 "to ROOT::Fit::ExecutionPolicy::kSerial.");
1219 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"Execution policy unknown. Avalaible choices:\n " 1220 "ROOT::Fit::ExecutionPolicy::kSerial (default)\n " 1221 "ROOT::Fit::ExecutionPolicy::kMultithread (requires IMT)\n");
1226 unsigned int remainingPoints = initialNPoints % vecSize;
1227 if (remainingPoints > 0) {
1228 auto remainingPointsContribution = mapFunction(numVectors);
1230 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
1231 for (
unsigned int param = 0; param < npar; param++) {
1232 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1236 for (
unsigned int param = 0; param < npar; param++) {
1237 grad[param] = vecCore::ReduceAdd(gVec[param]);
1240 #ifdef DEBUG_FITUTIL 1241 std::cout <<
"***** Final gradient : ";
1242 for (
unsigned int ii = 0; ii< npar; ++ii) std::cout << grad[ii] <<
" ";
1249 double *grad,
unsigned int &,
1251 unsigned nChunks = 0)
1256 assert(fg !=
nullptr);
1261 unsigned int npar = func.
NPar();
1262 auto vecSize = vecCore::VectorSize<T>();
1263 unsigned initialNPoints = data.
Size();
1264 unsigned numVectors = initialNPoints / vecSize;
1266 #ifdef DEBUG_FITUTIL 1267 std::cout <<
"\n===> Evaluate Gradient for parameters ";
1268 for (
unsigned int ip = 0; ip < npar; ++ip)
1269 std::cout <<
" " << p[ip];
1278 auto mapFunction = [&](
const unsigned int i) {
1279 std::vector<T> gradFunc(npar);
1280 std::vector<T> pointContributionVec(npar);
1285 const T *
x =
nullptr;
1287 unsigned int ndim = data.
NDim();
1288 std::vector<T> xc(ndim);
1292 for (
unsigned int j = 1; j < ndim; ++j)
1300 T fval = func(x, p);
1303 #ifdef DEBUG_FITUTIL 1304 if (i < 5 || (i > numVectors-5) ) {
1305 if (ndim > 1) std::cout << i <<
" x " << x[0] <<
" y " << x[1] <<
" gradient " << gradFunc[0] <<
" " << gradFunc[1] <<
" " << gradFunc[3] << std::endl;
1306 else std::cout << i <<
" x " << x[0] <<
" gradient " << gradFunc[0] <<
" " << gradFunc[1] <<
" " << gradFunc[3] << std::endl;
1310 vecCore::Mask<T> positiveValues = fval > 0;
1312 for (
unsigned int kpar = 0; kpar < npar; ++kpar) {
1313 if (!vecCore::MaskEmpty(positiveValues))
1314 vecCore::MaskedAssign<T>(pointContributionVec[kpar], positiveValues, -1. / fval * gradFunc[kpar]);
1316 vecCore::Mask<T> nonZeroGradientValues = !positiveValues && gradFunc[kpar] != 0;
1317 if (!vecCore::MaskEmpty(nonZeroGradientValues)) {
1318 T gg = kdmax1 * gradFunc[kpar];
1319 pointContributionVec[kpar] =
1326 return pointContributionVec;
1330 auto redFunction = [&](
const std::vector<std::vector<T>> &pointContributions) {
1331 std::vector<T> result(npar);
1333 for (
auto const &pointContributionVec : pointContributions) {
1334 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
1335 result[parameterIndex] += pointContributionVec[parameterIndex];
1341 std::vector<T> gVec(npar);
1342 std::vector<double>
g(npar);
1350 Warning(
"FitUtil::EvaluateLogLGradient",
1351 "Multithread execution policy requires IMT, which is disabled. Changing " 1352 "to ROOT::Fit::ExecutionPolicy::kSerial.");
1369 Error(
"FitUtil::EvaluateLogLGradient",
"Execution policy unknown. Avalaible choices:\n " 1370 "ROOT::Fit::ExecutionPolicy::kSerial (default)\n " 1371 "ROOT::Fit::ExecutionPolicy::kMultithread (requires IMT)\n");
1375 unsigned int remainingPoints = initialNPoints % vecSize;
1376 if (remainingPoints > 0) {
1377 auto remainingPointsContribution = mapFunction(numVectors);
1379 auto remainingMask = vecCore::Int2Mask<T>(initialNPoints % vecSize);
1380 for (
unsigned int param = 0; param < npar; param++) {
1381 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1385 for (
unsigned int param = 0; param < npar; param++) {
1386 grad[param] = vecCore::ReduceAdd(gVec[param]);
1389 #ifdef DEBUG_FITUTIL 1390 std::cout <<
"Final gradient ";
1391 for (
unsigned int param = 0; param < npar; param++) {
1392 std::cout <<
" " << grad[param];
1403 static double EvalChi2(
const IModelFunction &func,
const BinData &data,
const double *p,
unsigned int &nPoints,
1418 int iWeight,
bool extended,
unsigned int &nPoints,
1425 int iWeight,
bool extended,
unsigned int &nPoints,
1436 double *
g,
unsigned int &nPoints,
1438 unsigned nChunks = 0)
1455 unsigned int &nPoints,
1457 unsigned nChunks = 0)
1463 double *
g,
unsigned int &nPoints,
1465 unsigned nChunks = 0)
1477 #if defined (R__HAS_VECCORE) && defined(R__HAS_VC) LikelihoodAux & operator+=(const LikelihoodAux &l)
void SetFunction(const ParamFunc &func, const double *p=0)
static double EvalChi2Residual(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, unsigned int i, double *g=0)
ROOT::Math::IntegratorOneDim * fIg1Dim
LikelihoodAux operator+(const LikelihoodAux &l) const
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
void SetParameters(const double *p)
unsigned int NDim() const
return coordinate data dimension
double ExecFunc(T *f, const double *x, const double *p) const
Namespace for new ROOT classes and functions.
double EvaluateChi2(const IModelFunction &func, const BinData &data, const double *x, unsigned int &nPoints, ROOT::Fit::ExecutionPolicy executionPolicy, unsigned nChunks=0)
Chi2 Functions.
void EvaluateLogLGradient(const IModelFunction &func, const UnBinData &data, const double *x, double *grad, unsigned int &nPoints, ROOT::Fit::ExecutionPolicy executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial, unsigned nChunks=0)
evaluate the LogL gradient given a model function and the data at the point x.
static double EvalChi2(const IModelFunction &func, const BinData &data, const double *p, unsigned int &nPoints, ::ROOT::Fit::ExecutionPolicy executionPolicy, unsigned nChunks=0)
double EvaluatePoissonBinPdf(const IModelFunction &func, const BinData &data, const double *x, unsigned int ipoint, double *g=0)
evaluate the pdf contribution to the Poisson LogL given a model function and the BinPoint data...
ROOT::Math::IMultiGenFunction * fFuncNDim
ErrorType GetErrorType() const
retrieve the errortype
auto MapReduce(F func, unsigned nTimes, R redfunc) -> typename std::result_of< F()>::type
const double * ValuePtr(unsigned int ipoint) const
return a pointer to the value for the given fit point
unsigned setAutomaticChunking(unsigned nEvents)
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
Short_t Min(Short_t a, Short_t b)
Interface (abstract class) for parametric gradient multi-dimensional functions providing in addition ...
R__EXTERN TVirtualMutex * gROOTMutex
ROOT::Math::IParamMultiGradFunction IGradModelFunction
ROOT::Math::IntegratorMultiDim * fIgNDim
static double EvalPoissonBinPdf(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, unsigned int i, double *g)
evaluate the pdf (Poisson) contribution to the logl (return actually log of pdf) and its gradient ...
double SumOfError2() const
compute the total sum of the error square (sum of weight square in case of a weighted data set) ...
LikelihoodAux(double logv=0.0, double w=0.0, double w2=0.0)
static void EvalPoissonLogLGradient(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, double *g, unsigned int &nPoints, ::ROOT::Fit::ExecutionPolicy executionPolicy=::ROOT::Fit::ExecutionPolicy::kSerial, unsigned nChunks=0)
static const double x2[5]
void GetRange(unsigned int irange, unsigned int icoord, double &xmin, double &xmax) const
get the i-th range for given coordinate.
const double * GetCoordComponent(unsigned int ipoint, unsigned int icoord) const
returns a single coordinate component of a point.
void EvaluatePoissonLogLGradient(const IModelFunction &func, const BinData &data, const double *x, double *grad, unsigned int &nPoints, ROOT::Fit::ExecutionPolicy executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial, unsigned nChunks=0)
evaluate the Poisson LogL given a model function and the data at the point x.
static void EvalLogLGradient(const IModelFunctionTempl< double > &func, const UnBinData &data, const double *p, double *g, unsigned int &nPoints, ::ROOT::Fit::ExecutionPolicy executionPolicy=::ROOT::Fit::ExecutionPolicy::kSerial, unsigned nChunks=0)
static double EvalPoissonLogL(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, ::ROOT::Fit::ExecutionPolicy executionPolicy, unsigned nChunks=0)
double EvaluatePoissonLogL(const IModelFunction &func, const BinData &data, const double *x, int iWeight, bool extended, unsigned int &nPoints, ROOT::Fit::ExecutionPolicy executionPolicy, unsigned nChunks=0)
evaluate the Poisson LogL given a model function and the data at the point x.
double FN(const double *x) const
unsigned int Size() const
return number of fit points
#define MATH_ERROR_MSG(loc, str)
void Error(const char *location, const char *msgfmt,...)
T EvalLog(T x)
safe evaluation of log(x) with a protections against negative or zero argument to the log smooth line...
Documentation for the abstract class IBaseFunctionMultiDim.
void EvaluateChi2Gradient(const IModelFunction &func, const BinData &data, const double *x, double *grad, unsigned int &nPoints, ROOT::Fit::ExecutionPolicy executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial, unsigned nChunks=0)
evaluate the Chi2 gradient given a model function and the data at the point x.
This class provides a simple interface to execute the same task multiple times in parallel...
virtual unsigned int NPar() const =0
Return the number of Parameters.
Double_t Sqrt(Double_t x)
DataOptions : simple structure holding the options on how the data are filled.
double EvaluateChi2Effective(const IModelFunction &func, const BinData &data, const double *x, unsigned int &nPoints)
evaluate the effective Chi2 given a model function and the data at the point x.
LikelihoodAux & operator+=(const LikelihoodAux &l)
unsigned int Size(unsigned int icoord=0) const
return range size for coordinate icoord (starts from zero) Size == 0 indicates no range is present [-...
double EvaluateChi2Residual(const IModelFunction &func, const BinData &data, const double *x, unsigned int ipoint, double *g=0)
evaluate the residual contribution to the Chi2 given a model function and the BinPoint data and if th...
IntegralEvaluator(const ParamFunc &func, const double *p, bool useIntegral=true)
User Class for performing numerical integration of a function in one dimension.
LikelihoodAux operator+(const LikelihoodAux &l) const
const DataOptions & Opt() const
access to options
virtual void ParameterGradient(const T *x, const double *p, T *grad) const
Evaluate the all the derivatives (gradient vector) of the function with respect to the parameters at ...
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
bool HaveCoordErrors() const
flag to control if data provides error on the coordinates
void Warning(const char *location, const char *msgfmt,...)
ROOT::Math::IParamMultiFunction IModelFunction
ROOT::Math::IGenFunction * fFunc1Dim
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
virtual void SetParameters(const double *p)=0
Set the parameter values.
const double * ErrorPtr(unsigned int ipoint) const
return error on the value for the given fit point Safe (but slower) method returning correctly the er...
static const double x1[5]
A pseudo container class which is a generator of indices.
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
double F1(double x) const
double EvaluatePdf(const IModelFunction &func, const UnBinData &data, const double *x, unsigned int ipoint, double *g=0)
evaluate the pdf contribution to the LogL given a model function and the BinPoint data...
static double EvalChi2Effective(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, unsigned int &nPoints)
#define R__LOCKGUARD(mutex)
double EvaluateLogL(const IModelFunction &func, const UnBinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, ROOT::Fit::ExecutionPolicy executionPolicy, unsigned nChunks=0)
evaluate the LogL given a model function and the data at the point x.
Binding & operator=(OUT(*fun)(void))
double SumOfContent() const
compute the total sum of the data content (sum of weights in case of weighted data set) ...
LikelihoodAux(T logv={}, T w={}, T w2={})
typedef void((*Func_t)())
auto MapReduce(F func, unsigned nTimes, R redfunc) -> typename std::result_of< F()>::type
This method behaves just like Map, but an additional redfunc function must be provided.
User class for performing multidimensional integration.
Short_t Max(Short_t a, Short_t b)
unsigned int NDim() const
return coordinate data dimension
const DataRange & Range() const
access to range
double Integral(const double *x1, const double *x2)
static void EvalChi2Gradient(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, double *g, unsigned int &nPoints, ::ROOT::Fit::ExecutionPolicy executionPolicy=::ROOT::Fit::ExecutionPolicy::kSerial, unsigned nChunks=0)
Template class to wrap any member function of a class taking a double and returning a double in a 1D ...
double operator()(const double *x1, const double *x2)
static double EvalLogL(const IModelFunctionTempl< double > &func, const UnBinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, ::ROOT::Fit::ExecutionPolicy executionPolicy, unsigned nChunks=0)
const double * WeightsPtr(unsigned int ipoint) const