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
234 vecCore::Load<ROOT::Double_v>(xx,
x);
235 const double *p0 =
p;
236 auto res = (*f)(&xx, (
const double *)p0);
237 return vecCore::Get<ROOT::Double_v>(res, 0);
239 std::vector<ROOT::Double_v> xx(
fDim);
240 for (
unsigned int i = 0; i <
fDim; ++i) {
241 vecCore::Load<ROOT::Double_v>(xx[i],
x + i);
243 auto res = (*f)(xx.data(),
p);
244 return vecCore::Get<ROOT::Double_v>(res, 0);
285 unsigned int &nPoints,
287 unsigned nChunks = 0);
301 unsigned int &nPoints,
303 unsigned nChunks = 0);
318 unsigned nChunks = 0);
325 unsigned int &nPoints,
327 unsigned nChunks = 0);
338 double *
g =
nullptr,
double *
h =
nullptr,
bool hasGrad =
false,
bool fullHessian =
false);
373 unsigned int n =
data.Size();
374 nPoints =
data.Size();
387 Error(
"FitUtil::EvaluateChi2",
"The vectorized implementation doesn't support Integrals, BinVolume or ExpErrors\n. Aborting operation.");
391 double maxResValue = std::numeric_limits<double>::max() /
n;
392 std::vector<double> ones{1., 1., 1., 1.};
393 auto vecSize = vecCore::VectorSize<T>();
395 auto mapFunction = [&](
unsigned int i) {
397 T
x1,
y, invErrorVec;
398 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
399 vecCore::Load<T>(
y,
data.ValuePtr(i * vecSize));
400 const auto invError =
data.ErrorPtr(i * vecSize);
401 auto invErrorptr = (invError !=
nullptr) ? invError : &ones.front();
402 vecCore::Load<T>(invErrorVec, invErrorptr);
406 if(
data.NDim() > 1) {
407 xc.resize(
data.NDim());
409 for (
unsigned int j = 1; j <
data.NDim(); ++j)
410 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
424 T tmp = (
y - fval) * invErrorVec;
429 auto m = vecCore::Mask_v<T>(chi2 > maxResValue);
431 vecCore::MaskedAssign<T>(chi2,
m, maxResValue);
436 auto redFunction = [](
const std::vector<T> &objs) {
437 return std::accumulate(objs.begin(), objs.end(), T{});
445 Warning(
"FitUtil::EvaluateChi2",
"Multithread execution policy requires IMT, which is disabled. Changing "
446 "to ::ROOT::EExecutionPolicy::kSequential.");
462 Error(
"FitUtil::EvaluateChi2",
"Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n ::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
466 if (
data.Size() % vecSize != 0)
467 vecCore::MaskedAssign(res, vecCore::Int2Mask<T>(
data.Size() % vecSize),
468 res + mapFunction(
data.Size() / vecSize));
470 return vecCore::ReduceAdd(res);
474 int iWeight,
bool extended,
unsigned int &nPoints,
478 unsigned int n =
data.Size();
479 nPoints =
data.Size();
482 bool normalizeFunc =
false;
492 if (!normalizeFunc) {
493 if (
data.NDim() == 1) {
495 vecCore::Load<T>(
x,
data.GetCoordComponent(0, 0));
499 std::vector<T>
x(
data.NDim());
500 for (
unsigned int j = 0; j <
data.NDim(); ++j)
501 vecCore::Load<T>(
x[j],
data.GetCoordComponent(0, j));
511 std::vector<double>
xmin(
data.NDim());
512 std::vector<double>
xmax(
data.NDim());
515 if (
data.Range().Size() > 0) {
517 for (
unsigned int ir = 0; ir <
data.Range().Size(); ++ir) {
526 vecCore::Load<T>(xmin_v,
xmin.data());
527 vecCore::Load<T>(xmax_v,
xmax.data());
528 if (vecCore::ReduceAdd(func(&xmin_v,
p)) != 0 || vecCore::ReduceAdd(func(&xmax_v,
p)) != 0) {
529 MATH_ERROR_MSG(
"FitUtil::EvaluateLogLikelihood",
"A range has not been set and the function is not zero at +/- inf");
538 auto vecSize = vecCore::VectorSize<T>();
539 unsigned int numVectors =
n / vecSize;
541 auto mapFunction = [ &,
p](
const unsigned i) {
549 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
550 const T *
x =
nullptr;
551 unsigned int ndim =
data.NDim();
556 for (
unsigned int j = 1; j < ndim; ++j)
557 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
570 if (i < 5 || (i > numVectors-5) ) {
571 if (ndim == 1) std::cout << i <<
" x " <<
x[0] <<
" fval = " << fval;
572 else std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" fval = " << fval;
576 if (normalizeFunc) fval = fval * (1 / norm);
582 if (
data.WeightsPtr(i) ==
nullptr)
585 vecCore::Load<T>(weight,
data.WeightsPtr(i*vecSize));
592 W2 = weight * weight;
597 if (i < 5 || (i > numVectors-5)) {
598 std::cout <<
" " << fval <<
" logfval " << logval << std::endl;
605 auto redFunction = [](
const std::vector<LikelihoodAux<T>> &objs) {
617 Warning(
"FitUtil::EvaluateLogL",
"Multithread execution policy requires IMT, which is disabled. Changing "
618 "to ::ROOT::EExecutionPolicy::kSequential.");
637 Error(
"FitUtil::EvaluateLogL",
"Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n ::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
645 unsigned int remainingPoints =
n % vecSize;
646 if (remainingPoints > 0) {
647 auto remainingPointsContribution = mapFunction(numVectors);
649 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
650 vecCore::MaskedAssign(logl_v, remainingMask, logl_v + remainingPointsContribution.logvalue);
651 vecCore::MaskedAssign(sumW_v, remainingMask, sumW_v + remainingPointsContribution.weight);
652 vecCore::MaskedAssign(sumW2_v, remainingMask, sumW2_v + remainingPointsContribution.weight2);
657 double logl = vecCore::ReduceAdd(logl_v);
658 double sumW = vecCore::ReduceAdd(sumW_v);
659 double sumW2 = vecCore::ReduceAdd(sumW2_v);
663 double extendedTerm = 0;
667 if (!normalizeFunc) {
669 std::vector<double>
xmin(
data.NDim());
670 std::vector<double>
xmax(
data.NDim());
673 if (
data.Range().Size() > 0) {
675 for (
unsigned int ir = 0; ir <
data.Range().Size(); ++ir) {
684 vecCore::Load<T>(xmin_v,
xmin.data());
685 vecCore::Load<T>(xmax_v,
xmax.data());
686 if (vecCore::ReduceAdd(func(&xmin_v,
p)) != 0 || vecCore::ReduceAdd(func(&xmax_v,
p)) != 0) {
687 MATH_ERROR_MSG(
"FitUtil::EvaluateLogLikelihood",
"A range has not been set and the function is not zero at +/- inf");
696 extendedTerm = - nuTot;
700 extendedTerm = - (sumW2 / sumW) * nuTot;
709 logl += extendedTerm;
713 std::cout <<
"Evaluated log L for parameters (";
714 for (
unsigned int ip = 0; ip < func.
NPar(); ++ip)
715 std::cout <<
" " <<
p[ip];
716 std::cout <<
") nll = " << -logl << std::endl;
724 int iWeight,
bool extended,
unsigned int,
745 auto vecSize = vecCore::VectorSize<T>();
749 Error(
"FitUtil::EvaluateChi2",
750 "The vectorized implementation doesn't support Integrals or BinVolume\n. Aborting operation.");
751 bool useW2 = (iWeight == 2);
753 auto mapFunction = [&](
unsigned int i) {
755 vecCore::Load<T>(
y,
data.ValuePtr(i * vecSize));
758 if (
data.NDim() > 1) {
759 std::vector<T>
x(
data.NDim());
760 for (
unsigned int j = 0; j <
data.NDim(); ++j)
761 vecCore::Load<T>(
x[j],
data.GetCoordComponent(i * vecSize, j));
763 fval = func(
x.data());
765 fval = func(
x.data(),
p);
770 vecCore::Load<T>(
x,
data.GetCoordComponent(i * vecSize, 0));
780 vecCore::MaskedAssign<T>(fval, fval < 0.0, 0.0);
792 vecCore::Load<T>(error,
data.ErrorPtr(i * vecSize));
794 auto m = vecCore::Mask_v<T>(
y != 0.0);
795 auto weight = vecCore::Blend(
m,(error * error) /
y, T(
data.SumOfError2()/
data.SumOfContent()) );
797 nloglike = weight * ( fval -
y);
806 if (extended) nloglike = fval -
y;
808 vecCore::MaskedAssign<T>(
816 auto redFunction = [](
const std::vector<T> &objs) {
return std::accumulate(objs.begin(), objs.end(), T{}); };
822 Warning(
"FitUtil::Evaluate<T>::EvalPoissonLogL",
823 "Multithread execution policy requires IMT, which is disabled. Changing "
824 "to ::ROOT::EExecutionPolicy::kSequential.");
831 for (
unsigned int i = 0; i < (
data.Size() / vecSize); i++) {
832 res += mapFunction(i);
842 "FitUtil::Evaluate<T>::EvalPoissonLogL",
843 "Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n ::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
847 if (
data.Size() % vecSize != 0)
848 vecCore::MaskedAssign(res, vecCore::Int2Mask<T>(
data.Size() % vecSize),
849 res + mapFunction(
data.Size() / vecSize));
851 return vecCore::ReduceAdd(res);
856 Error(
"FitUtil::Evaluate<T>::EvalChi2Effective",
"The vectorized evaluation of the Chi2 with coordinate errors is still not supported");
863 static vecCore::Mask<T> CheckInfNaNValues(T &rval)
865 auto mask = rval > -vecCore::NumericLimits<T>::Max() && rval < vecCore::NumericLimits<T>::Max();
868 vecCore::MaskedAssign(rval, !
mask, +vecCore::NumericLimits<T>::Max());
871 vecCore::MaskedAssign(rval, !
mask && rval < 0, -vecCore::NumericLimits<T>::Max());
877 unsigned int &nPoints,
879 unsigned nChunks = 0)
887 if (
data.HaveCoordErrors()) {
889 "Error on the coordinates are not used in calculating Chi2 gradient");
894 assert(fg !=
nullptr);
900 Error(
"FitUtil::EvaluateChi2Gradient",
"The vectorized implementation doesn't support Integrals,"
901 "BinVolume or ExpErrors\n. Aborting operation.");
903 unsigned int npar = func.
NPar();
904 auto vecSize = vecCore::VectorSize<T>();
905 unsigned initialNPoints =
data.Size();
906 unsigned numVectors = initialNPoints / vecSize;
909 std::vector<vecCore::Mask<T>> validPointsMasks(numVectors + 1);
911 auto mapFunction = [&](
const unsigned int i) {
913 std::vector<T> gradFunc(npar);
914 std::vector<T> pointContributionVec(npar);
918 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
919 vecCore::Load<T>(
y,
data.ValuePtr(i * vecSize));
920 const auto invErrorPtr =
data.ErrorPtr(i * vecSize);
922 if (invErrorPtr ==
nullptr)
925 vecCore::Load<T>(invError, invErrorPtr);
931 const T *
x =
nullptr;
933 unsigned int ndim =
data.NDim();
940 for (
unsigned int j = 1; j < ndim; ++j)
941 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
950 validPointsMasks[i] = CheckInfNaNValues(fval);
951 if (vecCore::MaskEmpty(validPointsMasks[i])) {
953 return pointContributionVec;
957 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
960 validPointsMasks[i] = CheckInfNaNValues(gradFunc[ipar]);
962 if (vecCore::MaskEmpty(validPointsMasks[i])) {
967 vecCore::MaskedAssign(pointContributionVec[ipar], validPointsMasks[i],
968 -2.0 * (
y - fval) * invError * invError * gradFunc[ipar]);
971 return pointContributionVec;
975 auto redFunction = [&](
const std::vector<std::vector<T>> &partialResults) {
976 std::vector<T>
result(npar);
978 for (
auto const &pointContributionVec : partialResults) {
979 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
980 result[parameterIndex] += pointContributionVec[parameterIndex];
986 std::vector<T> gVec(npar);
987 std::vector<double>
g(npar);
995 Warning(
"FitUtil::EvaluateChi2Gradient",
996 "Multithread execution policy requires IMT, which is disabled. Changing "
997 "to ::ROOT::EExecutionPolicy::kSequential.");
1015 "FitUtil::EvaluateChi2Gradient",
1016 "Execution policy unknown. Available choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
1020 unsigned int remainingPoints = initialNPoints % vecSize;
1021 if (remainingPoints > 0) {
1022 auto remainingPointsContribution = mapFunction(numVectors);
1024 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
1025 for (
unsigned int param = 0; param < npar; param++) {
1026 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1030 for (
unsigned int param = 0; param < npar; param++) {
1031 grad[param] = vecCore::ReduceAdd(gVec[param]);
1035 nPoints = initialNPoints;
1037 if (std::any_of(validPointsMasks.begin(), validPointsMasks.end(),
1038 [](vecCore::Mask<T> validPoints) { return !vecCore::MaskFull(validPoints); })) {
1039 unsigned nRejected = 0;
1041 for (
const auto &
mask : validPointsMasks) {
1042 for (
unsigned int i = 0; i < vecSize; i++) {
1043 nRejected += !vecCore::Get(
mask, i);
1047 assert(nRejected <= initialNPoints);
1048 nPoints = initialNPoints - nRejected;
1050 if (nPoints < npar) {
1052 "Too many points rejected for overflow in gradient calculation");
1059 Error(
"FitUtil::Evaluate<T>::EvalChi2Residual",
"The vectorized evaluation of the Chi2 with the ith residual is still not supported");
1066 Error(
"FitUtil::Evaluate<T>::EvaluatePoissonBinPdf",
"The vectorized evaluation of the BinnedLikelihood fit evaluated point by point is still not supported");
1071 Error(
"FitUtil::Evaluate<T>::EvalPdf",
"The vectorized evaluation of the LogLikelihood fit evaluated point by point is still not supported");
1089 unsigned nChunks = 0)
1094 assert(fg !=
nullptr);
1103 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"The vectorized implementation doesn't support Integrals,"
1104 "BinVolume or ExpErrors\n. Aborting operation.");
1106 unsigned int npar = func.
NPar();
1107 auto vecSize = vecCore::VectorSize<T>();
1108 unsigned initialNPoints =
data.Size();
1109 unsigned numVectors = initialNPoints / vecSize;
1111 auto mapFunction = [&](
const unsigned int i) {
1113 std::vector<T> gradFunc(npar);
1114 std::vector<T> pointContributionVec(npar);
1118 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
1119 vecCore::Load<T>(
y,
data.ValuePtr(i * vecSize));
1123 const T *
x =
nullptr;
1125 unsigned ndim =
data.NDim();
1130 for (
unsigned int j = 1; j < ndim; ++j)
1131 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
1141 for (
unsigned int ipar = 0; ipar < npar; ++ipar) {
1142 vecCore::Mask<T> positiveValuesMask = fval > 0;
1145 vecCore::MaskedAssign(pointContributionVec[ipar], positiveValuesMask, gradFunc[ipar] * (1. -
y / fval));
1147 vecCore::Mask<T> validNegativeValuesMask = !positiveValuesMask && gradFunc[ipar] != 0;
1149 if (!vecCore::MaskEmpty(validNegativeValuesMask)) {
1150 const T kdmax1 = vecCore::math::Sqrt(vecCore::NumericLimits<T>::Max());
1151 const T kdmax2 = vecCore::NumericLimits<T>::Max() / (4 * initialNPoints);
1152 T gg = kdmax1 * gradFunc[ipar];
1153 pointContributionVec[ipar] = -vecCore::Blend(gg > 0, vecCore::math::Min(gg, kdmax2), vecCore::math::Max(gg, -kdmax2));
1160 if (i < 5 || (i >
data.Size()-5) ) {
1161 if (
data.NDim() > 1) std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1];
1162 else std::cout << i <<
" x " <<
x[0];
1163 std::cout <<
" func " << fval <<
" gradient ";
1164 for (
unsigned int ii = 0; ii < npar; ++ii) std::cout <<
" " << pointContributionVec[ii];
1170 return pointContributionVec;
1174 auto redFunction = [&](
const std::vector<std::vector<T>> &partialResults) {
1175 std::vector<T>
result(npar);
1177 for (
auto const &pointContributionVec : partialResults) {
1178 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
1179 result[parameterIndex] += pointContributionVec[parameterIndex];
1185 std::vector<T> gVec(npar);
1193 Warning(
"FitUtil::EvaluatePoissonLogLGradient",
1194 "Multithread execution policy requires IMT, which is disabled. Changing "
1195 "to ::ROOT::EExecutionPolicy::kSequential.");
1212 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"Execution policy unknown. Available choices:\n "
1213 "::ROOT::EExecutionPolicy::kSequential (default)\n "
1214 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1219 unsigned int remainingPoints = initialNPoints % vecSize;
1220 if (remainingPoints > 0) {
1221 auto remainingPointsContribution = mapFunction(numVectors);
1223 auto remainingMask = vecCore::Int2Mask<T>(remainingPoints);
1224 for (
unsigned int param = 0; param < npar; param++) {
1225 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1229 for (
unsigned int param = 0; param < npar; param++) {
1230 grad[param] = vecCore::ReduceAdd(gVec[param]);
1234 std::cout <<
"***** Final gradient : ";
1235 for (
unsigned int ii = 0; ii< npar; ++ii) std::cout << grad[ii] <<
" ";
1242 double *grad,
unsigned int &,
1244 unsigned nChunks = 0)
1249 assert(fg !=
nullptr);
1254 unsigned int npar = func.
NPar();
1255 auto vecSize = vecCore::VectorSize<T>();
1256 unsigned initialNPoints =
data.Size();
1257 unsigned numVectors = initialNPoints / vecSize;
1260 std::cout <<
"\n===> Evaluate Gradient for parameters ";
1261 for (
unsigned int ip = 0; ip < npar; ++ip)
1262 std::cout <<
" " <<
p[ip];
1268 const T kdmax1 = vecCore::math::Sqrt(vecCore::NumericLimits<T>::Max());
1269 const T kdmax2 = vecCore::NumericLimits<T>::Max() / (4 * initialNPoints);
1271 auto mapFunction = [&](
const unsigned int i) {
1272 std::vector<T> gradFunc(npar);
1273 std::vector<T> pointContributionVec(npar);
1276 vecCore::Load<T>(
x1,
data.GetCoordComponent(i * vecSize, 0));
1278 const T *
x =
nullptr;
1280 unsigned int ndim =
data.NDim();
1281 std::vector<T> xc(ndim);
1285 for (
unsigned int j = 1; j < ndim; ++j)
1286 vecCore::Load<T>(xc[j],
data.GetCoordComponent(i * vecSize, j));
1293 T fval = func(
x,
p);
1297 if (i < 5 || (i > numVectors-5) ) {
1298 if (ndim > 1) std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" gradient " << gradFunc[0] <<
" " << gradFunc[1] <<
" " << gradFunc[3] << std::endl;
1299 else std::cout << i <<
" x " <<
x[0] <<
" gradient " << gradFunc[0] <<
" " << gradFunc[1] <<
" " << gradFunc[3] << std::endl;
1303 vecCore::Mask<T> positiveValues = fval > 0;
1305 for (
unsigned int kpar = 0; kpar < npar; ++kpar) {
1306 if (!vecCore::MaskEmpty(positiveValues))
1307 vecCore::MaskedAssign<T>(pointContributionVec[kpar], positiveValues, -1. / fval * gradFunc[kpar]);
1309 vecCore::Mask<T> nonZeroGradientValues = !positiveValues && gradFunc[kpar] != 0;
1310 if (!vecCore::MaskEmpty(nonZeroGradientValues)) {
1311 T gg = kdmax1 * gradFunc[kpar];
1312 pointContributionVec[kpar] =
1313 vecCore::Blend(nonZeroGradientValues && gg > 0, -vecCore::math::Min(gg, kdmax2),
1314 -vecCore::math::Max(gg, -kdmax2));
1319 return pointContributionVec;
1323 auto redFunction = [&](
const std::vector<std::vector<T>> &pointContributions) {
1324 std::vector<T>
result(npar);
1326 for (
auto const &pointContributionVec : pointContributions) {
1327 for (
unsigned int parameterIndex = 0; parameterIndex < npar; parameterIndex++)
1328 result[parameterIndex] += pointContributionVec[parameterIndex];
1334 std::vector<T> gVec(npar);
1335 std::vector<double>
g(npar);
1343 Warning(
"FitUtil::EvaluateLogLGradient",
1344 "Multithread execution policy requires IMT, which is disabled. Changing "
1345 "to ::ROOT::EExecutionPolicy::kSequential.");
1362 Error(
"FitUtil::EvaluateLogLGradient",
"Execution policy unknown. Available choices:\n "
1363 "::ROOT::EExecutionPolicy::kSequential (default)\n "
1364 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1368 unsigned int remainingPoints = initialNPoints % vecSize;
1369 if (remainingPoints > 0) {
1370 auto remainingPointsContribution = mapFunction(numVectors);
1372 auto remainingMask = vecCore::Int2Mask<T>(initialNPoints % vecSize);
1373 for (
unsigned int param = 0; param < npar; param++) {
1374 vecCore::MaskedAssign(gVec[param], remainingMask, gVec[param] + remainingPointsContribution[param]);
1378 for (
unsigned int param = 0; param < npar; param++) {
1379 grad[param] = vecCore::ReduceAdd(gVec[param]);
1383 std::cout <<
"Final gradient ";
1384 for (
unsigned int param = 0; param < npar; param++) {
1385 std::cout <<
" " << grad[param];
1411 int iWeight,
bool extended,
unsigned int &nPoints,
1418 int iWeight,
bool extended,
unsigned int &nPoints,
1429 double *
g,
unsigned int &nPoints,
1431 unsigned nChunks = 0)
1437 bool hasGrad,
bool fullHessian)
1454 unsigned int &nPoints,
1456 unsigned nChunks = 0)
1462 double *
g,
unsigned int &nPoints,
1464 unsigned nChunks = 0)
1476#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 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 mask
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)
IntegralEvaluator & operator=(const IntegralEvaluator &rhs)
ROOT::Math::IGenFunction * fFunc1Dim
ROOT::Math::IntegratorMultiDim * fIgNDim
IntegralEvaluator(const IntegralEvaluator &rhs)
IntegralEvaluator(const ParamFunc &func, const double *p, bool useIntegral=true, ROOT::Math::IntegrationOneDim::Type igType=ROOT::Math::IntegrationOneDim::kDEFAULT)
double F1(double x) const
ROOT::Math::IntegratorOneDim * fIg1Dim
void SetFunction(const ParamFunc &func, const double *p=0, ROOT::Math::IntegrationOneDim::Type igType=ROOT::Math::IntegrationOneDim::kDEFAULT)
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...
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
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)