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;
371 double resval = tmp * tmp;
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");
434 unsigned int n =
data.Size();
437 std::cout <<
"\n\nFit data size = " <<
n << std::endl;
438 std::cout <<
"evaluate effective chi2 using function " << &func <<
" " <<
p << std::endl;
449 unsigned int ndim = func.
NDim();
454 double maxResValue = std::numeric_limits<double>::max() /
n;
458 for (
unsigned int i = 0; i <
n; ++ i) {
462 const double *
x =
data.GetPoint(i,
y);
464 double fval = func(
x,
p );
470 const double *
ex =
nullptr;
471 if (!
data.HaveAsymErrors() )
484 while (
j < ndim &&
ex[
j] == 0.) {
j++; }
504 std::cout <<
"error for coord " <<
icoord <<
" = " <<
ex[
icoord] <<
" deriv " <<
deriv << std::endl;
509 double w2 = (
e2 > 0) ? 1.0/
e2 : 0;
513 std::cout <<
x[0] <<
" " <<
y <<
" ex " <<
ex[0] <<
" ey " <<
ey <<
" params : ";
514 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar)
515 std::cout <<
p[ipar] <<
"\t";
516 std::cout <<
"\tfval = " <<
fval <<
"\tresval = " <<
resval << std::endl;
534 std::cout <<
"chi2 = " <<
chi2 <<
" n = " <<
nPoints << std::endl;
551 MATH_ERROR_MSG(
"FitUtil::EvaluateChi2Residual",
"Error on the coordinates are not used in calculating Chi2 residual");
565 unsigned int ndim =
data.NDim();
566 double binVolume = 1.0;
567 const double *
x2 =
nullptr;
570 std::vector<double>
xc;
575 for (
unsigned int j = 0;
j < ndim; ++
j) {
576 binVolume *= std::abs(
x2[
j]-
x1[
j] );
627 return std::numeric_limits<double>::quiet_NaN();
653 for (
unsigned int k = 0; k <
npar; ++k) {
657 for (
unsigned int l = 0;
l <= k;
l++) {
658 unsigned int idx =
l + k * (k + 1) / 2;
667 h[idx] += 2. *
g[k]*
g[
l];
687 if (
data.HaveCoordErrors()) {
689 "Error on the coordinates are not used in calculating Chi2 gradient");
693 const IGradModelFunction *
fg =
dynamic_cast<const IGradModelFunction *
>(&
f);
696 const IGradModelFunction &func = *
fg;
699 std::cout <<
"\n\nFit data size = " <<
nPoints << std::endl;
700 std::cout <<
"evaluate chi2 using function gradient " << &func <<
" " <<
p << std::endl;
719 unsigned int npar = func.NPar();
729 const auto x1 =
data.GetCoordComponent(i, 0);
730 const auto y =
data.Value(i);
737 const double *
x =
nullptr;
738 std::vector<double>
xc;
740 unsigned int ndim =
data.NDim();
741 double binVolume = 1;
744 for (
unsigned int j = 0;
j < ndim; ++
j) {
745 double x1_j = *
data.GetCoordComponent(i,
j);
746 double x2_j =
data.GetBinUpEdgeComponent(i,
j);
755 }
else if (ndim > 1) {
758 for (
unsigned int j = 1;
j < ndim; ++
j)
759 xc[
j] = *
data.GetCoordComponent(i,
j);
769 std::vector<double>
x2(
data.NDim());
770 data.GetBinUpEdgeCoordinates(i,
x2.data());
780 std::cout <<
x[0] <<
" " <<
y <<
" " << 1. /
invError <<
" params : ";
781 for (
unsigned int ipar = 0; ipar <
npar; ++ipar)
782 std::cout <<
p[ipar] <<
"\t";
783 std::cout <<
"\tfval = " <<
fval << std::endl;
792 unsigned int ipar = 0;
793 for (; ipar <
npar; ++ipar) {
830 std::vector<double>
g(
npar);
835 Warning(
"FitUtil::EvaluateChi2Gradient",
"Multithread execution policy requires IMT, which is disabled. Changing "
836 "to ROOT::EExecutionPolicy::kSequential.");
860 Error(
"FitUtil::EvaluateChi2Gradient",
861 "Execution policy unknown. Available choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
879 "Error - too many points rejected for overflow in gradient calculation");
883 std::copy(
g.begin(),
g.end(), grad);
902 const double *
x =
data.Coords(i);
903 double fval = func (
x,
p );
906 if (
g ==
nullptr)
return logPdf;
914 gfunc->ParameterGradient(
x ,
p,
g );
923 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar) {
928 std::cout <<
x[i] <<
"\t";
929 std::cout <<
"\tpar = [ " << func.
NPar() <<
" ] = ";
930 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar)
931 std::cout <<
p[ipar] <<
"\t";
932 std::cout <<
"\tfval = " <<
fval;
933 std::cout <<
"\tgrad = [ ";
934 for (
unsigned int ipar = 0; ipar < func.
NPar(); ++ipar)
935 std::cout <<
g[ipar] <<
"\t";
936 std::cout <<
" ] " << std::endl;
949 unsigned int n =
data.Size();
966 if (
data.NDim() == 1) {
967 const double *
x =
data.GetCoordComponent(0,0);
971 std::vector<double>
x(
data.NDim());
972 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
973 x[
j] = *
data.GetCoordComponent(0,
j);
982 std::vector<double>
xmin(
data.NDim());
983 std::vector<double>
xmax(
data.NDim());
986 if (
data.Range().Size() > 0) {
996 if (func(
xmin.data(),
p) != 0 || func(
xmax.data(),
p) != 0) {
998 "A range has not been set and the function is not zero at +/- inf");
1012 if (
data.NDim() > 1) {
1013 std::vector<double>
x(
data.NDim());
1014 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
1015 x[
j] = *
data.GetCoordComponent(i,
j);
1016#ifdef USE_PARAMCACHE
1017 fval = func(
x.data());
1019 fval = func(
x.data(),
p);
1024 const auto x =
data.GetCoordComponent(i, 0);
1025#ifdef USE_PARAMCACHE
1038 double weight =
data.Weight(i);
1045 W2 = weight * weight;
1060 auto redFunction = [](
const std::vector<LikelihoodAux<double>> &
objs){
1062 for (
auto &
l :
objs ) {
1072 Warning(
"FitUtil::EvaluateLogL",
"Multithread execution policy requires IMT, which is disabled. Changing "
1073 "to ROOT::EExecutionPolicy::kSequential.");
1082 for (
unsigned int i=0; i<
n; ++i) {
1101 Error(
"FitUtil::EvaluateLogL",
"Execution policy unknown. Available choices:\n ROOT::EExecutionPolicy::kSequential (default)\n ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1106 double extendedTerm = 0;
1112 std::vector<double>
xmin(
data.NDim());
1113 std::vector<double>
xmax(
data.NDim());
1116 if (
data.Range().Size() > 0 ) {
1126 if (func(
xmin.data(),
p) != 0 || func(
xmax.data(),
p) != 0) {
1127 MATH_ERROR_MSG(
"FitUtil::EvaluateLogLikelihood",
"A range has not been set and the function is not zero at +/- inf");
1136 extendedTerm = -
nuTot;
1149 logl += extendedTerm;
1154 std::cout <<
"Evaluated log L for parameters (";
1155 for (
unsigned int ip = 0;
ip < func.NPar(); ++
ip)
1156 std::cout <<
" " <<
p[
ip];
1157 std::cout <<
") fval = " << -
logl << std::endl;
1173 unsigned int npar = func.NPar();
1179 std::cout <<
"\n===> Evaluate Gradient for parameters ";
1181 std::cout <<
" " <<
p[
ip];
1185 const double kdmax1 = std::sqrt(std::numeric_limits<double>::max());
1193 const double *
x =
nullptr;
1194 std::vector<double>
xc;
1195 if (
data.NDim() > 1) {
1197 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
1198 xc[
j] = *
data.GetCoordComponent(i,
j);
1201 x =
data.GetCoordComponent(i, 0);
1204 double fval = func(
x,
p);
1210 if (i < 5 || (i >
data.Size()-5) ) {
1211 if (
data.NDim() > 1) std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" func " <<
fval
1213 else std::cout << i <<
" x " <<
x[0] <<
" gradient " <<
gradFunc[0] <<
" " <<
gradFunc[1] <<
" " <<
gradFunc[3] << std::endl;
1247 std::vector<double>
g(
npar);
1252 Warning(
"FitUtil::EvaluateLogLGradient",
"Multithread execution policy requires IMT, which is disabled. Changing "
1253 "to ROOT::EExecutionPolicy::kSequential.");
1273 Error(
"FitUtil::EvaluateLogLGradient",
"Execution policy unknown. Available choices:\n "
1274 "ROOT::EExecutionPolicy::kSequential (default)\n "
1275 "ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1284 std::copy(
g.begin(),
g.end(), grad);
1288 std::cout <<
"FitUtil.cxx : Final gradient ";
1289 for (
unsigned int param = 0; param <
npar; param++) {
1290 std::cout <<
" " << grad[param];
1303 const double *
x1 =
data.GetPoint(i,
y);
1310 const double *
x2 =
nullptr;
1312 double binVolume = 1;
1313 std::vector<double>
xc;
1315 unsigned int ndim =
data.NDim();
1317 for (
unsigned int j = 0;
j < ndim; ++
j) {
1318 double x2j =
data.GetBinUpEdgeComponent(i,
j);
1319 binVolume *= std::abs(
x2j-
x1[
j] );
1323 binVolume /=
data.RefVolume();
1334 std::vector<double>
vx2(
data.NDim());
1335 data.GetBinUpEdgeCoordinates(i,
vx2.data());
1357 return std::numeric_limits<double>::quiet_NaN();
1363 gfunc->ParameterGradient(
x ,
p,
g );
1365 if (!
gfunc->HasParameterHessian())
1366 return std::numeric_limits<double>::quiet_NaN();
1369 return std::numeric_limits<double>::quiet_NaN();
1389 double coeffGrad = (
fval > 0) ? (1. -
y/
fval) : ( (
y > 0) ? std::sqrt( std::numeric_limits<double>::max() ) : 1. );
1390 double coeffHess = (
fval > 0) ?
y/(
fval*
fval) : ( (
y > 0) ? std::sqrt( std::numeric_limits<double>::max() ) : 0. );
1395 for (
unsigned int k = 0; k <
npar; ++k) {
1398 for (
unsigned int l = k;
l <
npar; ++
l) {
1399 unsigned int idx = k +
l * (
l + 1) / 2;
1418 std::cout <<
"x = " <<
x[0] <<
" y " <<
y <<
" fval " <<
fval <<
" logPdf = " <<
nlogPdf <<
" gradient : ";
1419 for (
unsigned int ipar = 0; ipar <
npar; ++ipar)
1420 std::cout <<
g[ipar] <<
"\t";
1422 std::cout <<
"\thessian : ";
1423 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
1426 std::cout <<
h[ipar +
jpar * (
jpar + 1) / 2] <<
"\t";
1431 std::cout << std::endl;
1459 unsigned int n =
data.Size();
1461#ifdef USE_PARAMCACHE
1462 (
const_cast<IModelFunction &
>(func)).SetParameters(
p);
1482 std::cout <<
"Evaluate PoissonLogL for params = [ ";
1483 for (
unsigned int j = 0;
j < func.NPar(); ++
j) std::cout <<
p[
j] <<
" , ";
1484 std::cout <<
"] - data size = " <<
n <<
" useBinIntegral " <<
useBinIntegral <<
" useBinVolume "
1494#ifdef USE_PARAMCACHE
1501 auto x1 =
data.GetCoordComponent(i, 0);
1502 auto y = *
data.ValuePtr(i);
1504 const double *
x =
nullptr;
1505 std::vector<double>
xc;
1507 double binVolume = 1.0;
1510 unsigned int ndim =
data.NDim();
1512 for (
unsigned int j = 0;
j < ndim; ++
j) {
1513 double xx = *
data.GetCoordComponent(i,
j);
1514 double x2 =
data.GetBinUpEdgeComponent(i,
j);
1515 binVolume *= std::abs(
x2 -
xx);
1521 }
else if (
data.NDim() > 1) {
1524 for (
unsigned int j = 1;
j <
data.NDim(); ++
j) {
1525 xc[
j] = *
data.GetCoordComponent(i,
j);
1533#ifdef USE_PARAMCACHE
1541 std::vector<double>
x2(
data.NDim());
1542 data.GetBinUpEdgeCoordinates(i,
x2.data());
1552 std::cout <<
"evt " << i <<
" x = [ ";
1553 for (
unsigned int j = 0;
j < func.NDim(); ++
j) std::cout <<
x[
j] <<
" , ";
1556 std::cout <<
"x2 = [ ";
1557 for (
unsigned int j = 0;
j < func.NDim(); ++
j) std::cout <<
data.GetBinUpEdgeComponent(i,
j) <<
" , ";
1560 std::cout <<
" y = " <<
y <<
" fval = " <<
fval << std::endl;
1578 double weight = 1.0;
1580 double error =
data.Error(i);
1581 weight = (error * error) /
y;
1586 weight =
data.SumOfError2()/
data.SumOfContent();
1606 std::cout <<
" nll = " <<
nloglike << std::endl;
1621 Warning(
"FitUtil::EvaluatePoissonLogL",
"Multithread execution policy requires IMT, which is disabled. Changing "
1622 "to ROOT::EExecutionPolicy::kSequential.");
1629 for (
unsigned int i = 0; i <
n; ++i) {
1642 Error(
"FitUtil::EvaluatePoissonLogL",
1643 "Execution policy unknown. Available choices:\n ROOT::EExecutionPolicy::kSequential (default)\n ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
1647 std::cout <<
"Loglikelihood = " << res << std::endl;
1663#ifdef USE_PARAMCACHE
1683 unsigned int npar = func.NPar();
1691 const auto x1 =
data.GetCoordComponent(i, 0);
1692 const auto y =
data.Value(i);
1699 const double *
x =
nullptr;
1700 std::vector<double>
xc;
1702 unsigned ndim =
data.NDim();
1703 double binVolume = 1.0;
1708 for (
unsigned int j = 0;
j < ndim; ++
j) {
1709 double x1_j = *
data.GetCoordComponent(i,
j);
1710 double x2_j =
data.GetBinUpEdgeComponent(i,
j);
1711 binVolume *= std::abs(
x2_j -
x1_j);
1719 }
else if (ndim > 1) {
1722 for (
unsigned int j = 1;
j < ndim; ++
j)
1723 xc[
j] = *
data.GetCoordComponent(i,
j);
1735 std::vector<double>
x2(
data.NDim());
1736 data.GetBinUpEdgeCoordinates(i,
x2.data());
1746 if (i < 5 || (i >
data.Size()-5) ) {
1747 if (
data.NDim() > 1) std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" func " <<
fval
1749 else std::cout << i <<
" x " <<
x[0] <<
" gradient " <<
gradFunc[0] <<
" " <<
gradFunc[1] <<
" " <<
gradFunc[3] << std::endl;
1755 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
1765 const double kdmax1 = std::sqrt(std::numeric_limits<double>::max());
1792 std::vector<double>
g(
npar);
1797 Warning(
"FitUtil::EvaluatePoissonLogLGradient",
1798 "Multithread execution policy requires IMT, which is disabled. Changing "
1799 "to ROOT::EExecutionPolicy::kSequential.");
1824 Error(
"FitUtil::EvaluatePoissonLogLGradient",
1825 "Execution policy unknown. Available choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
1834 std::copy(
g.begin(),
g.end(), grad);
1837 std::cout <<
"***** Final gradient : ";
1838 for (
unsigned int ii = 0;
ii<
npar; ++
ii) std::cout << grad[
ii] <<
" ";
1847 if (nEvents/
ncpu < 1000)
return ncpu;
1848 return nEvents/1000;
1852#ifdef R__HAS_STD_EXPERIMENTAL_SIMD
1860 return T{std::numeric_limits<typename T::value_type>::max()};
1863template <
typename V,
typename S>
1864void Load(V &
v, S
const *ptr)
1866 for (
size_t i = 0; i < V::size(); ++i)
1870template <
typename T>
1873 typename T::value_type
result(0);
1874 for (
size_t i = 0; i < T::size(); ++i) {
1880template <
typename T>
1881bool MaskEmpty(T
mask)
1883 for (
size_t i = 0; i < T::size(); ++i)
1889template <
class T = ROOT::Double_v>
1893 for (
unsigned j = 0;
j < T::size();
j++) {
1911 unsigned int n =
data.Size();
1915#ifdef USE_PARAMCACHE
1924 Error(
"FitUtil::EvaluateChi2",
1925 "The vectorized implementation doesn't support Integrals, BinVolume or ExpErrors\n. Aborting operation.");
1929 double maxResValue = std::numeric_limits<double>::max() /
n;
1930 std::vector<double>
ones{1., 1., 1., 1.};
1931 auto vecSize = Double_v::size();
1943 std::vector<Double_v>
xc;
1944 if (
data.NDim() > 1) {
1947 for (
unsigned int j = 1;
j <
data.NDim(); ++
j)
1956#ifdef USE_PARAMCACHE
1980 Warning(
"FitUtil::EvaluateChi2",
"Multithread execution policy requires IMT, which is disabled. Changing "
1981 "to ::ROOT::EExecutionPolicy::kSequential.");
1997 Error(
"FitUtil::EvaluateChi2",
1998 "Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n "
1999 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2014 unsigned int n =
data.Size();
2021#ifdef USE_PARAMCACHE
2029 if (
data.NDim() == 1) {
2031 Load(
x,
data.GetCoordComponent(0, 0));
2034 std::vector<Double_v>
x(
data.NDim());
2035 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
2036 Load(
x[
j],
data.GetCoordComponent(0,
j));
2046 std::vector<double>
xmin(
data.NDim());
2047 std::vector<double>
xmax(
data.NDim());
2050 if (
data.Range().Size() > 0) {
2066 "A range has not been set and the function is not zero at +/- inf");
2075 auto vecSize = Double_v::size();
2088 unsigned int ndim =
data.NDim();
2089 std::vector<Double_v>
xc;
2093 for (
unsigned int j = 1;
j < ndim; ++
j)
2100#ifdef USE_PARAMCACHE
2109 std::cout << i <<
" x " <<
x[0] <<
" fval = " <<
fval;
2111 std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" fval = " <<
fval;
2122 if (
data.WeightsPtr(i) ==
nullptr)
2132 W2 = weight * weight;
2138 std::cout <<
" " <<
fval <<
" logfval " <<
logval << std::endl;
2145 auto redFunction = [](
const std::vector<LikelihoodAux<Double_v>> &
objs) {
2146 return std::accumulate(
2156 Warning(
"FitUtil::EvaluateLogL",
"Multithread execution policy requires IMT, which is disabled. Changing "
2157 "to ::ROOT::EExecutionPolicy::kSequential.");
2176 Error(
"FitUtil::EvaluateLogL",
2177 "Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n "
2178 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2203 double extendedTerm = 0;
2209 std::vector<double>
xmin(
data.NDim());
2210 std::vector<double>
xmax(
data.NDim());
2213 if (
data.Range().Size() > 0) {
2228 "A range has not been set and the function is not zero at +/- inf");
2237 extendedTerm = -
nuTot;
2250 logl += extendedTerm;
2254 std::cout <<
"Evaluated log L for parameters (";
2255 for (
unsigned int ip = 0;
ip < func.NPar(); ++
ip)
2256 std::cout <<
" " <<
p[
ip];
2257 std::cout <<
") nll = " << -
logl << std::endl;
2282#ifdef USE_PARAMCACHE
2285 auto vecSize = Double_v::size();
2289 Error(
"FitUtil::EvaluateChi2",
2290 "The vectorized implementation doesn't support Integrals or BinVolume\n. Aborting operation.");
2298 if (
data.NDim() > 1) {
2299 std::vector<Double_v>
x(
data.NDim());
2300 for (
unsigned int j = 0;
j <
data.NDim(); ++
j)
2302#ifdef USE_PARAMCACHE
2303 fval = func(
x.data());
2305 fval = func(
x.data(),
p);
2311#ifdef USE_PARAMCACHE
2336 where(
m, weight) = (error * error) /
y;
2367 Warning(
"FitUtil::Evaluate<T>::EvalPoissonLogL",
2368 "Multithread execution policy requires IMT, which is disabled. Changing "
2369 "to ::ROOT::EExecutionPolicy::kSequential.");
2376 for (
unsigned int i = 0; i < (
data.Size() /
vecSize); i++) {
2386 Error(
"FitUtil::Evaluate<T>::EvalPoissonLogL",
2387 "Execution policy unknown. Available choices:\n ::ROOT::EExecutionPolicy::kSequential (default)\n "
2388 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2428 if (
data.HaveCoordErrors()) {
2430 "Error on the coordinates are not used in calculating Chi2 gradient");
2441 Error(
"FitUtil::EvaluateChi2Gradient",
"The vectorized implementation doesn't support Integrals,"
2442 "BinVolume or ExpErrors\n. Aborting operation.");
2444 unsigned int npar = func.NPar();
2445 auto vecSize = Double_v::size();
2474 unsigned int ndim =
data.NDim();
2477 std::vector<Double_v>
xc;
2481 for (
unsigned int j = 1;
j < ndim; ++
j)
2498 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
2528 std::vector<double>
g(
npar);
2536 Warning(
"FitUtil::EvaluateChi2Gradient",
"Multithread execution policy requires IMT, which is disabled. Changing "
2537 "to ::ROOT::EExecutionPolicy::kSequential.");
2554 Error(
"FitUtil::EvaluateChi2Gradient",
2555 "Execution policy unknown. Available choices:\n 0: Serial (default)\n 1: MultiThread (requires IMT)\n");
2564 for (
unsigned int param = 0; param <
npar; param++) {
2569 for (
unsigned int param = 0; param <
npar; param++) {
2578 for (size_t i = 0; i < Double_v::mask_type::size(); ++i)
2579 if (!validPoints[i])
2586 for (
unsigned int i = 0; i <
vecSize; i++) {
2596 "Too many points rejected for overflow in gradient calculation");
2602 const double *
p,
double *grad,
unsigned int &,
2616 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"The vectorized implementation doesn't support Integrals,"
2617 "BinVolume or ExpErrors\n. Aborting operation.");
2619 unsigned int npar = func.NPar();
2620 auto vecSize = Double_v::size();
2638 unsigned ndim =
data.NDim();
2639 std::vector<Double_v>
xc;
2643 for (
unsigned int j = 1;
j < ndim; ++
j)
2654 for (
unsigned int ipar = 0; ipar <
npar; ++ipar) {
2676 if (i < 5 || (i >
data.Size() - 5)) {
2677 if (
data.NDim() > 1)
2678 std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1];
2680 std::cout << i <<
" x " <<
x[0];
2681 std::cout <<
" func " <<
fval <<
" gradient ";
2712 Warning(
"FitUtil::EvaluatePoissonLogLGradient",
2713 "Multithread execution policy requires IMT, which is disabled. Changing "
2714 "to ::ROOT::EExecutionPolicy::kSequential.");
2731 Error(
"FitUtil::EvaluatePoissonLogLGradient",
"Execution policy unknown. Available choices:\n "
2732 "::ROOT::EExecutionPolicy::kSequential (default)\n "
2733 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2742 for (
unsigned int param = 0; param <
npar; param++) {
2747 for (
unsigned int param = 0; param <
npar; param++) {
2752 std::cout <<
"***** Final gradient : ";
2754 std::cout << grad[
ii] <<
" ";
2760 const double *
p,
double *grad,
unsigned int &,
2770 unsigned int npar = func.NPar();
2771 auto vecSize = Double_v::size();
2776 std::cout <<
"\n===> Evaluate Gradient for parameters ";
2778 std::cout <<
" " <<
p[
ip];
2796 unsigned int ndim =
data.NDim();
2797 std::vector<Double_v>
xc(ndim);
2801 for (
unsigned int j = 1;
j < ndim; ++
j)
2814 std::cout << i <<
" x " <<
x[0] <<
" y " <<
x[1] <<
" gradient " <<
gradFunc[0] <<
" " <<
gradFunc[1]
2815 <<
" " <<
gradFunc[3] << std::endl;
2817 std::cout << i <<
" x " <<
x[0] <<
" gradient " <<
gradFunc[0] <<
" " <<
gradFunc[1] <<
" "
2855 std::vector<double>
g(
npar);
2863 Warning(
"FitUtil::EvaluateLogLGradient",
"Multithread execution policy requires IMT, which is disabled. Changing "
2864 "to ::ROOT::EExecutionPolicy::kSequential.");
2881 Error(
"FitUtil::EvaluateLogLGradient",
"Execution policy unknown. Available choices:\n "
2882 "::ROOT::EExecutionPolicy::kSequential (default)\n "
2883 "::ROOT::EExecutionPolicy::kMultiThread (requires IMT)\n");
2892 for (
unsigned int param = 0; param <
npar; param++) {
2897 for (
unsigned int param = 0; param <
npar; param++) {
2902 std::cout <<
"Final gradient ";
2903 for (
unsigned int param = 0; param <
npar; param++) {
2904 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)
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)