17 #if defined(DEBUG) || defined(WARNINGMSG)
35 std::cout <<
"Running Simplex with maxfcn = " << maxfcn <<
" minedm = " << minedm << std::endl;
42 unsigned int n = x.
size();
44 double alpha = 1.,
beta = 0.5,
gamma = 2., rhomin = 4., rhomax = 8.;
45 double rho1 = 1. + alpha;
48 double rho2 = 1. + alpha*
gamma;
51 std::vector<std::pair<double, MnAlgebraicVector> > simpl; simpl.reserve(n+1);
52 simpl.push_back(std::pair<double, MnAlgebraicVector>(seed.
Fval(),
x));
54 unsigned int jl = 0, jh = 0;
55 double amin = seed.
Fval(), aming = seed.
Fval();
57 for(
unsigned int i = 0; i <
n; i++) {
59 if(step(i) < dmin) step(i) = dmin;
70 simpl.push_back(std::pair<double, MnAlgebraicVector>(tmp, x));
76 std::cout <<
"simplex initial parameters - min " << jl <<
" " << amin <<
" max " << jh <<
" " << aming << std::endl;
77 for (
unsigned int i = 0; i < simplex.
Simplex().size(); ++i)
78 std::cout <<
" i = " << i <<
" x = " << simplex(i).second <<
" fval(x) = " << simplex(i).first << std::endl;
81 double edmPrev = simplex.
Edm();
86 amin = simplex(jl).first;
87 edmPrev = simplex.
Edm();
90 std::cout <<
"\n\nsimplex iteration: edm = " << simplex.
Edm()
91 <<
"\n--> Min Param is " << jl <<
" pmin " << simplex(jl).second <<
" f(pmin) " << amin
92 <<
"\n--> Max param is " << jh <<
" " << simplex(jh).first << std::endl;
106 for(
unsigned int i = 0; i < n+1; i++) {
107 if(i == jh)
continue;
108 pbar += (wg*simplex(i).second);
112 double ystar = mfcn(pstar);
115 std::cout <<
" pbar = " << pbar << std::endl;
116 std::cout <<
" pstar = " << pstar <<
" f(pstar) = " << ystar << std::endl;
120 if(ystar < simplex(jh).first) {
121 simplex.
Update(ystar, pstar);
122 if(jh != simplex.
Jh())
continue;
125 double ystst = mfcn(pstst);
127 std::cout <<
"Reduced simplex pstst = " << pstst <<
" f(pstst) = " << ystst << std::endl;
129 if(ystst > simplex(jh).first)
break;
130 simplex.
Update(ystst, pstst);
135 double ystst = mfcn(pstst);
137 std::cout <<
" pstst = " << pstst <<
" f(pstst) = " << ystst << std::endl;
140 double y1 = (ystar - simplex(jh).first)*rho2;
141 double y2 = (ystst - simplex(jh).first)*rho1;
142 double rho = 0.5*(rho2*y1 - rho1*y2)/(y1 - y2);
144 if(ystst < simplex(jl).first) simplex.
Update(ystst, pstst);
145 else simplex.
Update(ystar, pstar);
148 if(rho > rhomax) rho = rhomax;
150 double yrho = mfcn(prho);
152 std::cout <<
" prho = " << prho <<
" f(prho) = " << yrho << std::endl;
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) simplex.
Update(ystst, pstst);
164 else simplex.
Update(ystar, pstar);
167 if(ystar > simplex(jh).first) {
168 pstst =
beta*simplex(jh).second + (1. -
beta)*pbar;
170 if(ystst > simplex(jh).first)
break;
171 simplex.
Update(ystst, pstst);
174 std::cout <<
"End loop : edm = " << simplex.
Edm() <<
" pstst = " << pstst <<
" f(pstst) = " << ystst << std::endl;
176 }
while( (simplex.
Edm() > minedm || edmPrev > minedm ) && mfcn.
NumOfCalls() < maxfcn);
180 amin = simplex(jl).first;
183 for(
unsigned int i = 0; i < n+1; i++) {
184 if(i == jh)
continue;
185 pbar += (wg*simplex(i).second);
187 double ybar = mfcn(pbar);
188 if(ybar < amin) simplex.
Update(ybar, pbar);
190 pbar = simplex(jl).second;
191 ybar = simplex(jl).first;
199 std::cout <<
"End simplex " << simplex.
Edm() <<
" pbar = " << pbar <<
" f(p) = " << ybar << std::endl;
211 MN_INFO_MSG(
"Simplex did not converge, #fcn calls exhausted.");
215 if(simplex.
Edm() > minedm) {
217 MN_INFO_MSG(
"Simplex did not converge, edm > minedm.");
const MinimumParameters & Parameters() const
Namespace for new ROOT classes and functions.
const MnMachinePrecision & Precision() const
unsigned int size() const
MinimumSeed contains the starting values for the minimization produced by the SeedGenerator.
const FunctionGradient & Gradient() const
determines the relative floating point arithmetic precision.
double beta(double x, double y)
Calculates the beta function.
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
const MnAlgebraicVector & Vec() const
static void PrintState(std::ostream &os, const MinimumState &state, const char *msg, int iter=-1)
Wrapper class to FCNBase interface used internally by Minuit.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
void Update(double, const MnAlgebraicVector &)
double Eps2() const
eps2 returns 2*sqrt(eps)
class describing the simplex set of points (f(x), x ) which evolve during the minimization iteration ...
const MnAlgebraicVector & Gstep() const
virtual FunctionMinimum Minimum(const MnFcn &, const GradientCalculator &, const MinimumSeed &, const MnStrategy &, unsigned int, double) const
const std::vector< std::pair< double, MnAlgebraicVector > > & Simplex() const
void TraceIteration(int iter, const MinimumState &state) const
MnAlgebraicVector Dirin() const
unsigned int NumOfCalls() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
API class for defining three levels of strategies: low (0), medium (1), high (>=2); acts on: Migrad (...
interface class for gradient calculators