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';
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");