28#include "Math/Minimizer1D.h"
60 print.
Debug(
"doing line search along given step and gdel = s^t*g = ",
gdel);
72 for (
unsigned int i = 0; i < step.
size(); i++) {
75 double ratio = std::fabs(
st.Vec()(i) / step(i));
85 double f0 =
st.Fval();
86 double f1 =
fcn(
st.Vec() + step);
129#ifdef TRY_OPPOSIT_DIR
137#ifdef TRY_OPPOSITE_DIR
146 print.
Trace(
"slam larger than max value - set to",
slamax);
154 print.
Trace(
"slam smaller than",
slamin,
"return");
178#ifdef TRY_OPPOSITE_DIR
210 print.
Trace(
"after initial 2-point iter:",
'\n',
" x0, x1, x2:",
p0.X(),
p1.X(),
slam,
'\n',
" f0, f1, f2:",
p0.Y(),
219 print.
Trace(
"Iteration",
niter,
'\n',
" x0, x1, x2:",
p0.X(),
p1.X(),
p2.X(),
'\n',
" f0, f1, f2:",
p0.Y(),
220 p1.Y(),
p2.Y(),
'\n',
" slamax :",
slamax,
'\n',
" p2-p0,p1 :",
p2.Y() -
p0.Y(),
p2.Y() -
p1.Y(),
221 '\n',
" a, b, c :",
pb.A(),
pb.B(),
pb.C());
222 if (
pb.A() <
prec.Eps2()) {
267 print.
Trace(
"f3", f3,
"f3-p(2-0).Y()", f3 -
p2.Y(), f3 -
p1.Y(), f3 -
p0.Y());
269 if (f3 >
p0.Y() && f3 >
p1.Y() && f3 >
p2.Y()) {
270 print.
Trace(
"f3 worse than all three previous");
283 print.
Debug(
"Exhausted max number of iterations ",
maxiter,
" return");
289 if (
p0.Y() >
p1.Y() &&
p0.Y() >
p2.Y())
291 else if (
p1.Y() >
p0.Y() &&
p1.Y() >
p2.Y())
309 print.
Debug(
"f1, f2 =",
p0.Y(),
p1.Y(),
'\n',
"x1, x2 =",
p0.X(),
p1.X(),
'\n',
"x, f =",
xvmin,
fvmin);
322 MnPrint print(
"MnLineSearch::CubicSearch");
324 print.Trace(
"gdel",
gdel,
"g2del",
g2del,
"step", step);
334 for (
unsigned int i = 0; i < step.
size(); i++) {
337 double ratio = std::fabs(
st.Vec()(i) / step(i));
347 double f0 =
st.Fval();
348 double f1 =
fcn(
st.Vec() + step);
351 print.Debug(
"f0",
f0,
"f1",
f1);
389 print.Debug(
"Vec:\n ",
bVec);
393 print.Warn(
"Inversion failed - return");
429 print.Debug(
"try with slam 2",
slam2,
"f2", f2);
452 print.Debug(
"try with slam 1",
slam1,
"f3", f3);
479 print.Debug(
"iter",
niter,
"test approx deriv ad second deriv at",
slam,
"fp", fp);
482 double h = 0.001 *
slam;
483 double fh =
fcn(
st.Vec() + (
slam +
h) * step);
484 double fl =
fcn(
st.Vec() + (
slam -
h) * step);
485 double df = (fh - fl) / (2. *
h);
486 double df2 = (fh + fl - 2. * fp) / (
h *
h);
488 print.Debug(
"deriv", df,
df2);
491 if (std::fabs(df) <
prec.Eps() && std::fabs(
df2) <
prec.Eps()) {
496 }
else if (std::fabs(
df2) <= 0) {
499 return MnParabolaPoint(
slam, fp);
510 return MnParabolaPoint(
slam, fp);
522 ProjectedFcn(
const MnFcn &
fcn,
const MinimumParameters &
pa,
const MnAlgebraicVector &step)
523 : fFcn(
fcn), fPar(
pa), fStep(step)
530 double DoEval(
double x)
const {
return fFcn(fPar.Vec() +
x * fStep); }
533 const MinimumParameters &fPar;
537MnParabolaPoint MnLineSearch::BrentSearch(
const MnFcn &
fcn,
const MinimumParameters &
st,
const MnAlgebraicVector &step,
538 double gdel,
double g2del,
const MnMachinePrecision &
prec)
const
540 MnPrint print(
"MnLineSearch::BrentSearch");
542 print.Debug(
"gdel",
gdel,
"g2del",
g2del);
544 print.Debug([&](std::ostream &os) {
545 for (
unsigned int i = 0; i < step.size(); ++i) {
547 os <<
"step(i) " << step(i) <<
'\n';
548 std::cout <<
"par(i) " <<
st.Vec()(i) <<
'\n';
558 double f0 =
st.Fval();
559 double f1 =
fcn(
st.Vec() + step);
564 print.Debug(
"f0",
f0,
"f1",
f1);
607 print.Debug(
"Vec:\n ",
bVec);
611 print.Warn(
"Inversion failed - return");
644 print.Debug(
"slam1",
slam1,
"slam2",
slam2,
"f(slam1)",
fs1,
"f(slam2)",
fs2);
674 print.Debug(
"f(0)", func(0.),
"f1", func(1.0),
"f(3)", func(3.0),
"f(5)", func(5.0));
690 print.Debug(
"iter", iter,
"a",
a,
"b",
b,
"x0", x0,
"fa", fa,
"fb", fb,
"f0",
f0);
691 if (fa <=
f0 || fb <=
f0) {
704 if (std::fabs((fa - f2) / (
a -
x2)) >
toler) {
716 x0 = x0 + dir * delta;
719 if (std::fabs((
f0 - fa) / (x0 -
a)) <
toler) {
727 print.Info(
"A: Done a reset - scan in opposite direction!");
746 if (std::fabs((fb - f2) / (
x2 -
b)) >
toler) {
758 x0 = x0 + dir * delta;
761 if (std::fabs((
f0 - fb) / (x0 -
b)) <
toler) {
769 print.Info(
"B: Done a reset - scan in opposite direction!");
772 if (x0 >
a && x0 <
b)
786 print.Debug(
"new x0", x0,
"f0",
f0);
798 if (
f0 > fa ||
f0 > fb)
803 print.Info(
"1D minimization using",
minType);
805 ROOT::Math::Minimizer1D min(
minType);
807 min.SetFunction(func, x0,
a,
b);
810 MnPrint::info(
"result of GSL 1D minimization:",
ret,
"niter", min.Iterations(),
"xmin", min.XMinimum(),
"fmin",
813 return MnParabolaPoint(min.XMinimum(), min.FValMinimum());
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
SMatrix: a generic fixed size D1 x D2 Matrix class.
SVector: a generic fixed size Vector class.
unsigned int size() const
Wrapper class to FCNBase interface used internally by Minuit.
MnParabolaPoint operator()(const MnFcn &, const MinimumParameters &, const MnAlgebraicVector &, double, const MnMachinePrecision &) const
Perform a line search from position defined by the vector st along the direction step,...
Sets the relative floating point (double) arithmetic precision.
This class defines a parabola of the form a*x*x + b*x + c.
void Debug(const Ts &... args)
void Trace(const Ts &... args)
Type
Enumeration with One Dimensional Minimizer Algorithms.
int iterate(rng_state_t *X)
LAVector MnAlgebraicVector
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...