57 template<
class GradFunc = IGradModelFunction>
131 for (
unsigned int k = 0; k <
fN; ++k) {
140 for (
unsigned int k = 0; k <
fN; ++k) {
150 g[k] = 0.5 * ( f2 -
f1 )/
h;
166 mutable std::vector<double>
fVec;
173 if (
rval > - std::numeric_limits<double>::max() &&
rval < std::numeric_limits<double>::max() )
177 return -std::numeric_limits<double>::max();
180 return + std::numeric_limits<double>::max();
187 if (
rval > - std::numeric_limits<double>::max() &&
rval < std::numeric_limits<double>::max() )
191 rval = -std::numeric_limits<double>::max();
196 rval = + std::numeric_limits<double>::max();
205 template <
class GFunc>
207 const double *
x1,
const double *
x2,
const double *
p,
double *
g) {
214 for (
unsigned int k = 0; k <
npar; ++k ) {
215 pfunc.SetDerivComponent(k);
238 unsigned int n =
data.Size();
253 bool isWeighted =
fitOpt.fExpErrors && !
fitOpt.fErrors1 &&
data.IsWeighted();
255 std::cout <<
"\n\nFit data size = " <<
n << std::endl;
256 std::cout <<
"evaluate chi2 using function " << &func <<
" " <<
p << std::endl;
257 std::cout <<
"use empty bins " <<
fitOpt.fUseEmpty << std::endl;
259 std::cout <<
"use binvolume " <<
useBinVolume << std::endl;
260 std::cout <<
"use Exp Errors " <<
useExpErrors << std::endl;
261 std::cout <<
"use all error=1 " <<
fitOpt.fErrors1 << std::endl;
262 if (isWeighted) std::cout <<
"Weighted data set - sumw = " <<
data.SumOfContent() <<
" sumw2 = " <<
data.SumOfError2() << std::endl;
275 double maxResValue = std::numeric_limits<double>::max() /
n;
288 const auto x1 =
data.GetCoordComponent(i, 0);
289 const auto y =
data.Value(i);
294 const double *
x =
nullptr;
295 std::vector<double>
xc;
296 double binVolume = 1.0;
298 unsigned int ndim =
data.NDim();
300 for (
unsigned int j = 0;
j < ndim; ++
j) {
301 double xx = *
data.GetCoordComponent(i,
j);
302 double x2 =
data.GetBinUpEdgeComponent(i,
j);
303 binVolume *= std::abs(
x2 -
xx);
309 }
else if(
data.NDim() > 1) {
314 for (
unsigned int j = 1;
j <
data.NDim(); ++
j)
315 xc[
j] = *
data.GetCoordComponent(i,
j);
333 std::vector<double>
x2(
data.NDim());
334 data.GetBinUpEdgeCoordinates(i,
x2.data());
362 std::cout <<
x[0] <<
" " <<
y <<
" " << 1./
invError <<
" params : ";
363 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar)
364 std::cout <<
p[ipar] <<
"\t";
365 std::cout <<
"\tfval = " <<
fval <<
" bin volume " << binVolume <<
" ref " <<
wrefVolume << std::endl;
394 Warning(
"FitUtil::EvaluateChi2",
"Multithread execution policy requires IMT, which is disabled. Changing "
395 "to ROOT::EExecutionPolicy::kSequential.");
402 for (
unsigned int i=0; i<
n; ++i) {
415 Error(
"FitUtil::EvaluateChi2",
"Execution policy unknown. Available choices:\n ROOT::EExecutionPolicy::kSequential (default)\n ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
435 unsigned int n =
data.Size();
438 std::cout <<
"\n\nFit data size = " <<
n << std::endl;
439 std::cout <<
"evaluate effective chi2 using function " << &func <<
" " <<
p << std::endl;
446 unsigned int ndim = func.
NDim();
448 double maxResValue = std::numeric_limits<double>::max() /
n;
460 std::vector<double>
x(ndim);
461 std::vector<double>
ex(ndim);
467 double y =
data.Value(i);
469 double fval = func(
x.data(),
p );
475 if (!
data.HaveAsymErrors() )
488 while (
j < ndim &&
ex[
j] == 0.) {
j++; }
508 std::cout <<
"error for coord " <<
icoord <<
" = " <<
ex[
icoord] <<
" deriv " <<
deriv << std::endl;
513 double w2 = (
e2 > 0) ? 1.0/
e2 : 0;
517 std::cout <<
x[0] <<
" " <<
y <<
" ex " <<
ex[0] <<
" ey " <<
ey <<
" params : ";
518 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar)
519 std::cout <<
p[ipar] <<
"\t";
520 std::cout <<
"\tfval = " <<
fval <<
"\tresval = " <<
resval << std::endl;
538 Warning(
"FitUtil::EvaluateChi2Effective",
"Multithread execution policy requires IMT, which is disabled. Changing "
539 "to ROOT::EExecutionPolicy::kSequential.");
546 for (
unsigned int i = 0; i <
n; ++i) {
556 Error(
"FitUtil::EvaluateChi2Effective",
"Execution policy unknown. Available choices:\n ROOT::EExecutionPolicy::kSequential (default)\n ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
564 std::cout <<
"chi2 = " <<
chi2 <<
" n = " <<
nPoints << std::endl;
581 MATH_ERROR_MSG(
"FitUtil::EvaluateChi2Residual",
"Error on the coordinates are not used in calculating Chi2 residual");
595 unsigned int ndim =
data.NDim();
596 double binVolume = 1.0;
597 const double *
x2 =
nullptr;
600 std::vector<double>
xc;
605 for (
unsigned int j = 0;
j < ndim; ++
j) {
606 binVolume *= std::abs(
x2[
j]-
x1[
j] );
657 return std::numeric_limits<double>::quiet_NaN();
683 for (
unsigned int k = 0; k <
npar; ++k) {
687 for (
unsigned int l = 0;
l <= k;
l++) {
688 unsigned int idx =
l + k * (k + 1) / 2;
697 h[idx] += 2. *
g[k]*
g[
l];
717 if (
data.HaveCoordErrors()) {
719 "Error on the coordinates are not used in calculating Chi2 gradient");
723 const IGradModelFunction *
fg =
dynamic_cast<const IGradModelFunction *
>(&
f);
726 const IGradModelFunction &func = *
fg;
729 std::cout <<
"\n\nFit data size = " <<
nPoints << std::endl;
730 std::cout <<
"evaluate chi2 using function gradient " << &func <<
" " <<
p << std::endl;
749 unsigned int npar = func.NPar();
759 const auto x1 =
data.GetCoordComponent(i, 0);
760 const auto y =
data.Value(i);
767 const double *
x =
nullptr;
768 std::vector<double>
xc;
770 unsigned int ndim =
data.NDim();
771 double binVolume = 1;
774 for (
unsigned int j = 0;
j < ndim; ++
j) {
775 double x1_j = *
data.GetCoordComponent(i,
j);
776 double x2_j =
data.GetBinUpEdgeComponent(i,
j);
785 }
else if (ndim > 1) {
788 for (
unsigned int j = 1;
j < ndim; ++
j)
789 xc[
j] = *
data.GetCoordComponent(i,
j);
799 std::vector<double>
x2(
data.NDim());
800 data.GetBinUpEdgeCoordinates(i,
x2.data());
810 std::cout <<
x[0] <<
" " <<
y <<
" " << 1. /
invError <<
" params : ";
811 for (
unsigned int ipar = 0; ipar <
npar; ++ipar)
812 std::cout <<
p[ipar] <<
"\t";
813 std::cout <<
"\tfval = " <<
fval << std::endl;
822 unsigned int ipar = 0;
823 for (; ipar <
npar; ++ipar) {
860 std::vector<double>
g(
npar);
865 Warning(
"FitUtil::EvaluateChi2Gradient",
"Multithread execution policy requires IMT, which is disabled. Changing "
866 "to ROOT::EExecutionPolicy::kSequential.");
890 Error(
"FitUtil::EvaluateChi2Gradient",
891 "Execution policy unknown. Available choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
909 "Error - too many points rejected for overflow in gradient calculation");
913 std::copy(
g.begin(),
g.end(), grad);
932 const double *
x =
data.Coords(i);
933 double fval = func (
x,
p );
936 if (
g ==
nullptr)
return logPdf;
944 gfunc->ParameterGradient(
x ,
p,
g );
953 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar) {
958 std::cout <<
x[i] <<
"\t";
959 std::cout <<
"\tpar = [ " << func.
NPar() <<
" ] = ";
960 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar)
961 std::cout <<
p[ipar] <<
"\t";
962 std::cout <<
"\tfval = " <<
fval;
963 std::cout <<
"\tgrad = [ ";
964 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar)
965 std::cout <<
g[ipar] <<
"\t";
966 std::cout <<
" ] " << std::endl;
979 unsigned int n =
data.Size();
996 if (
data.NDim() == 1) {
997 const double *
x =
data.GetCoordComponent(0,0);
1001 std::vector<double>
x(
data.NDim());
1002 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
1003 x[
j] = *
data.GetCoordComponent(0,
j);
1012 std::vector<double>
xmin(
data.NDim());
1013 std::vector<double>
xmax(
data.NDim());
1016 if (
data.Range().Size() > 0) {
1026 if (func(
xmin.data(),
p) != 0 || func(
xmax.data(),
p) != 0) {
1028 "A range has not been set and the function is not zero at +/- inf");
1042 if (
data.NDim() > 1) {
1043 std::vector<double>
x(
data.NDim());
1044 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
1045 x[
j] = *
data.GetCoordComponent(i,
j);
1046#ifdef USE_PARAMCACHE
1047 fval = func(
x.data());
1049 fval = func(
x.data(),
p);
1054 const auto x =
data.GetCoordComponent(i, 0);
1055#ifdef USE_PARAMCACHE
1068 double weight =
data.Weight(i);
1075 W2 = weight * weight;
1090 auto redFunction = [](
const std::vector<LikelihoodAux<double>> &
objs){
1092 for (
auto &
l :
objs ) {
1102 Warning(
"FitUtil::EvaluateLogL",
"Multithread execution policy requires IMT, which is disabled. Changing "
1103 "to ROOT::EExecutionPolicy::kSequential.");
1112 for (
unsigned int i=0; i<
n; ++i) {
1131 Error(
"FitUtil::EvaluateLogL",
"Execution policy unknown. Available choices:\n ROOT::EExecutionPolicy::kSequential (default)\n ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1136 double extendedTerm = 0;
1142 std::vector<double>
xmin(
data.NDim());
1143 std::vector<double>
xmax(
data.NDim());
1146 if (
data.Range().Size() > 0 ) {
1156 if (func(
xmin.data(),
p) != 0 || func(
xmax.data(),
p) != 0) {
1157 MATH_ERROR_MSG(
"FitUtil::EvaluateLogLikelihood",
"A range has not been set and the function is not zero at +/- inf");
1166 extendedTerm = -
nuTot;
1179 logl += extendedTerm;
1184 std::cout <<
"Evaluated log L for parameters (";
1185 for (
unsigned int ip = 0;
ip < func.NPar(); ++
ip)
1186 std::cout <<
" " <<
p[
ip];
1187 std::cout <<
") fval = " << -
logl << std::endl;
1203 unsigned int npar = func.NPar();
1209 std::cout <<
"\n===> Evaluate Gradient for parameters ";
1211 std::cout <<
" " <<
p[
ip];
1215 const double kdmax1 = std::sqrt(std::numeric_limits<double>::max());
1223 const double *
x =
nullptr;
1224 std::vector<double>
xc;
1225 if (
data.NDim() > 1) {
1227 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
1228 xc[
j] = *
data.GetCoordComponent(i,
j);
1231 x =
data.GetCoordComponent(i, 0);
1234 double fval = func(
x,
p);
1240 if (i < 5 || (i >
data.Size()-5) ) {
1241 if (
data.NDim() > 1) std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" func " <<
fval
1243 else std::cout << i <<
" x " <<
x[0] <<
" gradient " <<
gradFunc[0] <<
" " <<
gradFunc[1] <<
" " <<
gradFunc[3] << std::endl;
1277 std::vector<double>
g(
npar);
1282 Warning(
"FitUtil::EvaluateLogLGradient",
"Multithread execution policy requires IMT, which is disabled. Changing "
1283 "to ROOT::EExecutionPolicy::kSequential.");
1303 Error(
"FitUtil::EvaluateLogLGradient",
"Execution policy unknown. Available choices:\n "
1304 "ROOT::EExecutionPolicy::kSequential (default)\n "
1305 "ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1314 std::copy(
g.begin(),
g.end(), grad);
1318 std::cout <<
"FitUtil.cxx : Final gradient ";
1319 for (
unsigned int param = 0; param <
npar; param++) {
1320 std::cout <<
" " << grad[param];
1333 const double *
x1 =
data.GetPoint(i,
y);
1340 const double *
x2 =
nullptr;
1342 double binVolume = 1;
1343 std::vector<double>
xc;
1345 unsigned int ndim =
data.NDim();
1347 for (
unsigned int j = 0;
j < ndim; ++
j) {
1348 double x2j =
data.GetBinUpEdgeComponent(i,
j);
1349 binVolume *= std::abs(
x2j-
x1[
j] );
1353 binVolume /=
data.RefVolume();
1364 std::vector<double>
vx2(
data.NDim());
1365 data.GetBinUpEdgeCoordinates(i,
vx2.data());
1387 return std::numeric_limits<double>::quiet_NaN();
1393 gfunc->ParameterGradient(
x ,
p,
g );
1395 if (!
gfunc->HasParameterHessian())
1396 return std::numeric_limits<double>::quiet_NaN();
1399 return std::numeric_limits<double>::quiet_NaN();
1419 double coeffGrad = (
fval > 0) ? (1. -
y/
fval) : ( (
y > 0) ? std::sqrt( std::numeric_limits<double>::max() ) : 1. );
1420 double coeffHess = (
fval > 0) ?
y/(
fval*
fval) : ( (
y > 0) ? std::sqrt( std::numeric_limits<double>::max() ) : 0. );
1425 for (
unsigned int k = 0; k <
npar; ++k) {
1428 for (
unsigned int l = k;
l <
npar; ++
l) {
1429 unsigned int idx = k +
l * (
l + 1) / 2;
1448 std::cout <<
"x = " <<
x[0] <<
" y " <<
y <<
" fval " <<
fval <<
" logPdf = " <<
nlogPdf <<
" gradient : ";
1449 for (
unsigned int ipar = 0; ipar <
npar; ++ipar)
1450 std::cout <<
g[ipar] <<
"\t";
1452 std::cout <<
"\thessian : ";
1453 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
1456 std::cout <<
h[ipar +
jpar * (
jpar + 1) / 2] <<
"\t";
1461 std::cout << std::endl;
1489 unsigned int n =
data.Size();
1491#ifdef USE_PARAMCACHE
1492 (
const_cast<IModelFunction &
>(func)).SetParameters(
p);
1512 std::cout <<
"Evaluate PoissonLogL for params = [ ";
1513 for (
unsigned int j = 0;
j < func.NPar(); ++
j) std::cout <<
p[
j] <<
" , ";
1514 std::cout <<
"] - data size = " <<
n <<
" useBinIntegral " <<
useBinIntegral <<
" useBinVolume "
1524#ifdef USE_PARAMCACHE
1531 auto x1 =
data.GetCoordComponent(i, 0);
1532 auto y = *
data.ValuePtr(i);
1534 const double *
x =
nullptr;
1535 std::vector<double>
xc;
1537 double binVolume = 1.0;
1540 unsigned int ndim =
data.NDim();
1542 for (
unsigned int j = 0;
j < ndim; ++
j) {
1543 double xx = *
data.GetCoordComponent(i,
j);
1544 double x2 =
data.GetBinUpEdgeComponent(i,
j);
1545 binVolume *= std::abs(
x2 -
xx);
1551 }
else if (
data.NDim() > 1) {
1554 for (
unsigned int j = 1;
j <
data.NDim(); ++
j) {
1555 xc[
j] = *
data.GetCoordComponent(i,
j);
1563#ifdef USE_PARAMCACHE
1571 std::vector<double>
x2(
data.NDim());
1572 data.GetBinUpEdgeCoordinates(i,
x2.data());
1582 std::cout <<
"evt " << i <<
" x = [ ";
1583 for (
unsigned int j = 0;
j < func.NDim(); ++
j) std::cout <<
x[
j] <<
" , ";
1586 std::cout <<
"x2 = [ ";
1587 for (
unsigned int j = 0;
j < func.NDim(); ++
j) std::cout <<
data.GetBinUpEdgeComponent(i,
j) <<
" , ";
1590 std::cout <<
" y = " <<
y <<
" fval = " <<
fval << std::endl;
1608 double weight = 1.0;
1610 double error =
data.Error(i);
1611 weight = (error * error) /
y;
1616 weight =
data.SumOfError2()/
data.SumOfContent();
1636 std::cout <<
" nll = " <<
nloglike << std::endl;
1651 Warning(
"FitUtil::EvaluatePoissonLogL",
"Multithread execution policy requires IMT, which is disabled. Changing "
1652 "to ROOT::EExecutionPolicy::kSequential.");
1659 for (
unsigned int i = 0; i <
n; ++i) {
1672 Error(
"FitUtil::EvaluatePoissonLogL",
1673 "Execution policy unknown. Available choices:\n ROOT::EExecutionPolicy::kSequential (default)\n ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1677 std::cout <<
"Loglikelihood = " << res << std::endl;
1693#ifdef USE_PARAMCACHE
1713 unsigned int npar = func.NPar();
1721 const auto x1 =
data.GetCoordComponent(i, 0);
1722 const auto y =
data.Value(i);
1729 const double *
x =
nullptr;
1730 std::vector<double>
xc;
1732 unsigned ndim =
data.NDim();
1733 double binVolume = 1.0;
1738 for (
unsigned int j = 0;
j < ndim; ++
j) {
1739 double x1_j = *
data.GetCoordComponent(i,
j);
1740 double x2_j =
data.GetBinUpEdgeComponent(i,
j);
1741 binVolume *= std::abs(
x2_j -
x1_j);
1749 }
else if (ndim > 1) {
1752 for (
unsigned int j = 1;
j < ndim; ++
j)
1753 xc[
j] = *
data.GetCoordComponent(i,
j);
1765 std::vector<double>
x2(
data.NDim());
1766 data.GetBinUpEdgeCoordinates(i,
x2.data());
1776 if (i < 5 || (i >
data.Size()-5) ) {
1777 if (
data.NDim() > 1) std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" func " <<
fval
1779 else std::cout << i <<
" x " <<
x[0] <<
" gradient " <<
gradFunc[0] <<
" " <<
gradFunc[1] <<
" " <<
gradFunc[3] << std::endl;
1785 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
1795 const double kdmax1 = std::sqrt(std::numeric_limits<double>::max());
1822 std::vector<double>
g(
npar);
1827 Warning(
"FitUtil::EvaluatePoissonLogLGradient",
1828 "Multithread execution policy requires IMT, which is disabled. Changing "
1829 "to ROOT::EExecutionPolicy::kSequential.");
1854 Error(
"FitUtil::EvaluatePoissonLogLGradient",
1855 "Execution policy unknown. Available choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
1864 std::copy(
g.begin(),
g.end(), grad);
1867 std::cout <<
"***** Final gradient : ";
1868 for (
unsigned int ii = 0;
ii<
npar; ++
ii) std::cout << grad[
ii] <<
" ";
1877 if (nEvents/
ncpu < 1000)
return ncpu;
1878 return nEvents/1000;
1882#ifdef R__HAS_STD_EXPERIMENTAL_SIMD
1890 return T{std::numeric_limits<typename T::value_type>::max()};
1893template <
typename V,
typename S>
1894void Load(V &
v, S
const *ptr)
1896 for (
size_t i = 0; i < V::size(); ++i)
1900template <
typename T>
1903 typename T::value_type
result(0);
1904 for (
size_t i = 0; i < T::size(); ++i) {
1910template <
typename T>
1911bool MaskEmpty(T
mask)
1913 for (
size_t i = 0; i < T::size(); ++i)
1919template <
class T = ROOT::Double_v>
1923 for (
unsigned j = 0;
j < T::size();
j++) {
1941 unsigned int n =
data.Size();
1945#ifdef USE_PARAMCACHE
1954 Error(
"FitUtil::EvaluateChi2",
1955 "The vectorized implementation doesn't support Integrals, BinVolume or ExpErrors\n. Aborting operation.");
1959 double maxResValue = std::numeric_limits<double>::max() /
n;
1960 std::vector<double>
ones{1., 1., 1., 1.};
1961 auto vecSize = Double_v::size();
1973 std::vector<Double_v>
xc;
1974 if (
data.NDim() > 1) {
1977 for (
unsigned int j = 1;
j <
data.NDim(); ++
j)
1986#ifdef USE_PARAMCACHE
2010 Warning(
"FitUtil::EvaluateChi2",
"Multithread execution policy requires IMT, which is disabled. Changing "
2011 "to ::ROOT::EExecutionPolicy::kSequential.");
2027 Error(
"FitUtil::EvaluateChi2",
2028 "Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n "
2029 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2044 unsigned int n =
data.Size();
2051#ifdef USE_PARAMCACHE
2059 if (
data.NDim() == 1) {
2061 Load(
x,
data.GetCoordComponent(0, 0));
2064 std::vector<Double_v>
x(
data.NDim());
2065 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
2066 Load(
x[
j],
data.GetCoordComponent(0,
j));
2076 std::vector<double>
xmin(
data.NDim());
2077 std::vector<double>
xmax(
data.NDim());
2080 if (
data.Range().Size() > 0) {
2096 "A range has not been set and the function is not zero at +/- inf");
2105 auto vecSize = Double_v::size();
2118 unsigned int ndim =
data.NDim();
2119 std::vector<Double_v>
xc;
2123 for (
unsigned int j = 1;
j < ndim; ++
j)
2130#ifdef USE_PARAMCACHE
2139 std::cout << i <<
" x " <<
x[0] <<
" fval = " <<
fval;
2141 std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" fval = " <<
fval;
2152 if (
data.WeightsPtr(i) ==
nullptr)
2162 W2 = weight * weight;
2168 std::cout <<
" " <<
fval <<
" logfval " <<
logval << std::endl;
2175 auto redFunction = [](
const std::vector<LikelihoodAux<Double_v>> &
objs) {
2176 return std::accumulate(
2186 Warning(
"FitUtil::EvaluateLogL",
"Multithread execution policy requires IMT, which is disabled. Changing "
2187 "to ::ROOT::EExecutionPolicy::kSequential.");
2206 Error(
"FitUtil::EvaluateLogL",
2207 "Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n "
2208 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2233 double extendedTerm = 0;
2239 std::vector<double>
xmin(
data.NDim());
2240 std::vector<double>
xmax(
data.NDim());
2243 if (
data.Range().Size() > 0) {
2258 "A range has not been set and the function is not zero at +/- inf");
2267 extendedTerm = -
nuTot;
2280 logl += extendedTerm;
2284 std::cout <<
"Evaluated log L for parameters (";
2285 for (
unsigned int ip = 0;
ip < func.NPar(); ++
ip)
2286 std::cout <<
" " <<
p[
ip];
2287 std::cout <<
") nll = " << -
logl << std::endl;
2312#ifdef USE_PARAMCACHE
2315 auto vecSize = Double_v::size();
2319 Error(
"FitUtil::EvaluateChi2",
2320 "The vectorized implementation doesn't support Integrals or BinVolume\n. Aborting operation.");
2328 if (
data.NDim() > 1) {
2329 std::vector<Double_v>
x(
data.NDim());
2330 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
2332#ifdef USE_PARAMCACHE
2333 fval = func(
x.data());
2335 fval = func(
x.data(),
p);
2341#ifdef USE_PARAMCACHE
2366 where(
m, weight) = (error * error) /
y;
2397 Warning(
"FitUtil::Evaluate<T>::EvalPoissonLogL",
2398 "Multithread execution policy requires IMT, which is disabled. Changing "
2399 "to ::ROOT::EExecutionPolicy::kSequential.");
2406 for (
unsigned int i = 0; i < (
data.Size() /
vecSize); i++) {
2416 Error(
"FitUtil::Evaluate<T>::EvalPoissonLogL",
2417 "Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n "
2418 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2458 if (
data.HaveCoordErrors()) {
2460 "Error on the coordinates are not used in calculating Chi2 gradient");
2471 Error(
"FitUtil::EvaluateChi2Gradient",
"The vectorized implementation doesn't support Integrals,"
2472 "BinVolume or ExpErrors\n. Aborting operation.");
2474 unsigned int npar = func.NPar();
2475 auto vecSize = Double_v::size();
2504 unsigned int ndim =
data.NDim();
2507 std::vector<Double_v>
xc;
2511 for (
unsigned int j = 1;
j < ndim; ++
j)
2528 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
2558 std::vector<double>
g(
npar);
2566 Warning(
"FitUtil::EvaluateChi2Gradient",
"Multithread execution policy requires IMT, which is disabled. Changing "
2567 "to ::ROOT::EExecutionPolicy::kSequential.");
2584 Error(
"FitUtil::EvaluateChi2Gradient",
2585 "Execution policy unknown. Available choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
2594 for (
unsigned int param = 0; param <
npar; param++) {
2599 for (
unsigned int param = 0; param <
npar; param++) {
2608 for (size_t i = 0; i < Double_v::mask_type::size(); ++i)
2609 if (!validPoints[i])
2616 for (
unsigned int i = 0; i <
vecSize; i++) {
2626 "Too many points rejected for overflow in gradient calculation");
2632 const double *
p,
double *grad,
unsigned int &,
2646 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"The vectorized implementation doesn't support Integrals,"
2647 "BinVolume or ExpErrors\n. Aborting operation.");
2649 unsigned int npar = func.NPar();
2650 auto vecSize = Double_v::size();
2668 unsigned ndim =
data.NDim();
2669 std::vector<Double_v>
xc;
2673 for (
unsigned int j = 1;
j < ndim; ++
j)
2684 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
2706 if (i < 5 || (i >
data.Size() - 5)) {
2707 if (
data.NDim() > 1)
2708 std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1];
2710 std::cout << i <<
" x " <<
x[0];
2711 std::cout <<
" func " <<
fval <<
" gradient ";
2742 Warning(
"FitUtil::EvaluatePoissonLogLGradient",
2743 "Multithread execution policy requires IMT, which is disabled. Changing "
2744 "to ::ROOT::EExecutionPolicy::kSequential.");
2761 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"Execution policy unknown. Available choices:\n "
2762 "::ROOT::EExecutionPolicy::kSequential (default)\n "
2763 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2772 for (
unsigned int param = 0; param <
npar; param++) {
2777 for (
unsigned int param = 0; param <
npar; param++) {
2782 std::cout <<
"***** Final gradient : ";
2784 std::cout << grad[
ii] <<
" ";
2790 const double *
p,
double *grad,
unsigned int &,
2800 unsigned int npar = func.NPar();
2801 auto vecSize = Double_v::size();
2806 std::cout <<
"\n===> Evaluate Gradient for parameters ";
2808 std::cout <<
" " <<
p[
ip];
2826 unsigned int ndim =
data.NDim();
2827 std::vector<Double_v>
xc(ndim);
2831 for (
unsigned int j = 1;
j < ndim; ++
j)
2844 std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" gradient " <<
gradFunc[0] <<
" " <<
gradFunc[1]
2845 <<
" " <<
gradFunc[3] << std::endl;
2847 std::cout << i <<
" x " <<
x[0] <<
" gradient " <<
gradFunc[0] <<
" " <<
gradFunc[1] <<
" "
2885 std::vector<double>
g(
npar);
2893 Warning(
"FitUtil::EvaluateLogLGradient",
"Multithread execution policy requires IMT, which is disabled. Changing "
2894 "to ::ROOT::EExecutionPolicy::kSequential.");
2911 Error(
"FitUtil::EvaluateLogLGradient",
"Execution policy unknown. Available choices:\n "
2912 "::ROOT::EExecutionPolicy::kSequential (default)\n "
2913 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2922 for (
unsigned int param = 0; param <
npar; param++) {
2927 for (
unsigned int param = 0; param <
npar; param++) {
2932 std::cout <<
"Final gradient ";
2933 for (
unsigned int param = 0; param <
npar; param++) {
2934 std::cout <<
" " << grad[param];
#define MATH_ERROR_MSG(loc, str)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void gc
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 ...
SimpleGradientCalculator(int gdim, const IModelFunction &func, double eps=2.E-8, int istrat=1)
const IModelFunction & fFunc
std::vector< double > fVec
double ParameterDerivative(const double *x, const double *p, int ipar) const
void Gradient(const double *x, const double *p, double f0, double *g)
unsigned int NDim() const
void ParameterGradient(const double *x, const double *p, double f0, double *g)
unsigned int NPar() const
double DoParameterDerivative(const double *x, const double *p, double f0, int k) const
Class describing the un-binned data sets (just x coordinates values) of any dimensions.
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
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 ...
OneDimMultiFunctionAdapter class to wrap a multidimensional function in one dimensional one.
User class for calculating the derivatives of a function.
const_iterator begin() const
const_iterator end() const
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,...
Type
enumeration specifying the integration types.
@ kGAUSS
simple Gauss integration method with fixed rule
@ 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
void CalculateGradientIntegral(const GFunc &gfunc, const double *x1, const double *x2, const double *p, double *g)
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.
double CorrectValue(double rval)
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, ::ROOT::EExecutionPolicy executionPolicy=::ROOT::EExecutionPolicy::kSequential, unsigned nChunks=0)
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.
bool CheckInfNaNValue(double &rval)
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...
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.
DataOptions : simple structure holding the options on how the data are filled.
double operator()(const double *x, const double *p) const
void SetDerivComponent(unsigned int ipar)
unsigned int NDim() const
ParamDerivFunc(const GradFunc &f)