25 const MnStrategy &,
unsigned int maxfcn,
double minedm)
const
36 print.
Debug(
"Running with maxfcn", maxfcn,
"minedm", minedm);
42 const unsigned int n =
x.size();
51 const double wg = 1. /
double(
n);
52 const double alpha = 1.;
53 const double beta = 0.5;
54 const double gamma = 2.;
55 const double rhomin = 4.;
56 const double rhomax = 8.;
57 const double rho1 = 1. + alpha;
60 const double rho2 = 1. + alpha * gamma;
62 std::vector<std::pair<double, MnAlgebraicVector>> simpl;
64 simpl.emplace_back(seed.
Fval(),
x);
68 double amin = seed.
Fval();
69 double aming = seed.
Fval();
71 for (
unsigned int i = 0; i <
n; i++) {
72 double dmin = 8. * prec.
Eps2() * (std::abs(
x(i)) + prec.
Eps2());
76 double tmp = mfcnCaller(
x);
85 simpl.emplace_back(tmp,
x);
90 print.
Debug([&](std::ostream &os) {
91 os <<
"Initial parameters - min " << jl <<
" " << amin <<
" max " << jh <<
" " << aming <<
'\n';
92 for (
unsigned int i = 0; i < simplex.
Simplex().
size(); ++i)
93 os <<
" i = " << i <<
" x = " << simplex(i).second <<
" fval(x) = " << simplex(i).first <<
'\n';
96 double edmPrev = simplex.
Edm();
102 amin = simplex(jl).first;
103 edmPrev = simplex.
Edm();
105 print.
Debug(
"iteration: edm =", simplex.
Edm(),
'\n',
"--> Min Param is", jl,
"pmin", simplex(jl).second,
106 "f(pmin)", amin,
'\n',
"--> Max param is", jh, simplex(jh).first);
121 for (
unsigned int i = 0; i <
n + 1; i++) {
124 pbar += (wg * simplex(i).second);
128 const double ystar = mfcnCaller(pstar);
130 print.
Debug(
"pbar", pbar,
"pstar", pstar,
"f(pstar)", ystar);
133 if (ystar < simplex(jh).first) {
134 simplex.
Update(ystar, pstar);
135 if (jh != simplex.
Jh())
139 double ystst = mfcnCaller(pstst);
141 print.
Debug(
"Reduced simplex pstst", pstst,
"f(pstst)", ystst);
143 if (ystst > simplex(jh).first)
145 simplex.
Update(ystst, pstst);
150 double ystst = mfcnCaller(pstst);
152 print.
Debug(
"pstst", pstst,
"f(pstst)", ystst);
154 const double y1 = (ystar - simplex(jh).first) * rho2;
155 const double y2 = (ystst - simplex(jh).first) * rho1;
156 double rho = 0.5 * (rho2 * y1 - rho1 * y2) / (y1 - y2);
158 if (ystst < simplex(jl).first)
159 simplex.
Update(ystst, pstst);
161 simplex.
Update(ystar, pstar);
167 double yrho = mfcnCaller(prho);
169 print.
Debug(
"prho", prho,
"f(prho)", yrho);
171 if (yrho < simplex(jl).first && yrho < ystst) {
172 simplex.
Update(yrho, prho);
175 if (ystst < simplex(jl).first) {
176 simplex.
Update(ystst, pstst);
179 if (yrho > simplex(jl).first) {
180 if (ystst < simplex(jl).first)
181 simplex.
Update(ystst, pstst);
183 simplex.
Update(ystar, pstar);
186 if (ystar > simplex(jh).first) {
187 pstst = beta * simplex(jh).second + (1. - beta) * pbar;
188 ystst = mfcnCaller(pstst);
189 if (ystst > simplex(jh).first)
191 simplex.
Update(ystst, pstst);
194 print.
Debug(
"End loop : Edm", simplex.
Edm(),
"pstst", pstst,
"f(pstst)", ystst);
196 }
while ((simplex.
Edm() > minedm || edmPrev > minedm) && mfcn.
NumOfCalls() < maxfcn);
200 amin = simplex(jl).first;
203 for (
unsigned int i = 0; i <
n + 1; i++) {
206 pbar += (wg * simplex(i).second);
208 double ybar = mfcnCaller(pbar);
210 simplex.
Update(ybar, pbar);
212 pbar = simplex(jl).second;
213 ybar = simplex(jl).first;
218 dirin *= std::sqrt(mfcn.
Up() / simplex.
Edm());
220 print.
Debug(
"End simplex edm =", simplex.
Edm(),
"pbar =", pbar,
"f(p) =", ybar);
230 print.
Warn(
"Simplex did not converge, #fcn calls exhausted");
234 if (simplex.
Edm() > minedm) {
235 print.
Warn(
"Simplex did not converge, edm > minedm");