Skip to content
Snippets Groups Projects
Commit aae2defb authored by Elias Pipping's avatar Elias Pipping
Browse files

[Algorit] Make minimisation terminate

parent c8774a97
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,14 @@ template <class Functional>
void minimise(Functional const &J, typename Functional::LocalVector &x,
size_t steps, Bisection const &bisection) {
using LocalVector = typename Functional::LocalVector;
auto const diff = [](LocalVector const &a, LocalVector const &b) {
LocalVector tmp = a;
tmp -= b;
return tmp.two_norm();
};
LocalVector x_initial = x;
LocalVector x_o = x;
for (size_t step = 0; step < steps; ++step) {
LocalVector v;
......@@ -40,6 +48,20 @@ void minimise(Functional const &J, typename Functional::LocalVector &x,
double const alpha = lineSearch(J, x, v, bisection);
Arithmetic::addProduct(x, alpha, v);
if (alpha < 1e-14) // TODO
break;
double const correction = diff(x, x_o);
double const overallCorrection = diff(x, x_initial);
if (overallCorrection <= 0.0)
return;
double const correctionQuotient = correction / overallCorrection;
if (correctionQuotient < 0.1) // enough descent; TODO
break;
x_o = x;
}
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment