22class GradientCalculator;
25 const MnStrategy &,
unsigned int maxfcn,
double minedm)
const
34 print.
Debug(
"Running with maxfcn", maxfcn,
"minedm", minedm);
42 double alpha = 1., beta = 0.5, gamma = 2., rhomin = 4., rhomax = 8.;
43 double rho1 = 1. + alpha;
46 double rho2 = 1. + alpha * gamma;
48 std::vector<std::pair<double, MnAlgebraicVector>> simpl;
50 simpl.push_back(std::pair<double, MnAlgebraicVector>(seed.
Fval(),
x));
52 unsigned int jl = 0, jh = 0;
53 double amin = seed.
Fval(), aming = seed.
Fval();
55 for (
unsigned int i = 0; i <
n; i++) {
56 double dmin = 8. * prec.
Eps2() * (std::fabs(
x(i)) + prec.
Eps2());
69 simpl.push_back(std::pair<double, MnAlgebraicVector>(tmp,
x));
74 print.
Debug([&](std::ostream &os) {
75 os <<
"Initial parameters - min " << jl <<
" " << amin <<
" max " << jh <<
" " << aming <<
'\n';
76 for (
unsigned int i = 0; i < simplex.
Simplex().size(); ++i)
77 os <<
" i = " << i <<
" x = " << simplex(i).second <<
" fval(x) = " << simplex(i).
first <<
'\n';
80 double edmPrev = simplex.
Edm();
85 amin = simplex(jl).first;
86 edmPrev = simplex.
Edm();
88 print.
Debug(
"iteration: edm =", simplex.
Edm(),
'\n',
"--> Min Param is", jl,
"pmin", simplex(jl).second,
89 "f(pmin)", amin,
'\n',
"--> Max param is", jh, simplex(jh).
first);
104 for (
unsigned int i = 0; i <
n + 1; i++) {
107 pbar += (wg * simplex(i).second);
111 double ystar = mfcn(pstar);
113 print.
Debug(
"pbar", pbar,
"pstar", pstar,
"f(pstar)", ystar);
116 if (ystar < simplex(jh).
first) {
117 simplex.
Update(ystar, pstar);
118 if (jh != simplex.
Jh())
122 double ystst = mfcn(pstst);
124 print.
Debug(
"Reduced simplex pstst", pstst,
"f(pstst)", ystst);
126 if (ystst > simplex(jh).
first)
128 simplex.
Update(ystst, pstst);
133 double ystst = mfcn(pstst);
135 print.
Debug(
"pstst", pstst,
"f(pstst)", ystst);
137 double y1 = (ystar - simplex(jh).first) * rho2;
138 double y2 = (ystst - simplex(jh).first) * rho1;
139 double rho = 0.5 * (rho2 * y1 - rho1 * y2) / (y1 - y2);
141 if (ystst < simplex(jl).first)
142 simplex.
Update(ystst, pstst);
144 simplex.
Update(ystar, pstar);
150 double yrho = mfcn(prho);
152 print.
Debug(
"prho", prho,
"f(prho)", yrho);
154 if (yrho < simplex(jl).
first && yrho < ystst) {
155 simplex.
Update(yrho, prho);
158 if (ystst < simplex(jl).
first) {
159 simplex.
Update(ystst, pstst);
162 if (yrho > simplex(jl).
first) {
163 if (ystst < simplex(jl).
first)
164 simplex.
Update(ystst, pstst);
166 simplex.
Update(ystar, pstar);
169 if (ystar > simplex(jh).
first) {
170 pstst = beta * simplex(jh).second + (1. - beta) * pbar;
172 if (ystst > simplex(jh).
first)
174 simplex.
Update(ystst, pstst);
177 print.
Debug(
"End loop : Edm", simplex.
Edm(),
"pstst", pstst,
"f(pstst)", ystst);
179 }
while ((simplex.
Edm() > minedm || edmPrev > minedm) && mfcn.
NumOfCalls() < maxfcn);
183 amin = simplex(jl).first;
186 for (
unsigned int i = 0; i <
n + 1; i++) {
189 pbar += (wg * simplex(i).second);
191 double ybar = mfcn(pbar);
193 simplex.
Update(ybar, pbar);
195 pbar = simplex(jl).second;
196 ybar = simplex(jl).first;
201 dirin *= std::sqrt(mfcn.
Up() / simplex.
Edm());
203 print.
Debug(
"End simplex edm =", simplex.
Edm(),
"pbar =", pbar,
"f(p) =", ybar);
213 print.
Warn(
"Simplex did not converge, #fcn calls exhausted");
217 if (simplex.
Edm() > minedm) {
218 print.
Warn(
"Simplex did not converge, edm > minedm");
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
MinimumSeed contains the starting values for the minimization produced by the SeedGenerator.
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 three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
virtual FunctionMinimum Minimum(const MnFcn &, const GradientCalculator &, const MinimumSeed &, const MnStrategy &, unsigned int, double) const
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...