22class GradientCalculator;
25 const MnStrategy &,
unsigned int maxfcn,
double minedm)
const
34 print.
Debug(
"Running with maxfcn", maxfcn,
"minedm", minedm);
40 const unsigned int n =
x.
size();
49 const double wg = 1. /
double(
n);
50 const double alpha = 1.;
51 const double beta = 0.5;
52 const double gamma = 2.;
53 const double rhomin = 4.;
54 const double rhomax = 8.;
55 const double rho1 = 1. + alpha;
58 const double rho2 = 1. + alpha * gamma;
60 std::vector<std::pair<double, MnAlgebraicVector>> simpl;
62 simpl.emplace_back(seed.
Fval(),
x);
66 double amin = seed.
Fval();
67 double aming = seed.
Fval();
69 for (
unsigned int i = 0; i <
n; i++) {
70 double dmin = 8. * prec.
Eps2() * (std::abs(
x(i)) + prec.
Eps2());
83 simpl.emplace_back(tmp,
x);
88 print.
Debug([&](std::ostream &os) {
89 os <<
"Initial parameters - min " << jl <<
" " << amin <<
" max " << jh <<
" " << aming <<
'\n';
90 for (
unsigned int i = 0; i < simplex.
Simplex().
size(); ++i)
91 os <<
" i = " << i <<
" x = " << simplex(i).second <<
" fval(x) = " << simplex(i).first <<
'\n';
94 double edmPrev = simplex.
Edm();
100 amin = simplex(jl).first;
101 edmPrev = simplex.
Edm();
103 print.
Debug(
"iteration: edm =", simplex.
Edm(),
'\n',
"--> Min Param is", jl,
"pmin", simplex(jl).second,
104 "f(pmin)", amin,
'\n',
"--> Max param is", jh, simplex(jh).first);
119 for (
unsigned int i = 0; i <
n + 1; i++) {
122 pbar += (wg * simplex(i).second);
126 const double ystar = mfcn(pstar);
128 print.
Debug(
"pbar", pbar,
"pstar", pstar,
"f(pstar)", ystar);
131 if (ystar < simplex(jh).first) {
132 simplex.
Update(ystar, pstar);
133 if (jh != simplex.
Jh())
137 double ystst = mfcn(pstst);
139 print.
Debug(
"Reduced simplex pstst", pstst,
"f(pstst)", ystst);
141 if (ystst > simplex(jh).first)
143 simplex.
Update(ystst, pstst);
148 double ystst = mfcn(pstst);
150 print.
Debug(
"pstst", pstst,
"f(pstst)", ystst);
152 const double y1 = (ystar - simplex(jh).first) * rho2;
153 const double y2 = (ystst - simplex(jh).first) * rho1;
154 double rho = 0.5 * (rho2 *
y1 - rho1 *
y2) / (
y1 -
y2);
156 if (ystst < simplex(jl).first)
157 simplex.
Update(ystst, pstst);
159 simplex.
Update(ystar, pstar);
165 double yrho = mfcn(prho);
167 print.
Debug(
"prho", prho,
"f(prho)", yrho);
169 if (yrho < simplex(jl).first && yrho < ystst) {
170 simplex.
Update(yrho, prho);
173 if (ystst < simplex(jl).first) {
174 simplex.
Update(ystst, pstst);
177 if (yrho > simplex(jl).first) {
178 if (ystst < simplex(jl).first)
179 simplex.
Update(ystst, pstst);
181 simplex.
Update(ystar, pstar);
184 if (ystar > simplex(jh).first) {
185 pstst = beta * simplex(jh).second + (1. - beta) * pbar;
187 if (ystst > simplex(jh).first)
189 simplex.
Update(ystst, pstst);
192 print.
Debug(
"End loop : Edm", simplex.
Edm(),
"pstst", pstst,
"f(pstst)", ystst);
194 }
while ((simplex.
Edm() > minedm || edmPrev > minedm) && mfcn.
NumOfCalls() < maxfcn);
198 amin = simplex(jl).first;
201 for (
unsigned int i = 0; i <
n + 1; i++) {
204 pbar += (wg * simplex(i).second);
206 double ybar = mfcn(pbar);
208 simplex.
Update(ybar, pbar);
210 pbar = simplex(jl).second;
211 ybar = simplex(jl).first;
216 dirin *= std::sqrt(mfcn.
Up() / simplex.
Edm());
218 print.
Debug(
"End simplex edm =", simplex.
Edm(),
"pbar =", pbar,
"f(p) =", ybar);
228 print.
Warn(
"Simplex did not converge, #fcn calls exhausted");
232 if (simplex.
Edm() > minedm) {
233 print.
Warn(
"Simplex did not converge, edm > minedm");
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
const MnAlgebraicVector & Gstep() const
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
interface class for gradient calculators
unsigned int size() const
void TraceIteration(int iter, const MinimumState &state) const
const MnAlgebraicVector & Vec() const
const FunctionGradient & Gradient() const
const MinimumParameters & Parameters() const
const MnMachinePrecision & Precision() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Wrapper class to FCNBase interface used internally by Minuit.
unsigned int NumOfCalls() const
Sets the relative floating point (double) arithmetic precision.
double Eps2() const
eps2 returns 2*sqrt(eps)
void Debug(const Ts &... args)
void Info(const Ts &... args)
void Warn(const Ts &... args)
API class for defining four levels of strategies: low (0), medium (1), high (2), very high (>=3); act...
FunctionMinimum Minimum(const MnFcn &, const GradientCalculator &, const MinimumSeed &, const MnStrategy &, unsigned int, double) const override
class describing the simplex set of points (f(x), x ) which evolve during the minimization iteration ...
MnAlgebraicVector Dirin() const
void Update(double, const MnAlgebraicVector &)
const std::vector< std::pair< double, MnAlgebraicVector > > & Simplex() const
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...