13#ifndef ROOT_Fit_FitUtil
14#define ROOT_Fit_FitUtil
42vecCore::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));
127 template <
class ParamFunc = ROOT::Math::IParamMultiFunctionTempl<
double>>
150 assert(
fFunc !=
nullptr);
160 }
else if (
fDim > 1) {
208 double dV = *
x2 - *
x1;
212 for (
unsigned int i = 0; i <
fDim; ++i)
213 dV *= (
x2[i] -
x1[i]);
224 inline double ExecFunc(T *
f,
const double *
x,
const double *
p)
const
233 constexpr static int vecSize =
sizeof(
ROOT::Double_v) /
sizeof(
double);
234 double xBuffer[vecSize];
236 for (
unsigned int i = 0; i <
fDim; ++i) {
242 for(
int j = 1; j < vecSize; ++j) {
245 vecCore::Load<ROOT::Double_v>(xx[i], xBuffer);
247 auto res = (*f)(xx,
p);
248 return vecCore::Get<ROOT::Double_v>(res, 0);
288 unsigned int &nPoints,
290 unsigned nChunks = 0);
304 unsigned int &nPoints,
306 unsigned nChunks = 0);
321 unsigned nChunks = 0);
328 unsigned int &nPoints,
330 unsigned nChunks = 0);
341 double *
g =
nullptr,
double *
h =
nullptr,
bool hasGrad =
false,
bool fullHessian =
false);
376 unsigned int n =
data.Size();
377 nPoints =
data.Size();
390 Error(
"FitUtil::EvaluateChi2",
"The vectorized implementation doesn't support Integrals, BinVolume or ExpErrors\n. Aborting operation.");
394 double maxResValue = std::numeric_limits<double>::max() /
n;
395 std::vector<double> ones{1., 1., 1., 1.};
396 auto vecSize = vecCore::VectorSize<T>();
398 auto mapFunction = [&](
unsigned int i) {
400 T
x1,
y, invErrorVec;
401 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
402 vecCore::Load<T>(
y,
data.ValuePtr(i * vecSize));
403 const auto invError =
data.ErrorPtr(i * vecSize);
404 auto invErrorptr = (invError !=
nullptr) ? invError : &ones.front();
405 vecCore::Load<T>(invErrorVec, invErrorptr);
409 if(
data.NDim() > 1) {
410 xc.resize(
data.NDim());
412 for (
unsigned int j = 1; j <
data.NDim(); ++j)
413 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
427 T tmp = (
y - fval) * invErrorVec;
432 auto m = vecCore::Mask_v<T>(chi2 > maxResValue);
434 vecCore::MaskedAssign<T>(chi2,
m, maxResValue);
439 auto redFunction = [](
const std::vector<T> &objs) {
440 return std::accumulate(objs.begin(), objs.end(), T{});
448 Warning(
"FitUtil::EvaluateChi2",
"Multithread execution policy requires IMT, which is disabled. Changing "
449 "to ::ROOT::EExecutionPolicy::kSequential.");
465 Error(
"FitUtil::EvaluateChi2",
"Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n ::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
469 if (
data.Size() % vecSize != 0)
470 vecCore::MaskedAssign(res, vecCore::Int2Mask<T>(
data.Size() % vecSize),
471 res + mapFunction(
data.Size() / vecSize));
473 return vecCore::ReduceAdd(res);
477 int iWeight,
bool extended,
unsigned int &nPoints,
481 unsigned int n =
data.Size();
482 nPoints =
data.Size();
485 bool normalizeFunc =
false;
495 if (!normalizeFunc) {
496 if (
data.NDim() == 1) {
498 vecCore::Load<T>(
x,
data.GetCoordComponent(0, 0));
502 std::vector<T>
x(
data.NDim());
503 for (
unsigned int j = 0; j <
data.NDim(); ++j)
504 vecCore::Load<T>(
x[j],
data.GetCoordComponent(0, j));
514 std::vector<double>
xmin(
data.NDim());
515 std::vector<double>
xmax(
data.NDim());
518 if (
data.Range().Size() > 0) {
520 for (
unsigned int ir = 0; ir <
data.Range().Size(); ++ir) {
529 vecCore::Load<T>(xmin_v,
xmin.data());
530 vecCore::Load<T>(xmax_v,
xmax.data());
531 if (vecCore::ReduceAdd(func(&xmin_v,
p)) != 0 || vecCore::ReduceAdd(func(&xmax_v,
p)) != 0) {
532 MATH_ERROR_MSG(
"FitUtil::EvaluateLogLikelihood",
"A range has not been set and the function is not zero at +/- inf");
541 auto vecSize = vecCore::VectorSize<T>();
542 unsigned int numVectors =
n / vecSize;
544 auto mapFunction = [ &,
p](
const unsigned i) {
552 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
553 const T *
x =
nullptr;
554 unsigned int ndim =
data.NDim();
559 for (
unsigned int j = 1; j < ndim; ++j)
560 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
573 if (i < 5 || (i > numVectors-5) ) {
574 if (ndim == 1) std::cout << i <<
" x " <<
x[0] <<
" fval = " << fval;
575 else std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" fval = " << fval;
579 if (normalizeFunc) fval = fval * (1 / norm);
585 if (
data.WeightsPtr(i) ==
nullptr)
588 vecCore::Load<T>(weight,
data.WeightsPtr(i*vecSize));
595 W2 = weight * weight;
600 if (i < 5 || (i > numVectors-5)) {
601 std::cout <<
" " << fval <<
" logfval " << logval << std::endl;
608 auto redFunction = [](
const std::vector<LikelihoodAux<T>> &objs) {
620 Warning(
"FitUtil::EvaluateLogL",
"Multithread execution policy requires IMT, which is disabled. Changing "
621 "to ::ROOT::EExecutionPolicy::kSequential.");
640 Error(
"FitUtil::EvaluateLogL",
"Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n ::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
648 unsigned int remainingPoints =
n % vecSize;
649 if (remainingPoints > 0) {
650 auto remainingPointsContribution = mapFunction(numVectors);
652 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
653 vecCore::MaskedAssign(logl_v, remainingMask, logl_v + remainingPointsContribution.logvalue);
654 vecCore::MaskedAssign(sumW_v, remainingMask, sumW_v + remainingPointsContribution.weight);
655 vecCore::MaskedAssign(sumW2_v, remainingMask, sumW2_v + remainingPointsContribution.weight2);
660 double logl = vecCore::ReduceAdd(logl_v);
661 double sumW = vecCore::ReduceAdd(sumW_v);
662 double sumW2 = vecCore::ReduceAdd(sumW2_v);
666 double extendedTerm = 0;
670 if (!normalizeFunc) {
672 std::vector<double>
xmin(
data.NDim());
673 std::vector<double>
xmax(
data.NDim());
676 if (
data.Range().Size() > 0) {
678 for (
unsigned int ir = 0; ir <
data.Range().Size(); ++ir) {
687 vecCore::Load<T>(xmin_v,
xmin.data());
688 vecCore::Load<T>(xmax_v,
xmax.data());
689 if (vecCore::ReduceAdd(func(&xmin_v,
p)) != 0 || vecCore::ReduceAdd(func(&xmax_v,
p)) != 0) {
690 MATH_ERROR_MSG(
"FitUtil::EvaluateLogLikelihood",
"A range has not been set and the function is not zero at +/- inf");
699 extendedTerm = - nuTot;
703 extendedTerm = - (sumW2 / sumW) * nuTot;
712 logl += extendedTerm;
716 std::cout <<
"Evaluated log L for parameters (";
717 for (
unsigned int ip = 0; ip < func.
NPar(); ++ip)
718 std::cout <<
" " <<
p[ip];
719 std::cout <<
") nll = " << -logl << std::endl;
727 int iWeight,
bool extended,
unsigned int,
748 auto vecSize = vecCore::VectorSize<T>();
752 Error(
"FitUtil::EvaluateChi2",
753 "The vectorized implementation doesn't support Integrals or BinVolume\n. Aborting operation.");
754 bool useW2 = (iWeight == 2);
756 auto mapFunction = [&](
unsigned int i) {
758 vecCore::Load<T>(
y,
data.ValuePtr(i * vecSize));
761 if (
data.NDim() > 1) {
762 std::vector<T>
x(
data.NDim());
763 for (
unsigned int j = 0; j <
data.NDim(); ++j)
764 vecCore::Load<T>(
x[j],
data.GetCoordComponent(i * vecSize, j));
766 fval = func(
x.data());
768 fval = func(
x.data(),
p);
773 vecCore::Load<T>(
x,
data.GetCoordComponent(i * vecSize, 0));
783 vecCore::MaskedAssign<T>(fval, fval < 0.0, 0.0);
795 vecCore::Load<T>(error,
data.ErrorPtr(i * vecSize));
797 auto m = vecCore::Mask_v<T>(
y != 0.0);
798 auto weight = vecCore::Blend(
m,(error * error) /
y, T(
data.SumOfError2()/
data.SumOfContent()) );
800 nloglike = weight * ( fval -
y);
809 if (extended) nloglike = fval -
y;
811 vecCore::MaskedAssign<T>(
819 auto redFunction = [](
const std::vector<T> &objs) {
return std::accumulate(objs.begin(), objs.end(), T{}); };
825 Warning(
"FitUtil::Evaluate<T>::EvalPoissonLogL",
826 "Multithread execution policy requires IMT, which is disabled. Changing "
827 "to ::ROOT::EExecutionPolicy::kSequential.");
834 for (
unsigned int i = 0; i < (
data.Size() / vecSize); i++) {
835 res += mapFunction(i);
845 "FitUtil::Evaluate<T>::EvalPoissonLogL",
846 "Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n ::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
850 if (
data.Size() % vecSize != 0)
851 vecCore::MaskedAssign(res, vecCore::Int2Mask<T>(
data.Size() % vecSize),
852 res + mapFunction(
data.Size() / vecSize));
854 return vecCore::ReduceAdd(res);
859 Error(
"FitUtil::Evaluate<T>::EvalChi2Effective",
"The vectorized evaluation of the Chi2 with coordinate errors is still not supported");
866 static vecCore::Mask<T> CheckInfNaNValues(T &rval)
868 auto mask = rval > -vecCore::NumericLimits<T>::Max() && rval < vecCore::NumericLimits<T>::Max();
871 vecCore::MaskedAssign(rval, !
mask, +vecCore::NumericLimits<T>::Max());
874 vecCore::MaskedAssign(rval, !
mask && rval < 0, -vecCore::NumericLimits<T>::Max());
880 unsigned int &nPoints,
882 unsigned nChunks = 0)
890 if (
data.HaveCoordErrors()) {
892 "Error on the coordinates are not used in calculating Chi2 gradient");
897 assert(fg !=
nullptr);
903 Error(
"FitUtil::EvaluateChi2Gradient",
"The vectorized implementation doesn't support Integrals,"
904 "BinVolume or ExpErrors\n. Aborting operation.");
906 unsigned int npar = func.
NPar();
907 auto vecSize = vecCore::VectorSize<T>();
908 unsigned initialNPoints =
data.Size();
909 unsigned numVectors = initialNPoints / vecSize;
912 std::vector<vecCore::Mask<T>> validPointsMasks(numVectors + 1);
914 auto mapFunction = [&](
const unsigned int i) {
916 std::vector<T> gradFunc(npar);
917 std::vector<T> pointContributionVec(npar);
921 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
922 vecCore::Load<T>(
y,
data.ValuePtr(i * vecSize));
923 const auto invErrorPtr =
data.ErrorPtr(i * vecSize);
925 if (invErrorPtr ==
nullptr)
928 vecCore::Load<T>(invError, invErrorPtr);
934 const T *
x =
nullptr;
936 unsigned int ndim =
data.NDim();
943 for (
unsigned int j = 1; j < ndim; ++j)
944 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
953 validPointsMasks[i] = CheckInfNaNValues(fval);
954 if (vecCore::MaskEmpty(validPointsMasks[i])) {
956 return pointContributionVec;
960 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
963 validPointsMasks[i] = CheckInfNaNValues(gradFunc[ipar]);
965 if (vecCore::MaskEmpty(validPointsMasks[i])) {
970 vecCore::MaskedAssign(pointContributionVec[ipar], validPointsMasks[i],
971 -2.0 * (
y - fval) * invError * invError * gradFunc[ipar]);
974 return pointContributionVec;
978 auto redFunction = [&](
const std::vector<std::vector<T>> &partialResults) {
979 std::vector<T>
result(npar);
981 for (
auto const &pointContributionVec : partialResults) {
982 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
983 result[parameterIndex] += pointContributionVec[parameterIndex];
989 std::vector<T> gVec(npar);
990 std::vector<double>
g(npar);
998 Warning(
"FitUtil::EvaluateChi2Gradient",
999 "Multithread execution policy requires IMT, which is disabled. Changing "
1000 "to ::ROOT::EExecutionPolicy::kSequential.");
1018 "FitUtil::EvaluateChi2Gradient",
1019 "Execution policy unknown. Available choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
1023 unsigned int remainingPoints = initialNPoints % vecSize;
1024 if (remainingPoints > 0) {
1025 auto remainingPointsContribution = mapFunction(numVectors);
1027 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
1028 for (
unsigned int param = 0; param < npar; param++) {
1029 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1033 for (
unsigned int param = 0; param < npar; param++) {
1034 grad[param] = vecCore::ReduceAdd(gVec[param]);
1038 nPoints = initialNPoints;
1040 if (std::any_of(validPointsMasks.begin(), validPointsMasks.end(),
1041 [](vecCore::Mask<T> validPoints) { return !vecCore::MaskFull(validPoints); })) {
1042 unsigned nRejected = 0;
1044 for (
const auto &
mask : validPointsMasks) {
1045 for (
unsigned int i = 0; i < vecSize; i++) {
1046 nRejected += !vecCore::Get(
mask, i);
1050 assert(nRejected <= initialNPoints);
1051 nPoints = initialNPoints - nRejected;
1053 if (nPoints < npar) {
1055 "Too many points rejected for overflow in gradient calculation");
1062 Error(
"FitUtil::Evaluate<T>::EvalChi2Residual",
"The vectorized evaluation of the Chi2 with the ith residual is still not supported");
1069 Error(
"FitUtil::Evaluate<T>::EvaluatePoissonBinPdf",
"The vectorized evaluation of the BinnedLikelihood fit evaluated point by point is still not supported");
1074 Error(
"FitUtil::Evaluate<T>::EvalPdf",
"The vectorized evaluation of the LogLikelihood fit evaluated point by point is still not supported");
1092 unsigned nChunks = 0)
1097 assert(fg !=
nullptr);
1106 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"The vectorized implementation doesn't support Integrals,"
1107 "BinVolume or ExpErrors\n. Aborting operation.");
1109 unsigned int npar = func.
NPar();
1110 auto vecSize = vecCore::VectorSize<T>();
1111 unsigned initialNPoints =
data.Size();
1112 unsigned numVectors = initialNPoints / vecSize;
1114 auto mapFunction = [&](
const unsigned int i) {
1116 std::vector<T> gradFunc(npar);
1117 std::vector<T> pointContributionVec(npar);
1121 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
1122 vecCore::Load<T>(
y,
data.ValuePtr(i * vecSize));
1126 const T *
x =
nullptr;
1128 unsigned ndim =
data.NDim();
1133 for (
unsigned int j = 1; j < ndim; ++j)
1134 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
1144 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
1145 vecCore::Mask<T> positiveValuesMask = fval > 0;
1148 vecCore::MaskedAssign(pointContributionVec[ipar], positiveValuesMask, gradFunc[ipar] * (1. -
y / fval));
1150 vecCore::Mask<T> validNegativeValuesMask = !positiveValuesMask && gradFunc[ipar] != 0;
1152 if (!vecCore::MaskEmpty(validNegativeValuesMask)) {
1153 const T kdmax1 = vecCore::math::Sqrt(vecCore::NumericLimits<T>::Max());
1154 const T kdmax2 = vecCore::NumericLimits<T>::Max() / (4 * initialNPoints);
1155 T gg = kdmax1 * gradFunc[ipar];
1156 pointContributionVec[ipar] = -vecCore::Blend(gg > 0, vecCore::math::Min(gg, kdmax2), vecCore::math::Max(gg, -kdmax2));
1163 if (i < 5 || (i >
data.Size()-5) ) {
1164 if (
data.NDim() > 1) std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1];
1165 else std::cout << i <<
" x " <<
x[0];
1166 std::cout <<
" func " << fval <<
" gradient ";
1167 for (
unsigned int ii = 0; ii < npar; ++ii) std::cout <<
" " << pointContributionVec[ii];
1173 return pointContributionVec;
1177 auto redFunction = [&](
const std::vector<std::vector<T>> &partialResults) {
1178 std::vector<T>
result(npar);
1180 for (
auto const &pointContributionVec : partialResults) {
1181 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
1182 result[parameterIndex] += pointContributionVec[parameterIndex];
1188 std::vector<T> gVec(npar);
1196 Warning(
"FitUtil::EvaluatePoissonLogLGradient",
1197 "Multithread execution policy requires IMT, which is disabled. Changing "
1198 "to ::ROOT::EExecutionPolicy::kSequential.");
1215 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"Execution policy unknown. Available choices:\n "
1216 "::ROOT::EExecutionPolicy::kSequential (default)\n "
1217 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1222 unsigned int remainingPoints = initialNPoints % vecSize;
1223 if (remainingPoints > 0) {
1224 auto remainingPointsContribution = mapFunction(numVectors);
1226 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
1227 for (
unsigned int param = 0; param < npar; param++) {
1228 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1232 for (
unsigned int param = 0; param < npar; param++) {
1233 grad[param] = vecCore::ReduceAdd(gVec[param]);
1237 std::cout <<
"***** Final gradient : ";
1238 for (
unsigned int ii = 0; ii< npar; ++ii) std::cout << grad[ii] <<
" ";
1245 double *grad,
unsigned int &,
1247 unsigned nChunks = 0)
1252 assert(fg !=
nullptr);
1257 unsigned int npar = func.
NPar();
1258 auto vecSize = vecCore::VectorSize<T>();
1259 unsigned initialNPoints =
data.Size();
1260 unsigned numVectors = initialNPoints / vecSize;
1263 std::cout <<
"\n===> Evaluate Gradient for parameters ";
1264 for (
unsigned int ip = 0; ip < npar; ++ip)
1265 std::cout <<
" " <<
p[ip];
1271 const T kdmax1 = vecCore::math::Sqrt(vecCore::NumericLimits<T>::Max());
1272 const T kdmax2 = vecCore::NumericLimits<T>::Max() / (4 * initialNPoints);
1274 auto mapFunction = [&](
const unsigned int i) {
1275 std::vector<T> gradFunc(npar);
1276 std::vector<T> pointContributionVec(npar);
1279 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
1281 const T *
x =
nullptr;
1283 unsigned int ndim =
data.NDim();
1284 std::vector<T> xc(ndim);
1288 for (
unsigned int j = 1; j < ndim; ++j)
1289 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
1296 T fval = func(
x,
p);
1300 if (i < 5 || (i > numVectors-5) ) {
1301 if (ndim > 1) std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" gradient " << gradFunc[0] <<
" " << gradFunc[1] <<
" " << gradFunc[3] << std::endl;
1302 else std::cout << i <<
" x " <<
x[0] <<
" gradient " << gradFunc[0] <<
" " << gradFunc[1] <<
" " << gradFunc[3] << std::endl;
1306 vecCore::Mask<T> positiveValues = fval > 0;
1308 for (
unsigned int kpar = 0; kpar < npar; ++kpar) {
1309 if (!vecCore::MaskEmpty(positiveValues))
1310 vecCore::MaskedAssign<T>(pointContributionVec[kpar], positiveValues, -1. / fval * gradFunc[kpar]);
1312 vecCore::Mask<T> nonZeroGradientValues = !positiveValues && gradFunc[kpar] != 0;
1313 if (!vecCore::MaskEmpty(nonZeroGradientValues)) {
1314 T gg = kdmax1 * gradFunc[kpar];
1315 pointContributionVec[kpar] =
1316 vecCore::Blend(nonZeroGradientValues && gg > 0, -vecCore::math::Min(gg, kdmax2),
1317 -vecCore::math::Max(gg, -kdmax2));
1322 return pointContributionVec;
1326 auto redFunction = [&](
const std::vector<std::vector<T>> &pointContributions) {
1327 std::vector<T>
result(npar);
1329 for (
auto const &pointContributionVec : pointContributions) {
1330 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
1331 result[parameterIndex] += pointContributionVec[parameterIndex];
1337 std::vector<T> gVec(npar);
1338 std::vector<double>
g(npar);
1346 Warning(
"FitUtil::EvaluateLogLGradient",
1347 "Multithread execution policy requires IMT, which is disabled. Changing "
1348 "to ::ROOT::EExecutionPolicy::kSequential.");
1365 Error(
"FitUtil::EvaluateLogLGradient",
"Execution policy unknown. Available choices:\n "
1366 "::ROOT::EExecutionPolicy::kSequential (default)\n "
1367 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1371 unsigned int remainingPoints = initialNPoints % vecSize;
1372 if (remainingPoints > 0) {
1373 auto remainingPointsContribution = mapFunction(numVectors);
1375 auto remainingMask = vecCore::Int2Mask<T>(initialNPoints % vecSize);
1376 for (
unsigned int param = 0; param < npar; param++) {
1377 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1381 for (
unsigned int param = 0; param < npar; param++) {
1382 grad[param] = vecCore::ReduceAdd(gVec[param]);
1386 std::cout <<
"Final gradient ";
1387 for (
unsigned int param = 0; param < npar; param++) {
1388 std::cout <<
" " << grad[param];
1414 int iWeight,
bool extended,
unsigned int &nPoints,
1421 int iWeight,
bool extended,
unsigned int &nPoints,
1432 double *
g,
unsigned int &nPoints,
1434 unsigned nChunks = 0)
1440 bool hasGrad,
bool fullHessian)
1457 unsigned int &nPoints,
1459 unsigned nChunks = 0)
1465 double *
g,
unsigned int &nPoints,
1467 unsigned nChunks = 0)
1479#if defined (R__HAS_VECCORE) && defined(R__HAS_VC)
#define MATH_ERROR_MSG(loc, str)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
R__EXTERN TVirtualMutex * gROOTMutex
#define R__LOCKGUARD(mutex)
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
double Integral(const double *x1, const double *x2)
ROOT::Math::IGenFunction * fFunc1Dim
ROOT::Math::IntegratorMultiDim * fIgNDim
void SetFunction(const ParamFunc &func, const double *p=nullptr, ROOT::Math::IntegrationOneDim::Type igType=ROOT::Math::IntegrationOneDim::kDEFAULT)
IntegralEvaluator(const IntegralEvaluator &rhs)=delete
IntegralEvaluator(const ParamFunc &func, const double *p, bool useIntegral=true, ROOT::Math::IntegrationOneDim::Type igType=ROOT::Math::IntegrationOneDim::kDEFAULT)
IntegralEvaluator & operator=(const IntegralEvaluator &rhs)=delete
double F1(double x) const
ROOT::Math::IntegratorOneDim * fIg1Dim
double FN(const double *x) const
ROOT::Math::IMultiGenFunction * fFuncNDim
void SetParameters(const double *p)
double ExecFunc(T *f, const double *x, const double *p) const
double operator()(const double *x1, const double *x2)
LikelihoodAux(double logv=0.0, double w=0.0, double w2=0.0)
LikelihoodAux & operator+=(const LikelihoodAux &l)
LikelihoodAux operator+(const LikelihoodAux &l) const
LikelihoodAux operator+(const LikelihoodAux &l) const
LikelihoodAux(T logv={}, T w={}, T w2={})
LikelihoodAux & operator+=(const LikelihoodAux &l)
Class describing the un-binned data sets (just x coordinates values) of any dimensions.
Documentation for the abstract class IBaseFunctionMultiDim.
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
virtual void SetParameters(const double *p)=0
Set the parameter values.
virtual unsigned int NPar() const =0
Return the number of Parameters.
Interface (abstract class) for parametric gradient multi-dimensional functions providing in addition ...
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 ...
User class for performing multidimensional integration.
double Integral(const double *xmin, const double *xmax)
evaluate the integral with the previously given function between xmin[] and xmax[]
void SetFunction(Function &f, unsigned int dim)
set integration function using a generic function implementing the operator()(double *x) The dimensio...
User Class for performing numerical integration of a function in one dimension.
void SetFunction(Function &f)
method to set the a generic integration function
double Integral(Function &f, double a, double b)
evaluate the Integral of a function f over the defined interval (a,b)
Template class to wrap any member function of a class taking a double and returning a double in a 1D ...
auto MapReduce(F func, unsigned nTimes, R redfunc) -> InvokeResult_t< F >
Execute a function without arguments several times (Map) and accumulate the results into a single val...
A pseudo container class which is a generator of indices.
This class provides a simple interface to execute the same task multiple times in parallel threads,...
auto MapReduce(F func, unsigned nTimes, R redfunc) -> InvokeResult_t< F >
Execute a function nTimes in parallel (Map) and accumulate the results into a single value (Reduce).
Type
enumeration specifying the integration types.
@ kDEFAULT
default type specified in the static options
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
ROOT::Math::IParamMultiGradFunction IGradModelFunction
ROOT::Math::IParamMultiFunction IModelFunction
double EvaluatePoissonBinPdf(const IModelFunction &func, const BinData &data, const double *x, unsigned int ipoint, double *g=nullptr, double *h=nullptr, bool hasGrad=false, bool fullHessian=false)
evaluate the pdf contribution to the Poisson LogL given a model function and the BinPoint data.
void EvaluatePoissonLogLGradient(const IModelFunction &func, const BinData &data, const double *p, double *grad, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy=::ROOT::EExecutionPolicy::kSequential, unsigned nChunks=0)
evaluate the Poisson LogL given a model function and the data at the point p.
double EvaluateChi2Residual(const IModelFunction &func, const BinData &data, const double *p, unsigned int ipoint, double *g=nullptr, double *h=nullptr, bool hasGrad=false, bool fullHessian=false)
evaluate the residual contribution to the Chi2 given a model function and the BinPoint data and if th...
double EvaluatePoissonLogL(const IModelFunction &func, const BinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy, unsigned nChunks=0)
evaluate the Poisson LogL given a model function and the data at the point p.
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.
void EvaluateLogLGradient(const IModelFunction &func, const UnBinData &data, const double *p, double *grad, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy=::ROOT::EExecutionPolicy::kSequential, unsigned nChunks=0)
evaluate the LogL gradient given a model function and the data at the point p.
double EvaluatePdf(const IModelFunction &func, const UnBinData &data, const double *p, unsigned int ipoint, double *g=nullptr, double *h=nullptr, bool hasGrad=false, bool fullHessian=false)
evaluate the pdf contribution to the LogL given a model function and the BinPoint data.
unsigned setAutomaticChunking(unsigned nEvents)
double EvaluateLogL(const IModelFunction &func, const UnBinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy, unsigned nChunks=0)
evaluate the LogL given a model function and the data at the point x.
double EvaluateChi2(const IModelFunction &func, const BinData &data, const double *p, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy, unsigned nChunks=0)
Chi2 Functions.
void EvaluateChi2Gradient(const IModelFunction &func, const BinData &data, const double *p, double *grad, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy=::ROOT::EExecutionPolicy::kSequential, unsigned nChunks=0)
evaluate the Chi2 gradient given a model function and the data at the point p.
T EvalLog(T x)
safe evaluation of log(x) with a protections against negative or zero argument to the log smooth line...
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
DataOptions : simple structure holding the options on how the data are filled.
bool fIntegral
use integral of bin content instead of bin center (default is false)
bool fExpErrors
use expected errors from the function and not from the data
bool fBinVolume
normalize data by the bin volume (it is used in the Poisson likelihood fits)
static double EvalLogL(const IModelFunctionTempl< double > &func, const UnBinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy, unsigned nChunks=0)
static double EvalChi2Effective(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, unsigned int &nPoints)
static void EvalLogLGradient(const IModelFunctionTempl< double > &func, const UnBinData &data, const double *p, double *g, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy=::ROOT::EExecutionPolicy::kSequential, unsigned nChunks=0)
static void EvalChi2Gradient(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, double *g, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy=::ROOT::EExecutionPolicy::kSequential, unsigned nChunks=0)
static double EvalPdf(const IModelFunctionTempl< double > &func, const UnBinData &data, const double *p, unsigned int i, double *g, double *h, bool hasGrad, bool fullHessian)
static double EvalChi2(const IModelFunction &func, const BinData &data, const double *p, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy, unsigned nChunks=0)
static double EvalPoissonBinPdf(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, unsigned int i, double *g, double *h, bool hasGrad, bool fullHessian)
evaluate the pdf (Poisson) contribution to the logl (return actually log of pdf) and its gradient
static void EvalPoissonLogLGradient(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, double *g, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy=::ROOT::EExecutionPolicy::kSequential, unsigned nChunks=0)
static double EvalPoissonLogL(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, int iWeight, bool extended, unsigned int &nPoints, ::ROOT::EExecutionPolicy executionPolicy, unsigned nChunks=0)
static double EvalChi2Residual(const IModelFunctionTempl< double > &func, const BinData &data, const double *p, unsigned int i, double *g, double *h, bool hasGrad, bool fullHessian)