23 inline std::pair<double, double>
getMinima(std::vector<std::vector<double>> vals,
int i0,
int j0)
26 int Nzoom = (N + 1) / 2;
29 double minIn = std::numeric_limits<double>::max();
30 double minOut = std::numeric_limits<double>::max();
32 for (
int i = 0; i < N; ++i)
33 for (
int j = 0; j < N; ++j) {
34 if ((i0 <= i && i < i0 + Nzoom) &&
35 (j0 <= j && j < j0 + Nzoom))
36 minIn = std::min(minIn, vals[i][j]);
38 minOut = std::min(minOut, vals[i][j]);
40 return {minIn, minOut};
44 inline std::vector<double>
getMinimum(std::function<
double(
double,
double)> fun,
double xMin,
double xMax,
double yMin,
double yMax)
47 const int Nzoom = (N + 1) / 2;
52 std::vector<std::vector<double>> vals(N);
53 for (
auto& v : vals) v.resize(N);
55 for (
int k = 0; k < kMax; ++k) {
58 for (
int i = 0; i < N; ++i)
59 for (
int j = 0; j < N; ++j) {
60 double x = xMin + i * (xMax - xMin) / (N - 1.);
61 double y = yMin + j * (yMax - yMin) / (N - 1.);
62 vals[i][j] = fun(x, y);
65 if (k == kMax - 1)
break;
67 double mOutMax = - std::numeric_limits<double>::max();
68 int iOpt = -1, jOpt = -1;
70 for (
int i = 0; i < N - Nzoom; ++i)
71 for (
int j = 0; j < N - Nzoom; ++j) {
73 std::tie(mIn, mOut) =
getMinima(vals, i, j);
85 double xMinNow = xMin + iOpt * (xMax - xMin) / (N - 1.);
86 double xMaxNow = xMin + (iOpt + Nzoom - 1) * (xMax - xMin) / (N - 1.);
88 double yMinNow = yMin + jOpt * (yMax - yMin) / (N - 1.);
89 double yMaxNow = yMin + (jOpt + Nzoom - 1) * (yMax - yMin) / (N - 1.);
100 double minTot = std::numeric_limits<double>::max();
101 int iOpt = -1, jOpt = -1;
103 for (
int i = 0; i < N; ++i)
104 for (
int j = 0; j < N; ++j) {
105 if (vals[i][j] < minTot) {
112 double xMinNow = xMin + iOpt * (xMax - xMin) / (N - 1.);
113 double yMinNow = yMin + jOpt * (yMax - yMin) / (N - 1.);
115 return {xMinNow, yMinNow};
std::pair< double, double > getMinima(std::vector< std::vector< double > > vals, int i0, int j0)
Get minimum inside and outside of the smaller window defined by i0, j0.
std::vector< double > getMinimum(std::function< double(double, double)> fun, double xMin, double xMax, double yMin, double yMax)
Get minimum of 2D function in the rectangular domain defined by xMin,xMax & yMin,yMax.
Abstract base class for different kinds of events.