17#if defined(DEBUG) || defined(WARNINGMSG)
28class GradientCalculator;
40 std::cout <<
"Running Simplex with maxfcn = " << maxfcn <<
" minedm = " << minedm << std::endl;
47 unsigned int n =
x.size();
49 double alpha = 1.,
beta = 0.5,
gamma = 2., rhomin = 4., rhomax = 8.;
50 double rho1 = 1. + alpha;
53 double rho2 = 1. + alpha*
gamma;
56 std::vector<std::pair<double, MnAlgebraicVector> > simpl; simpl.reserve(
n+1);
57 simpl.push_back(std::pair<double, MnAlgebraicVector>(seed.
Fval(),
x));
59 unsigned int jl = 0, jh = 0;
60 double amin = seed.
Fval(), aming = seed.
Fval();
62 for(
unsigned int i = 0; i <
n; i++) {
64 if(step(i) < dmin) step(i) = dmin;
75 simpl.push_back(std::pair<double, MnAlgebraicVector>(tmp,
x));
81 std::cout <<
"simplex initial parameters - min " << jl <<
" " << amin <<
" max " << jh <<
" " << aming << std::endl;
82 for (
unsigned int i = 0; i < simplex.
Simplex().size(); ++i)
83 std::cout <<
" i = " << i <<
" x = " << simplex(i).second <<
" fval(x) = " << simplex(i).first << std::endl;
86 double edmPrev = simplex.
Edm();
91 amin = simplex(jl).first;
92 edmPrev = simplex.
Edm();
95 std::cout <<
"\n\nsimplex iteration: edm = " << simplex.
Edm()
96 <<
"\n--> Min Param is " << jl <<
" pmin " << simplex(jl).second <<
" f(pmin) " << amin
97 <<
"\n--> Max param is " << jh <<
" " << simplex(jh).first << std::endl;
111 for(
unsigned int i = 0; i <
n+1; i++) {
112 if(i == jh)
continue;
113 pbar += (wg*simplex(i).second);
117 double ystar = mfcn(pstar);
120 std::cout <<
" pbar = " << pbar << std::endl;
121 std::cout <<
" pstar = " << pstar <<
" f(pstar) = " << ystar << std::endl;
125 if(ystar < simplex(jh).
first) {
126 simplex.
Update(ystar, pstar);
127 if(jh != simplex.
Jh())
continue;
130 double ystst = mfcn(pstst);
132 std::cout <<
"Reduced simplex pstst = " << pstst <<
" f(pstst) = " << ystst << std::endl;
134 if(ystst > simplex(jh).
first)
break;
135 simplex.
Update(ystst, pstst);
140 double ystst = mfcn(pstst);
142 std::cout <<
" pstst = " << pstst <<
" f(pstst) = " << ystst << std::endl;
145 double y1 = (ystar - simplex(jh).first)*rho2;
146 double y2 = (ystst - simplex(jh).first)*rho1;
147 double rho = 0.5*(rho2*y1 - rho1*y2)/(y1 - y2);
149 if(ystst < simplex(jl).first) simplex.
Update(ystst, pstst);
150 else simplex.
Update(ystar, pstar);
153 if(rho > rhomax) rho = rhomax;
155 double yrho = mfcn(prho);
157 std::cout <<
" prho = " << prho <<
" f(prho) = " << yrho << std::endl;
159 if(yrho < simplex(jl).
first && yrho < ystst) {
160 simplex.
Update(yrho, prho);
163 if(ystst < simplex(jl).
first) {
164 simplex.
Update(ystst, pstst);
167 if(yrho > simplex(jl).
first) {
168 if(ystst < simplex(jl).
first) simplex.
Update(ystst, pstst);
169 else simplex.
Update(ystar, pstar);
172 if(ystar > simplex(jh).
first) {
173 pstst =
beta*simplex(jh).second + (1. -
beta)*pbar;
175 if(ystst > simplex(jh).
first)
break;
176 simplex.
Update(ystst, pstst);
179 std::cout <<
"End loop : edm = " << simplex.
Edm() <<
" pstst = " << pstst <<
" f(pstst) = " << ystst << std::endl;
181 }
while( (simplex.
Edm() > minedm || edmPrev > minedm ) && mfcn.
NumOfCalls() < maxfcn);
185 amin = simplex(jl).first;
188 for(
unsigned int i = 0; i <
n+1; i++) {
189 if(i == jh)
continue;
190 pbar += (wg*simplex(i).second);
192 double ybar = mfcn(pbar);
193 if(ybar < amin) simplex.
Update(ybar, pbar);
195 pbar = simplex(jl).second;
196 ybar = simplex(jl).first;
204 std::cout <<
"End simplex " << simplex.
Edm() <<
" pbar = " << pbar <<
" f(p) = " << ybar << std::endl;
216 MN_INFO_MSG(
"Simplex did not converge, #fcn calls exhausted.");
220 if(simplex.
Edm() > minedm) {
222 MN_INFO_MSG(
"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
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)
static void PrintState(std::ostream &os, const MinimumState &state, const char *msg, int iter=-1)
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
double beta(double x, double y)
Calculates the beta function.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static constexpr double second